Skip to content

Commit

Permalink
fix ref for pr closed event when a pr is merged (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsciple authored Jan 21, 2020
1 parent db41740 commit 090d9c9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions __test__/input-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ describe('input-helper tests', () => {
expect(settings.repositoryPath).toBe(gitHubWorkspace)
})

it('qualifies ref', () => {
let originalContext = mockGitHub.context
try {
mockGitHub.context = {...originalContext} // Shallow clone
mockGitHub.context.ref = 'some-unqualified-ref'
const settings: ISourceSettings = inputHelper.getInputs()
expect(settings).toBeTruthy()
expect(settings.commit).toBe('1234567890123456789012345678901234567890')
expect(settings.ref).toBe('refs/heads/some-unqualified-ref')
} finally {
mockGitHub.context = originalContext
}
})

it('requires qualified repo', () => {
inputs.repository = 'some-unqualified-repo'
assert.throws(() => {
Expand Down
5 changes: 5 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12757,6 +12757,11 @@ function getInputs() {
if (isWorkflowRepository) {
result.ref = github.context.ref;
result.commit = github.context.sha;
// Some events have an unqualifed ref. For example when a PR is merged (pull_request closed event),
// the ref is unqualifed like "master" instead of "refs/heads/master".
if (result.commit && result.ref && !result.ref.startsWith('refs/')) {
result.ref = `refs/heads/${result.ref}`;
}
}
if (!result.ref && !result.commit) {
result.ref = 'refs/heads/master';
Expand Down
6 changes: 6 additions & 0 deletions src/input-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ export function getInputs(): ISourceSettings {
if (isWorkflowRepository) {
result.ref = github.context.ref
result.commit = github.context.sha

// Some events have an unqualifed ref. For example when a PR is merged (pull_request closed event),
// the ref is unqualifed like "master" instead of "refs/heads/master".
if (result.commit && result.ref && !result.ref.startsWith('refs/')) {
result.ref = `refs/heads/${result.ref}`
}
}

if (!result.ref && !result.commit) {
Expand Down

0 comments on commit 090d9c9

Please sign in to comment.