-
Notifications
You must be signed in to change notification settings - Fork 4.8k
51 lines (46 loc) · 1.9 KB
/
backport-fail-bot.yml
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
42
43
44
45
46
47
48
49
50
51
name: Forward failed backport alert to Slack
on:
issue_comment:
types: [created]
jobs:
check_comment:
runs-on: ubuntu-latest
if: github.event.issue.pull_request != null && contains(github.event.comment.body, 'cherry-pick the changes locally and resolve any conflicts')
steps:
- name: Fetch mapping file
id: fetch_mapping
uses: actions/github-script@v7
env:
ACCESS_TOKEN: ${{ secrets.PAT }}
with:
script: |
const url = 'https://raw.githubusercontent.com/Kong/github-slack-mapping/main/mapping.json';
const headers = {Authorization: `token ${process.env.ACCESS_TOKEN}`};
const response = await fetch(url, {headers});
const mapping = await response.json();
return mapping;
- name: Generate Slack Payload
id: generate-payload
uses: actions/github-script@v7
env:
SLACK_CHANNEL: gateway-notifications
SLACK_MAPPING: "${{ steps.fetch_mapping.outputs.result }}"
with:
script: |
const pr_url = ${{ github.event.issue.pull_request.html_url }};
const slack_mapping = JSON.parse(process.env.SLACK_MAPPING);
const pr_author_github_id = ${{ github.event.issue.user.login }};
const pr_author_slack_id = slack_mapping[pr_author_github_id];
const author = pr_author_slack_id ? `<@${pr_author_slack_id}>` : pr_author_github_id;
const payload = {
text: `${pr_url} from ${author} failed to backport.`,
channel: process.env.SLACK_CHANNEL,
};
return JSON.stringify(payload);
result-encoding: string
- name: Send Slack Message
uses: slackapi/slack-github-action@70cd7be8e40a46e8b0eced40b0de447bdb42f68e # v1.26.0
with:
payload: ${{ steps.generate-payload.outputs.result }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_GATEWAY_NOTIFICATIONS_WEBHOOK }}