-
Notifications
You must be signed in to change notification settings - Fork 0
62 lines (61 loc) · 2.46 KB
/
report_PR_status_as_label.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
52
53
54
55
56
57
58
59
60
61
62
name: Report PR status as label
on:
issue_comment:
types: [created]
jobs:
reportPRStatusAsLabel:
if: github.event.issue.pull_request && contains(github.event.issue.labels.*.name, 'auto-generated')
runs-on: ubuntu-latest
steps:
- name: Install jq
run: sudo apt-get install jq
- name: Checkout repository
uses: actions/checkout@v2
- name: Set env variables
run: |
echo "PR_FAIL=$(jq -r '.PR_FAIL' keywords.json)" >> $GITHUB_ENV
echo "PR_SUCCESS=$(jq -r '.PR_SUCCESS' keywords.json)" >> $GITHUB_ENV
echo "PR_ABORT=$(jq -r '.PR_ABORT' keywords.json)" >> $GITHUB_ENV
- name: Update label
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const pr = await github.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const branchName = pr.data.head.ref;
const issueNumber = branchName.split('-')[1].split('/')[0];
if (context.payload.comment.body.includes(process.env.PR_FAIL) ||
context.payload.comment.body.includes(process.env.PR_SUCCESS) ||
context.payload.comment.body.includes(process.env.PR_ABORT)) {
await github.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
name: 'submitted'
});
} if (context.payload.comment.body.includes(process.env.PR_FAIL)) {
await github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['failed']
});
} if (context.payload.comment.body.includes(process.env.PR_SUCCESS)){
await github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['completed']
});
} if (context.payload.comment.body.includes(process.env.PR_ABORT)){
await github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['aborted']
});
}