Skip to content

Commit 8bac97a

Browse files
authored
GitHub Actions: add check for empty commit message
There is no checking of proposed commit message presence. PR authors may forget to include proposed commit message. Adding a check using GitHub Actions will help remind and ensure that authors don't miss out on filling in the commit message. Let's add a job to the a new workflow, pr-message-reminder.yml file to help automate checking and reminding of filling in the proposed commit message for each PR. This approach automates the process, without having to have other users check and remind PR authors themselves. Adding the new job to a new workflow will allow greater control of job triggers while maintaining clean code.
1 parent 58fbbd0 commit 8bac97a

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: PR Message Reminder
2+
on:
3+
push:
4+
branches:
5+
- master
6+
tags:
7+
- 'v[0-9]+.[0-9]+.[0-9]+'
8+
pull_request:
9+
types:
10+
- opened
11+
- synchronize
12+
- reopened
13+
- edited
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
remind-pr-author:
21+
if: github.event_name == 'pull_request'
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- uses: actions/checkout@v3
26+
- name: Extract Proposed Commit Message
27+
run: |
28+
python scripts/process_message.py "${TEXT_BODY}" > processed_body.txt
29+
processed_body=$(cat processed_body.txt)
30+
proposed_commit_message=$(echo "$processed_body" | awk '/\\*\\*Proposed commit message: \\\(wrap lines at 72 characters\\\)\\*\\*/,/\\*\\*Checklist:\\*\\*/' | tail -n +2 | head -n -3)
31+
echo "Proposed commit message:"
32+
echo "$proposed_commit_message"
33+
if ! grep -q '[^[:space:]]' <<< "$proposed_commit_message"; then
34+
echo "Please fill in the proposed commit message section in the pull request description."
35+
exit 1
36+
fi
37+
env:
38+
TEXT_BODY: ${{ github.event.pull_request.body }}
39+

scripts/process_message.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import json
2+
import re
3+
import sys
4+
5+
markdown_content = sys.argv[1]
6+
7+
# Preprocessing the markdown content
8+
markdown_content = markdown_content.replace('`', '\\`')
9+
markdown_content = markdown_content.replace('(', '\\(').replace(')', '\\)')
10+
markdown_content = re.sub(r'<!--.*?-->', '', markdown_content, flags=re.DOTALL) # Remove HTML comments
11+
12+
print(markdown_content)
13+
14+
15+

0 commit comments

Comments
 (0)