Skip to content

Commit

Permalink
feat: handle check_suite not any related to pr
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentHardouin committed Dec 23, 2024
1 parent 3388c61 commit 3fab263
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions build/controllers/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ async function processWebhook(
} else if (eventName === 'check_suite') {
if (request.payload.action === 'completed') {
const repositoryName = request.payload.repository.full_name;

if (request.payload.check_suite.pull_requests.length === 0) {
return `check_suite is not related to any pull_request`;
}

const prNumber = request.payload.check_suite.pull_requests[0].number;
if (request.payload.check_suite.conclusion !== 'success') {
await pullRequestRepository.remove({
Expand Down
19 changes: 18 additions & 1 deletion test/unit/build/controllers/github_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,24 @@ Les variables d'environnement seront accessibles sur scalingo https://dashboard.
});
});

describe("when action is 'completed' and conclusion is'success'", function () {
describe("when action is 'completed' and conclusion is 'success'", function () {
it('should return ignoring message when not pr are related to check_suite', async function () {
const request = {
headers: {
'x-github-event': 'check_suite',
},
payload: {
action: 'completed',
repository: { full_name: '1024pix/pix-test' },
check_suite: { conclusion: 'success', pull_requests: [] },
},
};

const result = await githubController.processWebhook(request, {});

expect(result).to.equal('check_suite is not related to any pull_request');
});

it('should check PR as Ready to Merge label before saved it', async function () {
const repositoryName = '1024pix/pix-sample-repo';
const prNumber = 123;
Expand Down

0 comments on commit 3fab263

Please sign in to comment.