diff --git a/build/controllers/github.js b/build/controllers/github.js index 0db8562a..f9c0d686 100644 --- a/build/controllers/github.js +++ b/build/controllers/github.js @@ -257,6 +257,12 @@ async function processWebhook( repositoryName: request.payload.repository.name, }); } + if (request.payload.action === 'unlabeled' && request.payload.label.name === ':rocket: Ready to Merge') { + await pullRequestRepository.delete({ + number: request.payload.number, + repositoryName: request.payload.repository.name, + }); + } return `Ignoring ${request.payload.action} action`; } else { return `Ignoring ${eventName} event`; diff --git a/build/repositories/pull-request-repository.js b/build/repositories/pull-request-repository.js index 75a14704..572b4e9d 100644 --- a/build/repositories/pull-request-repository.js +++ b/build/repositories/pull-request-repository.js @@ -16,4 +16,8 @@ async function update({ number, repositoryName, isMerging }) { await knex('pull_requests').where({ number, repositoryName }).update({ isMerging }); } -export { save, isAtLeastOneMergeInProgress, update }; +async function remove({ number, repositoryName }) { + await knex('pull_requests').where({ number, repositoryName }).delete(); +} + +export { save, isAtLeastOneMergeInProgress, update, remove }; diff --git a/test/unit/build/controllers/github_test.js b/test/unit/build/controllers/github_test.js index a487b175..ae946d72 100644 --- a/test/unit/build/controllers/github_test.js +++ b/test/unit/build/controllers/github_test.js @@ -172,6 +172,31 @@ Les variables d'environnement seront accessibles sur scalingo https://dashboard. }); }); + describe('when action is `unlabeled`', function () { + describe('when label is Ready-to-merge', function () { + it('should call pullRequestRepository.remove() method', async function () { + // given + sinon.stub(request, 'payload').value({ + action: 'unlabeled', + number: 123, + label: { name: ':rocket: Ready to Merge' }, + repository: { name: 'pix-sample-repo' }, + }); + + const pullRequestRepository = { remove: sinon.stub() }; + + // when + await githubController.processWebhook(request, { pullRequestRepository }); + + // then + expect(pullRequestRepository.remove).to.be.calledOnceWithExactly({ + number: 123, + repositoryName: 'pix-sample-repo', + }); + }); + }); + }); + it('should call handleCloseRA() method on closed action', async function () { // given sinon.stub(request, 'payload').value({ action: 'closed' });