Skip to content

Commit

Permalink
feat(pix-bot): handle check_suite not succeeded
Browse files Browse the repository at this point in the history
Co-authored-by: Clément Latzarus <[email protected]>
Co-authored-by: Yannick François <[email protected]>
Co-authored-by: Vincent Hardouin <[email protected]>
Co-authored-by: Guillaume Lagorce <[email protected]>
  • Loading branch information
5 people committed Nov 19, 2024
1 parent 2c0f3ae commit 143b3b3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions build/controllers/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ async function processWebhook(
});
}
return `Ignoring ${request.payload.action} action`;
} else if (eventName === 'check_suite') {
if (request.payload.action === 'completed' && request.payload.check_suite.conclusion !== 'success') {
await pullRequestRepository.remove({
number: request.payload.pull_requests[0].number,
repositoryName: request.payload.repository.name,
});
}
} else {
return `Ignoring ${eventName} event`;
}
Expand Down
29 changes: 29 additions & 0 deletions test/unit/build/controllers/github_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,35 @@ Les variables d'environnement seront accessibles sur scalingo https://dashboard.
expect(result).to.equal('Ignoring unhandled-action action');
});
});

describe('when event is check_suite', function () {
describe("when action is 'completed' and conclusion is not 'success'", function () {
it('should call pullRequestRepository.remove() method', async function () {
const request = {
headers: {
'x-github-event': 'check_suite',
},
payload: {
action: 'completed',
pull_requests: [{ number: 123 }],
repository: { name: 'pix-sample-repo' },
check_suite: { conclusion: 'failure' },
},
};

const pullRequestRepository = { remove: sinon.stub() };

// when
await githubController.processWebhook(request, { pullRequestRepository });

// then
expect(pullRequestRepository.remove).to.be.calledOnceWithExactly({
number: 123,
repositoryName: 'pix-sample-repo',
});
});
});
});
});
});

Expand Down

0 comments on commit 143b3b3

Please sign in to comment.