Skip to content

Commit

Permalink
feat: add pr title validation feature
Browse files Browse the repository at this point in the history
  • Loading branch information
sujoypal144 committed May 7, 2024
1 parent 73f997a commit 76a4b60
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/pr_title_validation.yml
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 }}"
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)

0 comments on commit 76a4b60

Please sign in to comment.