Skip to content

Commit

Permalink
feat: handle unlabeled
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentHardouin committed Nov 5, 2024
1 parent 485b7cd commit d57b0f3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions build/controllers/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
6 changes: 5 additions & 1 deletion build/repositories/pull-request-repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
25 changes: 25 additions & 0 deletions test/unit/build/controllers/github_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down

0 comments on commit d57b0f3

Please sign in to comment.