feat: make slack notification optional

This commit is contained in:
Rainer Killinger
2020-11-23 10:19:10 +01:00
parent ccb1b56a0f
commit 84921ad5ce
+5 -3
View File
@@ -51,7 +51,9 @@ export async function remind(api: Api): Promise<void> {
Logger.info(`Found ${mergeRequests.length} open merge requests.`);
// instantiate slack client
const client = new WebClient(process.env.SLACK_API_TOKEN);
const client = typeof process.env.SLACK_API_TOKEN !== 'undefined' ?
new WebClient(process.env.SLACK_API_TOKEN) :
undefined;
// get members of main group
const members = await api.getMembers(MembershipScope.GROUPS, GROUPS[0]);
@@ -136,7 +138,7 @@ export async function remind(api: Api): Promise<void> {
.join(', ');
// send message to slack
await client.chat.postMessage({
await client?.chat.postMessage({
channel: SLACK_CHANNEL,
text: `Merge request '${mergeRequest.title}' needs more approvals! See ${mergeRequest.web_url}!`,
});
@@ -152,7 +154,7 @@ export async function remind(api: Api): Promise<void> {
Logger.log(`Merge request '${mergeRequest.title}' is ready to be merged!`);
// send message to slack
await client.chat.postMessage({
await client?.chat.postMessage({
channel: SLACK_CHANNEL,
text: `Merge request '${mergeRequest.title}' is ready to be merged! See ${mergeRequest.web_url}!`,
});