2022-02-24 12:01:55 -05:00
|
|
|
// this will announce that a deploy successfully finished into slack
|
|
|
|
|
|
|
|
const https = require('https');
|
|
|
|
|
2024-01-17 15:40:27 -05:00
|
|
|
const environment = process.env.SCRATCH_ENV || 'unknown environment';
|
2022-02-24 12:01:55 -05:00
|
|
|
|
2024-02-14 17:27:30 -05:00
|
|
|
const branch = process.env.SCRATCH_BRANCH || 'unknown branch';
|
2022-02-24 12:01:55 -05:00
|
|
|
|
2024-01-17 15:40:27 -05:00
|
|
|
const urlEng = process.env.SLACK_WEBHOOK_ENGINEERING;
|
|
|
|
const urlMod = process.env.SLACK_WEBHOOK_MODS;
|
|
|
|
const urlNotifications = process.env.SLACK_WEBHOOK_CIRCLECI_NOTIFICATIONS;
|
2022-02-24 12:01:55 -05:00
|
|
|
|
2024-01-17 15:40:27 -05:00
|
|
|
const announcement = {text: `scratch-www has deployed branch ${branch} to ${environment}.`};
|
2022-02-24 12:01:55 -05:00
|
|
|
|
|
|
|
const options = {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const postMessage = (url, message, channelName) => {
|
2024-01-17 15:40:27 -05:00
|
|
|
const data = JSON.stringify(message);
|
2022-02-24 12:01:55 -05:00
|
|
|
const req = https.request(url, options, res => {
|
|
|
|
console.log(`statusCode: ${res.statusCode}`); // eslint-disable-line no-console
|
|
|
|
if (res.statusCode === 200) {
|
2024-01-17 15:40:27 -05:00
|
|
|
process.stdout.write(`announced to ${channelName}\n${JSON.stringify(message)}\n`);
|
2022-02-24 12:01:55 -05:00
|
|
|
} else {
|
|
|
|
process.stdout.write(`FAILED to announce to slack`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
req.on('error', error => {
|
|
|
|
console.error(error); // eslint-disable-line no-console
|
|
|
|
});
|
|
|
|
|
|
|
|
req.write(data);
|
|
|
|
req.end();
|
|
|
|
};
|
|
|
|
|
|
|
|
postMessage(urlNotifications, announcement, '#circleci-notifications');
|
|
|
|
|
|
|
|
if (environment === 'production'){
|
|
|
|
postMessage(urlEng, announcement, '#engineering');
|
|
|
|
postMessage(urlMod, announcement, '#scratch-mods');
|
|
|
|
}
|