From 820030491f1d12253a100fc892e9d929e00f0082 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 23 Mar 2023 10:38:17 +0100 Subject: [PATCH] tools: notify on Slack when invalid commit lands PR-URL: https://github.com/nodejs/node/pull/47178 Reviewed-By: Rich Trott Reviewed-By: Yagiz Nizipli Reviewed-By: Debadree Chatterjee Reviewed-By: Darshan Sen Reviewed-By: Tierney Cyren Reviewed-By: Akhil Marsonya Reviewed-By: Chengzhong Wu Reviewed-By: Matteo Collina --- .github/workflows/notify-force-push.yml | 28 ----------- .github/workflows/notify-on-push.yml | 66 +++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 28 deletions(-) delete mode 100644 .github/workflows/notify-force-push.yml create mode 100644 .github/workflows/notify-on-push.yml diff --git a/.github/workflows/notify-force-push.yml b/.github/workflows/notify-force-push.yml deleted file mode 100644 index 69aacc8524fd93..00000000000000 --- a/.github/workflows/notify-force-push.yml +++ /dev/null @@ -1,28 +0,0 @@ -on: - push: - branches: - - main - -name: Notify on Force Push -permissions: - contents: read - -jobs: - slackNotification: - name: Slack Notification - 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 by - - Before: - After: - SLACK_USERNAME: nodejs-bot - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} diff --git a/.github/workflows/notify-on-push.yml b/.github/workflows/notify-on-push.yml new file mode 100644 index 00000000000000..dd415a4a380dae --- /dev/null +++ b/.github/workflows/notify-on-push.yml @@ -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 by + + Before: + 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 by . + + Before: + After: + SLACK_USERNAME: nodejs-bot + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}