Skip to content

Commit

Permalink
Use Github Actions to check PR messages (ouster-lidar#513)
Browse files Browse the repository at this point in the history
* Repo settings now always squash merge
* Default commit message is lifted from PR description
  • Loading branch information
kairenw authored May 8, 2023
1 parent d730798 commit 2554e13
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/check_title_and_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os
import sys
import re

title_re = r'\A[0-9A-Z][\x20-\x7E]{0,88}([a-zA-Z0-9]|[\)])'
description_re = r'(((\r)?\n[\20-\x7E]{0,100})+)?(\n)?'

title = os.environ.get("TITLE")
pr_number_string = os.environ.get("PR_NUMBER")
pr_description = "\n" + os.environ.get("PR_BODY")

# check title length with (PR number) added at end
new_title = title + " (#" + pr_number_string + ")"

error = False
print(f"Checking PR title {repr(new_title)}...")
if not re.fullmatch(title_re, new_title):
print(f"Error: Please revise the PR title {new_title} "
"to match the regex {title_re} where:\n"
"* the first letter is a capital letter or numeral 0-9\n"
"* title is more than 2 characters long\n"
"* the title is no longer than 90 characters including "
"the addition of (###) for the PR number")
error = True

print(f"Checking PR description {repr(pr_description)}")
if not re.fullmatch(description_re, pr_description):
print(f"Error: The PR description {repr(pr_description)}, "
"which will be treated as your commit message, does "
"not match the regex {description_re}")
error = True

if error:
sys.exit(1)
19 changes: 19 additions & 0 deletions .github/workflows/check-commit-message.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: check-merge-commit-message-on-PR

run-name: Check merge commit messages by ${{ github.actor }} on ${{ github.ref }}
on: [pull_request]

jobs:
check_title_and_description:
if: github.event_name == 'pull_request' && ! github.event.pull_request.draft
name: check PR title and description
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: check PR title and description
run: python .github/check_title_and_description.py
shell: bash
env:
TITLE: ${{ github.event.pull_request.title }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_BODY: ${{ github.event.pull_request.body }}

0 comments on commit 2554e13

Please sign in to comment.