Skip to content

Commit

Permalink
Call mergequeue service after remove
Browse files Browse the repository at this point in the history
Co-Authored-By: GUL <[email protected]>
Co-Authored-By: Vincent Hardouin <[email protected]>
Co-Authored-By: Clement Latzarus <[email protected]>
Co-Authored-By: Diane Cordier <[email protected]>
  • Loading branch information
5 people committed Nov 19, 2024
1 parent 143b3b3 commit 3394516
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
8 changes: 6 additions & 2 deletions build/controllers/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -247,6 +248,7 @@ async function processWebhook(
handleRA = _handleRA,
handleCloseRA = _handleCloseRA,
pullRequestRepository = _pullRequestRepository,
mergeQueue,
} = {},
) {
const eventName = request.headers['x-github-event'];
Expand All @@ -261,19 +263,22 @@ 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') {
await pullRequestRepository.save({
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') {
Expand All @@ -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) {
Expand Down
19 changes: 15 additions & 4 deletions test/unit/build/controllers/github_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
});
});
});
Expand All @@ -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;
});
});
});
Expand All @@ -211,17 +218,19 @@ 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({
number: 123,
repositoryName: 'pix-sample-repo',
});
expect(handleCloseRA.calledOnceWithExactly(request)).to.be.true;
expect(mergeQueue).to.be.calledOnce;
});
});

Expand Down Expand Up @@ -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;
});
});
});
Expand Down

0 comments on commit 3394516

Please sign in to comment.