Skip to content

Commit

Permalink
PR title validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Khushboo-dev-cpp committed Jan 28, 2025
1 parent e7b0eb7 commit e2009f3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/lint_title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Conventional Commits Validator

on:
pull_request_target:

jobs:
validate:
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Validate Conventional Commits format
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repo.name }}
run: |
title="${{ github.event.pull_request.title }}"
if [[ $title =~ ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert):(.*)$ ]]; then
echo "Pull request title is correctly formatted."
else
comment="Please ensure your pull request title follows the Conventional Commits standard. Example: 'type: brief description' where type is one of fix, feat, docs,
style, refactor, perf, test, build, ci, chore, or revert."
curl -s -X POST \
https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/issues/${PR_NUMBER}/comments \
-H 'Authorization: Bearer ${GITHUB_TOKEN}' \
-H 'Content-Type: application/json' \
-d '{"body":"'"${comment}"'"}'
echo "Comment added to pull request due to incorrect title format."
fi

0 comments on commit e2009f3

Please sign in to comment.