Skip to content

Commit 0c613c9

Browse files
aduh95RafaelGSS
authored andcommitted
tools: fix Slack notification action
PR-URL: #47237 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Debadree Chatterjee <[email protected]>
1 parent 461ef04 commit 0c613c9

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

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

+16-12
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,29 @@ jobs:
3131
name: Notify on Push on `main` that lacks metadata
3232
if: github.repository == 'nodejs/node'
3333
runs-on: ubuntu-latest
34+
permissions:
35+
pull-requests: write
3436
steps:
37+
- uses: actions/checkout@v3
38+
with:
39+
persist-credentials: false
3540
- name: Check commit message
36-
run: npx -q core-validate-commit ${{ github.event.commits[0].id }} || echo "INVALID_COMMIT_MESSAGE=1" >> $GITHUB_ENV
41+
run: npx -q core-validate-commit ${{ github.event.after }} || echo "INVALID_COMMIT_MESSAGE=1" >> $GITHUB_ENV
3742
- name: Retrieve PR number if possible
38-
if: ${{ env.INVALID_COMMIT_MESSAGE }}
43+
if: env.INVALID_COMMIT_MESSAGE
3944
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 }}
45+
COMMIT_TITLE=$(git --no-pager log --oneline -1 --no-color) node <<'EOF' >> $GITHUB_ENV || true
46+
const invalidCommitMessageMatch = /\s\(\#(\d+)\)$/.exec(process.env.COMMIT_TITLE);
47+
if (invalidCommitMessageMatch == null) process.exit(1)
48+
console.log(`PR_ID=${invalidCommitMessageMatch[1]}`)
49+
EOF
4750
- name: Comment on the Pull Request
4851
if: ${{ env.PR_ID }}
49-
run: gh pr comment ${{ env.PR_ID }} --repo "${{ github.repository }}" --body "$BODY"
52+
run: |
53+
gh pr comment ${{ env.PR_ID }} --repo "${{ github.repository }}" \
54+
--body "A commit referencing this Pull Request was pushed to `main` by @${{ github.actor }} without the expected commit metadata added to its message."
5055
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.
56+
GH_TOKEN: ${{ github.token }}
5357
- name: Slack Notification
5458
if: ${{ env.INVALID_COMMIT_MESSAGE }}
5559
uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7

0 commit comments

Comments
 (0)