Skip to content

feat: add pr title validation feature #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/pr_title_validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: python validate_title.py "$PR_TITLE"
25 changes: 25 additions & 0 deletions validate_title.py
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)