Skip to content

Commit

Permalink
[FEATURE] ✨ Envoyer un message sur slack en cas de changements sur le…
Browse files Browse the repository at this point in the history
… fichier config.js
  • Loading branch information
github-actions[bot] authored Sep 15, 2023
2 parents bc331ea + 683e80a commit f9664c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions build/services/slack/view-submissions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
const openModalReleasePublicationConfirmation = require('./surfaces/modals/publish-release/release-publication-confirmation');
const { environments, deploy, publish } = require('../../../common/services/releases');
const githubService = require('../../../common/services/github');
const slackPostMessageService = require('../../../common/services/slack/surfaces/messages/post-message');

module.exports = {
async submitReleaseTypeSelection(payload) {
const releaseType = payload.view.state.values['publish-release-type']['release-type-option'].selected_option.value;
const { hasConfigFileChanged, latestTag } = await githubService.hasConfigFileChangedSinceLatestRelease();
if (hasConfigFileChanged) {
await slackPostMessageService.postMessage({
message: 'Changements détéctés sur le fichier config.js dans la release : liens des commits',
channel: '#tech-releases',
});
}
return openModalReleasePublicationConfirmation({ releaseType, hasConfigFileChanged, latestTag });
},

Expand Down
12 changes: 11 additions & 1 deletion test/acceptance/build/slack_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('Acceptance | Build | Slack', function () {
});
});

it('returns the confirmation modal with a warning', async function () {
it('returns the confirmation modal with a warning and sends a slack message to tech-releases', async function () {
// given
const tagNock = nock('https://api.github.com')
.get('/repos/github-owner/github-repository/tags')
Expand Down Expand Up @@ -226,6 +226,15 @@ describe('Acceptance | Build | Slack', function () {
.get('/repos/github-owner/github-repository/commits?since=XXXX&until=XXXX&path=api%2Flib%2Fconfig.js')
.reply(200, [{}]);

const slackMessageNock = nock('https://slack.com')
.post('/api/chat.postMessage', {
channel: '#tech-releases',
text: 'Changements détéctés sur le fichier config.js dans la release : liens des commits',
})
.reply(200, {
ok: true,
});

const body = {
type: 'view_submission',
view: {
Expand Down Expand Up @@ -257,6 +266,7 @@ describe('Acceptance | Build | Slack', function () {
expect(tagNock.isDone()).to.be.true;
expect(firstCommitNock.isDone()).to.be.true;
expect(commitsNock.isDone()).to.be.true;
expect(slackMessageNock.isDone()).to.be.true;

expect(res.statusCode).to.equal(200);
expect(JSON.parse(res.payload)).to.deep.equal({
Expand Down

0 comments on commit f9664c6

Please sign in to comment.