From 3fab26322856d057910d11e7ef60018063bc6ace Mon Sep 17 00:00:00 2001 From: Vincent Hardouin Date: Mon, 23 Dec 2024 12:21:34 +0100 Subject: [PATCH] feat: handle check_suite not any related to pr --- build/controllers/github.js | 5 +++++ test/unit/build/controllers/github_test.js | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/build/controllers/github.js b/build/controllers/github.js index 83941f88..907673f5 100644 --- a/build/controllers/github.js +++ b/build/controllers/github.js @@ -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({ diff --git a/test/unit/build/controllers/github_test.js b/test/unit/build/controllers/github_test.js index 573fa740..48e326a1 100644 --- a/test/unit/build/controllers/github_test.js +++ b/test/unit/build/controllers/github_test.js @@ -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;