diff --git a/build/controllers/github.js b/build/controllers/github.js index 6bb66ec5..ba90089a 100644 --- a/build/controllers/github.js +++ b/build/controllers/github.js @@ -8,6 +8,7 @@ import ScalingoClient from '../../common/services/scalingo-client.js'; import { config } from '../../config.js'; import * as reviewAppRepo from '../repository/review-app-repository.js'; import * as _pullRequestRepository from '../repositories/pull-request-repository.js'; +import { mergeQueue } from '../services/merge-queue.js'; const repositoryToScalingoAppsReview = { 'pix-api-data': ['pix-api-data-integration'], @@ -247,6 +248,7 @@ async function processWebhook( handleRA = _handleRA, handleCloseRA = _handleCloseRA, pullRequestRepository = _pullRequestRepository, + mergeQueue, } = {}, ) { const eventName = request.headers['x-github-event']; @@ -261,6 +263,7 @@ async function processWebhook( number: request.payload.number, repositoryName: request.payload.pull_request.head.repo.name, }); + await mergeQueue(); return handleCloseRA(request); } if (request.payload.action === 'labeled' && request.payload.label.name === ':rocket: Ready to Merge') { @@ -268,12 +271,14 @@ async function processWebhook( number: request.payload.number, repositoryName: request.payload.repository.name, }); + await mergeQueue(); } if (request.payload.action === 'unlabeled' && request.payload.label.name === ':rocket: Ready to Merge') { await pullRequestRepository.remove({ number: request.payload.number, repositoryName: request.payload.repository.name, }); + await mergeQueue(); } return `Ignoring ${request.payload.action} action`; } else if (eventName === 'check_suite') { @@ -282,12 +287,11 @@ async function processWebhook( number: request.payload.pull_requests[0].number, repositoryName: request.payload.repository.name, }); + await mergeQueue(); } } else { return `Ignoring ${eventName} event`; } - - // TODO: check commits fail => j'enlève du tableau } function _handleNoRACase(request) { diff --git a/test/unit/build/controllers/github_test.js b/test/unit/build/controllers/github_test.js index 3e0136ad..d90dc457 100644 --- a/test/unit/build/controllers/github_test.js +++ b/test/unit/build/controllers/github_test.js @@ -132,6 +132,7 @@ Les variables d'environnement seront accessibles sur scalingo https://dashboard. }, payload: { action: 'nothing' }, }; + ['opened', 'reopened', 'synchronize'].forEach((action) => { it(`should call handleRA() method on ${action} action`, async function () { // given @@ -158,16 +159,19 @@ Les variables d'environnement seront accessibles sur scalingo https://dashboard. repository: { name: 'pix-sample-repo' }, }); + const mergeQueue = sinon.stub(); const pullRequestRepository = { save: sinon.stub() }; // when - await githubController.processWebhook(request, { pullRequestRepository }); + await githubController.processWebhook(request, { pullRequestRepository, mergeQueue }); // then expect(pullRequestRepository.save).to.be.calledOnceWithExactly({ number: 123, repositoryName: 'pix-sample-repo', }); + + expect(mergeQueue).to.be.calledOnce; }); }); }); @@ -183,16 +187,19 @@ Les variables d'environnement seront accessibles sur scalingo https://dashboard. repository: { name: 'pix-sample-repo' }, }); + const mergeQueue = sinon.stub(); const pullRequestRepository = { remove: sinon.stub() }; // when - await githubController.processWebhook(request, { pullRequestRepository }); + await githubController.processWebhook(request, { pullRequestRepository, mergeQueue }); // then expect(pullRequestRepository.remove).to.be.calledOnceWithExactly({ number: 123, repositoryName: 'pix-sample-repo', }); + + expect(mergeQueue).to.be.calledOnce; }); }); }); @@ -211,10 +218,11 @@ Les variables d'environnement seront accessibles sur scalingo https://dashboard. }); const handleCloseRA = sinon.stub(); + const mergeQueue = sinon.stub(); const pullRequestRepository = { remove: sinon.stub() }; // when - await githubController.processWebhook(request, { handleCloseRA, pullRequestRepository }); + await githubController.processWebhook(request, { handleCloseRA, pullRequestRepository, mergeQueue }); // then expect(pullRequestRepository.remove).to.be.calledOnceWithExactly({ @@ -222,6 +230,7 @@ Les variables d'environnement seront accessibles sur scalingo https://dashboard. repositoryName: 'pix-sample-repo', }); expect(handleCloseRA.calledOnceWithExactly(request)).to.be.true; + expect(mergeQueue).to.be.calledOnce; }); }); @@ -252,16 +261,18 @@ Les variables d'environnement seront accessibles sur scalingo https://dashboard. }, }; + const mergeQueue = sinon.stub(); const pullRequestRepository = { remove: sinon.stub() }; // when - await githubController.processWebhook(request, { pullRequestRepository }); + await githubController.processWebhook(request, { pullRequestRepository, mergeQueue }); // then expect(pullRequestRepository.remove).to.be.calledOnceWithExactly({ number: 123, repositoryName: 'pix-sample-repo', }); + expect(mergeQueue).to.be.calledOnce; }); }); });