-
Notifications
You must be signed in to change notification settings - Fork 18
/
closedPRs.ts
41 lines (37 loc) · 1.28 KB
/
closedPRs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { danger, peril } from "danger"
import { IncomingWebhook } from "@slack/client"
// Ping slack channels for related labels
// https://github.com/artsy/peril-settings/issues/33
export default async () => {
const pr = danger.github.pr
// You can get the channel ID by opening slack in
// the web inspector and looking at the channel name
const labelsMap = {
consignments: "C52403S10",
auctions: "C0C4AJ1PF",
analytics: "C0KEQD4B0",
} as any
// Find the labels in both the map above, and in the PR's labels
const allWantedLabels = Object.keys(labelsMap)
const labelsToAlert: string[] = danger.github.issue.labels
.map(l => l.name.toLowerCase())
.filter((l: string) => allWantedLabels.includes(l))
// Loop through and send out Slack messages
for (const label of labelsToAlert) {
var url = peril.env.SLACK_RFC_WEBHOOK_URL || ""
var webhook = new IncomingWebhook(url)
await webhook.send({
unfurl_links: false,
channel: labelsMap[label],
attachments: [
{
color: "good",
title: `PR merged on ${pr.base.repo.name} - ${pr.title}`,
title_link: `${pr.base.repo.html_url}/pull/${pr.number}`,
author_name: pr.user.login,
author_icon: pr.user.avatar_url,
},
],
})
}
}