-
Notifications
You must be signed in to change notification settings - Fork 5
Add action to validate PR & commit messages #33
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
Merged
robnester-rh
merged 1 commit into
enterprise-contract:main
from
robnester-rh:HACBS-2653
Sep 29, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,92 @@ | ||
| name: Check Commit Message | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, edited, reopened] | ||
|
|
||
| jobs: | ||
| check-commit-message: | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| REGEX_PATTERN: '^(?i)(ref|refs|reference|references|res|resolve|resolves)[ \t]*:[ \t]*(gh-|\#|\!|[A-Za-z]+-)\d+\s*$' | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 | ||
|
|
||
| - name: Install jq | ||
| run: sudo apt-get install jq | ||
|
robnester-rh marked this conversation as resolved.
|
||
|
|
||
| - name: Fetch PR data | ||
| id: pr_data | ||
| run: | | ||
| PR_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
| "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}") | ||
| echo "PR_DATA<<EOF" >> $GITHUB_ENV | ||
| echo "$PR_DATA" >> $GITHUB_ENV | ||
| echo "EOF" >> $GITHUB_ENV | ||
|
|
||
| - name: Check PR body | ||
| run: | | ||
|
robnester-rh marked this conversation as resolved.
|
||
| # Extract the PR body from the PR_DATA environment variable | ||
| PR_BODY=$(echo "$PR_DATA" | jq -r '.body') | ||
| echo -e "$PR_BODY" > temp_message.txt | ||
| echo -e "PR Body:\n$PR_BODY" | ||
| if grep -Pq "$REGEX_PATTERN" temp_message.txt; then | ||
| echo -e "PR body meets the requirements.\n" | ||
| exit 0 | ||
| else | ||
| echo """ | ||
| PR body does not meet the requirements. | ||
|
|
||
| If PR resolves an issue or ticket, amend the PR body to | ||
| include a reference to the issue or ticket like so: | ||
|
|
||
| resolves: PROJ-1234 | ||
| or | ||
| resolves: #123 (if resolving a GitHub issue) | ||
|
|
||
| If PR does not resolve an issue or ticket, but is part of | ||
| work done on an issue, amend the PR body to include a | ||
| reference to the issue or ticket like so: | ||
|
|
||
| reference: PROJ-1234 | ||
| or | ||
| reference: #123 (if referencing a GitHub issue) | ||
|
|
||
| """ | ||
| exit 1 | ||
| fi | ||
|
|
||
|
|
||
| - name: Check PR commit messages | ||
| run: | | ||
| COMMIT_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
|
robnester-rh marked this conversation as resolved.
|
||
| "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/commits") | ||
| echo "$COMMIT_DATA" | jq -c '.[]' | while read -r commit; do | ||
| COMMIT_MESSAGE=$(echo "$commit" | jq -r '.commit.message') | ||
| echo -e "$COMMIT_MESSAGE" > temp_commit_message.txt | ||
| echo -e "Evaluating commit message:\n$COMMIT_MESSAGE" | ||
| if grep -Pq "$REGEX_PATTERN" temp_commit_message.txt; then | ||
| echo -e "Commit message meets the requirements.\n" | ||
| else | ||
| echo -e """ | ||
| Commit message does not meet the requirements.\ | ||
|
|
||
| If commit resolves an issue or ticket, amend the commit to | ||
| include a reference to the issue or ticket like so: | ||
|
|
||
| resolves: PROJ-1234 | ||
| or | ||
| resolves: #123 (if resolving a GitHub issue) | ||
|
|
||
| If commit does not resolve an issue or ticket, but was | ||
| done while working on an issue, amend the commit to include | ||
| a reference to the issue or ticket like so: | ||
|
|
||
| reference: PROJ-1234 | ||
| or | ||
| reference: #123 (if referencing a GitHub issue) | ||
| """ | ||
| exit 1 | ||
| fi | ||
| done | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.