Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
fix(octokit): searched to the commit sha
Browse files Browse the repository at this point in the history
rather than the branch name, which was an accidental leftover from the previous version
  • Loading branch information
travi committed Mar 4, 2018
1 parent 3ad2b85 commit 0590cf3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
12 changes: 10 additions & 2 deletions src/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ function successfulStatusCouldBeForGreenkeeperPR(event, state, branches) {
}

export default async function (request, reply, settings) {
const {action, sender, state, repository, pull_request, branches} = request.payload; // eslint-disable-line camelcase
const {
action,
sender,
state,
repository,
pull_request, // eslint-disable-line camelcase
branches,
sha
} = request.payload;
const event = request.headers['x-github-event'];

if ('ping' === event) {
Expand All @@ -37,7 +45,7 @@ export default async function (request, reply, settings) {
if (successfulStatusCouldBeForGreenkeeperPR(event, state, branches)) {
const {getPullRequestsForCommit, getPullRequest} = createActions(settings.github);

return getPullRequestsForCommit({ref: branches[0].name})
return getPullRequestsForCommit({ref: sha})
.then(async pullRequests => {
if (!pullRequests.length) reply('no PRs for this commit').code(BAD_REQUEST);
else if (1 < pullRequests.length) reply(boom.internal('too many PRs exist for this commit'));
Expand Down
3 changes: 1 addition & 2 deletions test/integration/features/step_definitions/common-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ defineSupportCode(({When, Then, setWorldConstructor}) => {
prDetails: {
sender: this.prSender,
comments: this.comments,
number: this.prNumber,
sha: this.sha
number: this.prNumber
},
statusEventDetails: {
state: this.statusEventState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ defineSupportCode(({Before, After, Given, setWorldConstructor}) => {
}
githubScope
.matchHeader('Authorization', authorizationHeader)
.get(`/search/issues?q=${this.commitBranches[0]}+type%3Apr`)
.get(`/search/issues?q=${encodeURIComponent(this.sha)}+type%3Apr`)
.reply(OK, {
items: [{
url: 'https://api.github.com/123',
Expand All @@ -77,7 +77,7 @@ defineSupportCode(({Before, After, Given, setWorldConstructor}) => {
Given('no open PRs exist for the commit', function (callback) {
githubScope
.matchHeader('Authorization', authorizationHeader)
.get(`/search/issues?q=${this.commitBranches[0]}+type%3Apr`)
.get(`/search/issues?q=${encodeURIComponent(this.sha)}+type%3Apr`)
.reply(OK, {items: []});

callback();
Expand Down
10 changes: 8 additions & 2 deletions test/integration/features/support/world.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import any from '@travi/any';

function buildWebhookPayload(event, {action, prDetails, statusEventDetails, ref, repoFullName, repoName, repoOwner}) {
function buildWebhookPayload(
event,
{action, prDetails, statusEventDetails, ref, repoFullName, repoName, repoOwner, sha}
) {
if ('pull_request' === event) {
return {
action,
sha,
sender: {
html_url: prDetails.sender
},
Expand All @@ -13,7 +17,7 @@ function buildWebhookPayload(event, {action, prDetails, statusEventDetails, ref,
comments_url: `https://api.github.com${prDetails.comments}`,
url: 'https://api.github.com/123',
head: {
sha: prDetails.sha,
sha,
ref,
repo: {
full_name: repoFullName,
Expand All @@ -28,6 +32,7 @@ function buildWebhookPayload(event, {action, prDetails, statusEventDetails, ref,
if ('status' === event) {
return {
state: statusEventDetails.state,
sha,
repository: {
full_name: repoFullName,
name: repoName,
Expand Down Expand Up @@ -63,6 +68,7 @@ export function World() {
action,
prDetails,
statusEventDetails,
sha: this.sha,
ref: this.ref,
repoFullName: this.repoFullName,
repoName: this.repoName,
Expand Down
4 changes: 3 additions & 1 deletion test/unit/handler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,21 @@ suite('handler', () => {
const repository = any.simpleObject();
const branch = any.string();
const prNumber = any.integer();
const sha = any.string();
const partialPullRequest = {user: {html_url: greenkeeperSender}, number: prNumber};
const fullPullRequest = any.simpleObject();
const request = {
payload: {
state: 'success',
sha,
repository,
branches: [{name: branch}]
},
headers: {'x-github-event': 'status'},
log: () => undefined
};
reply.withArgs('ok').returns({code});
getPullRequestsForCommit.withArgs({ref: branch}).resolves([partialPullRequest]);
getPullRequestsForCommit.withArgs({ref: sha}).resolves([partialPullRequest]);
getPullRequest.withArgs(repository, prNumber).resolves(fullPullRequest);

return handler(request, reply, settings).then(() => {
Expand Down

0 comments on commit 0590cf3

Please sign in to comment.