Skip to content

Commit

Permalink
tools: notify on Slack when invalid commit lands
Browse files Browse the repository at this point in the history
PR-URL: #47178
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Debadree Chatterjee <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Tierney Cyren <[email protected]>
Reviewed-By: Akhil Marsonya <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
aduh95 authored and danielleadams committed Jul 6, 2023
1 parent 1e97ccd commit 9ac01ec
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 28 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/notify-force-push.yml

This file was deleted.

66 changes: 66 additions & 0 deletions .github/workflows/notify-on-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
on:
push:
branches:
- main

name: Notify on 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 }}

0 comments on commit 9ac01ec

Please sign in to comment.