forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 3
65 lines (61 loc) · 3.24 KB
/
notify-on-push.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
63
64
65
on:
push:
branches:
- main
name: Notify on Force Push
permissions:
contents: read
jobs:
notifyOnForcePush:
name: Notify on Force Push on `main`
if: github.repository == 'nodejs/node' && github.event.forced
runs-on: ubuntu-latest
steps:
- name: Slack Notification
uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7
env:
SLACK_COLOR: '#DE512A'
SLACK_ICON: https://github.com/nodejs.png?size=48
SLACK_TITLE: ${{ github.actor }} force-pushed to ${{ github.ref }}
SLACK_MESSAGE: |
A commit was force-pushed to <https://github.com/${{ github.repository }}/tree/${{ github.repository.default_branch }}|${{ github.repository }}@${{ github.repository.default_branch }}> by <https://github.com/${{ github.actor }}|${{ github.actor }}>
Before: <https://github.com/${{ github.repository }}/commit/${{ github.event.before }}|${{ github.event.before }}>
After: <https://github.com/${{ github.repository }}/commit/${{ github.event.after }}|${{ github.event.after }}>
SLACK_USERNAME: nodejs-bot
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
notifyOnMissingMetadata:
name: Notify on Push on `main` that lacks metadata
if: github.repository == 'nodejs/node'
runs-on: ubuntu-latest
steps:
- name: Check commit message
run: npx -q core-validate-commit ${{ github.event.commits[0].id }} || echo "INVALID_COMMIT_MESSAGE=1" >> $GITHUB_ENV
- name: Retrieve PR number if possible
if: ${{ env.INVALID_COMMIT_MESSAGE }}
run: |
node <<<'EOF'
const invalidCommitMessageMatch = /\s\(\#\d+\)$/.exec(process.env.COMMIT_MESSAGE);
if (match == null) process.exit(1)
console.log(`PR_ID=${match[0]}`)
EOF >> $GITHUB_ENV || true
env:
COMMIT_MESSAGE: ${{ github.event.commits[0].message }}
- name: Comment on the Pull Request
if: ${{ env.PR_ID }}
run: gh pr comment ${{ env.PR_ID }} --repo "${{ github.repository }}" --body "$BODY"
env:
BODY: |
A commit referencing this Pull Request was pushed to `main` by @${{ github.actor }} without the expected commit metadata added to its message.
- name: Slack Notification
if: ${{ env.INVALID_COMMIT_MESSAGE }}
uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7
env:
SLACK_COLOR: '#DE512A'
SLACK_ICON: https://github.com/nodejs.png?size=48
SLACK_TITLE: Invalid commit was pushed to ${{ github.repository.default_branch }}
SLACK_MESSAGE: |
A commit lacking the expected metadata was pushed to <https://github.com/${{ github.repository }}/tree/${{ github.repository.default_branch }}|${{ github.repository }}@${{ github.repository.default_branch }}> by <https://github.com/${{ github.actor }}|${{ github.actor }}>.
Before: <https://github.com/${{ github.repository }}/commit/${{ github.event.before }}|${{ github.event.before }}>
After: <https://github.com/${{ github.repository }}/commit/${{ github.event.after }}|${{ github.event.after }}>
SLACK_USERNAME: nodejs-bot
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}