-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
55 lines (48 loc) · 1.99 KB
/
handle_validation_result.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
name: Handle Validation Result
on:
workflow_run:
workflows: ["Commit Validation"]
types: [completed]
permissions:
contents: read
issues: write
pull-requests: write
# needed because gh cli fetches unnecessary extra data
repository-projects: read
jobs:
handle-validation-result:
runs-on: ubuntu-latest
steps:
- name: "Get PR number"
uses: actions/github-script@v6
with:
script: |
let prNumber = context.payload.workflow_run.pull_requests[0].number;
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.txt`, prNumber.toString());
- name: Mark unstale if success
if: ${{ github.event.workflow_run.conclusion == 'success' }}
run: |
export PR_NUMBER=$(cat pr_number.txt)
echo "In repo $GH_REPO on PR $PR_NUMBER"
if gh pr view -R"$GH_REPO" "$PR_NUMBER" --json labels | grep stale ; then
echo "No longer stale"
gh pr edit -R"$GH_REPO" "$PR_NUMBER" --remove-label stale
gh pr comment -R"$GH_REPO" "$PR_NUMBER" --body 'The validity checks are now passing. Thank you.'
else
echo "Was already not stale"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.event.repository.full_name }}
- name: Make comment and mark stale if failed
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
run: |
export PR_NUMBER=$(cat pr_number.txt)
echo "In repo $GH_REPO on PR $PR_NUMBER"
echo "Mark as stale"
gh pr edit -R"$GH_REPO" "$PR_NUMBER" --add-label stale
gh pr comment -R"$GH_REPO" "$PR_NUMBER" --body 'The validity checks failed. Please look at the logs (click the red X) and correct the errors. Your PR will be closed automatically in 2 days if not fixed.'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.event.repository.full_name }}