Skip to content

Commit 9ac01ec

Browse files
aduh95danielleadams
authored andcommitted
tools: notify on Slack when invalid commit lands
PR-URL: #47178 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Tierney Cyren <hello@bnb.im> Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 1e97ccd commit 9ac01ec

File tree

2 files changed

+66
-28
lines changed

2 files changed

+66
-28
lines changed

.github/workflows/notify-force-push.yml

-28
This file was deleted.

.github/workflows/notify-on-push.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
6+
name: Notify on Push
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
notifyOnForcePush:
12+
name: Notify on Force Push on `main`
13+
if: github.repository == 'nodejs/node' && github.event.forced
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Slack Notification
17+
uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7
18+
env:
19+
SLACK_COLOR: '#DE512A'
20+
SLACK_ICON: https://github.com/nodejs.png?size=48
21+
SLACK_TITLE: ${{ github.actor }} force-pushed to ${{ github.ref }}
22+
SLACK_MESSAGE: |
23+
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 }}>
24+
25+
Before: <https://github.com/${{ github.repository }}/commit/${{ github.event.before }}|${{ github.event.before }}>
26+
After: <https://github.com/${{ github.repository }}/commit/${{ github.event.after }}|${{ github.event.after }}>
27+
SLACK_USERNAME: nodejs-bot
28+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
29+
30+
notifyOnMissingMetadata:
31+
name: Notify on Push on `main` that lacks metadata
32+
if: github.repository == 'nodejs/node'
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Check commit message
36+
run: npx -q core-validate-commit ${{ github.event.commits[0].id }} || echo "INVALID_COMMIT_MESSAGE=1" >> $GITHUB_ENV
37+
- name: Retrieve PR number if possible
38+
if: ${{ env.INVALID_COMMIT_MESSAGE }}
39+
run: |
40+
node <<<'EOF'
41+
const invalidCommitMessageMatch = /\s\(\#\d+\)$/.exec(process.env.COMMIT_MESSAGE);
42+
if (match == null) process.exit(1)
43+
console.log(`PR_ID=${match[0]}`)
44+
EOF >> $GITHUB_ENV || true
45+
env:
46+
COMMIT_MESSAGE: ${{ github.event.commits[0].message }}
47+
- name: Comment on the Pull Request
48+
if: ${{ env.PR_ID }}
49+
run: gh pr comment ${{ env.PR_ID }} --repo "${{ github.repository }}" --body "$BODY"
50+
env:
51+
BODY: |
52+
A commit referencing this Pull Request was pushed to `main` by @${{ github.actor }} without the expected commit metadata added to its message.
53+
- name: Slack Notification
54+
if: ${{ env.INVALID_COMMIT_MESSAGE }}
55+
uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7
56+
env:
57+
SLACK_COLOR: '#DE512A'
58+
SLACK_ICON: https://github.com/nodejs.png?size=48
59+
SLACK_TITLE: Invalid commit was pushed to ${{ github.repository.default_branch }}
60+
SLACK_MESSAGE: |
61+
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 }}>.
62+
63+
Before: <https://github.com/${{ github.repository }}/commit/${{ github.event.before }}|${{ github.event.before }}>
64+
After: <https://github.com/${{ github.repository }}/commit/${{ github.event.after }}|${{ github.event.after }}>
65+
SLACK_USERNAME: nodejs-bot
66+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}

0 commit comments

Comments
 (0)