Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ref for pr closed event when a pr is merged #141

Merged
merged 3 commits into from Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions __test__/input-helper.test.ts
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
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),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andymckay is this a bug on the server? Seems like github.ref would always be qualified (e.g. refs/heads/master not master). For most events it's qualified. PR closed_event (when a PR is merged) is the only case I'm aware it's not.

I'm still planning to proceed with this fix here for resiliency, but just FYI since this seems like a bug on the server.

// 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
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