-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add pr title validation feature
- Loading branch information
1 parent
73f997a
commit 76a4b60
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: PR Title Validation | ||
|
||
on: | ||
pull_request: | ||
types: [opened, reopened, edited] | ||
|
||
jobs: | ||
validate_title: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Run validation script | ||
run: python validate_title.py "${{ github.event.pull_request.title }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import re | ||
import sys | ||
|
||
def validate_title(title): | ||
print("The title is:", title) | ||
prefix_pattern = r'^(build|chore|ci|docs|feat|fix|perf|refactor|style|test|sample)[:\s].+' | ||
max_length = 50 | ||
|
||
match = re.match(prefix_pattern, title, re.IGNORECASE) | ||
print("Match:", match) | ||
|
||
if not match: | ||
print("PR title must start with one of the following prefixes: build, chore, ci, docs, feat, fix, perf, refactor, style, test, sample", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
title_content = title.split(':', 1)[-1].strip() | ||
print("Title Content:", title_content) | ||
|
||
if len(title_content) > max_length: | ||
print(f"PR title content must not exceed {max_length} characters", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
if __name__ == "__main__": | ||
title = sys.argv[1] | ||
validate_title(title) |