-
Notifications
You must be signed in to change notification settings - Fork 6
[tool] chore: test #128
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
Open
guillaumejparis
wants to merge
12
commits into
release/current
Choose a base branch
from
test-title-pr
base: release/current
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[tool] chore: test #128
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d68c5fa
test pr title agent
guillaumejparis 8bf4676
test pr title agent
guillaumejparis d293ba6
test pr title agent
guillaumejparis 9b8d956
test pr title agent
guillaumejparis 5122378
test pr title agent
guillaumejparis caec71d
test pr title agent
guillaumejparis 5519f5b
test pr title agent
guillaumejparis e15556c
test pr title agent
guillaumejparis 4e517a6
test pr title agent
guillaumejparis a476a65
test pr title agent
guillaumejparis cac6549
test pr title agent
guillaumejparis c6169e7
test pr title agent
guillaumejparis 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| name: "Validate PR Title" | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, edited, reopened, ready_for_review, synchronize] | ||
|
|
||
| jobs: | ||
| validate-pr-title: | ||
| runs-on: ubuntu-latest | ||
| continue-on-error: true | ||
| permissions: | ||
| contents: read | ||
| checks: write | ||
|
|
||
| steps: | ||
| - name: Generate a token | ||
| id: generate-token | ||
| uses: actions/create-github-app-token@v2 | ||
| with: | ||
| app-id: ${{ secrets.OPENAEV_PR_CHECKS_APP_ID }} | ||
| private-key: ${{ secrets.OPENAEV_PR_CHECKS_PRIVATE_KEY }} | ||
| - name: Validate PR title and create check | ||
| shell: bash | ||
| env: | ||
| GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} | ||
| REPO: ${{ github.repository }} | ||
| SHA: ${{ github.event.pull_request.head.sha }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| TITLE="${{ github.event.pull_request.title }}" | ||
| echo "PR title: $TITLE" | ||
|
|
||
| # Skip validation for renovate | ||
| if [[ "$TITLE" == *"chore(deps)"* ]]; then | ||
| echo "⚠️ Skipping validation for renovate PRs." | ||
| OUTPUT_TITLE="⚠️ Skipping validation for Renovate PRs." | ||
| OUTPUT_SUMMARY="⚠️ Skipping validation for Renovate PRs." | ||
| CONCLUSION="success" | ||
| else | ||
| # Full pattern: | ||
| # [category/subcategory] type(scope?): description (#123) | ||
| FULL_PATTERN='^\[([a-z]+(/[a-z]+)*)\] (feat|fix|chore|docs|style|refactor|perf|test|build|ci|revert)(\([a-z-]+\))?: [a-z].*( \(#[0-9]+\))$' | ||
|
|
||
| if [[ "$TITLE" =~ $FULL_PATTERN ]]; then | ||
| echo "✅ PR title is valid." | ||
| OUTPUT_TITLE="✅ PR title is valid." | ||
| OUTPUT_SUMMARY="✅ PR title is valid." | ||
| CONCLUSION="success" | ||
| else | ||
| # Diagnose common failures | ||
|
|
||
| # 1) Check category block: [category/category] | ||
| CATEGORY_PATTERN='^\[([a-z]+(/[a-z]+)*)\]' | ||
| if ! [[ "$TITLE" =~ $CATEGORY_PATTERN ]]; then | ||
| REASON="Bad [category] block. Expected: [category] or [category/category]" | ||
| fi | ||
|
|
||
| # 2) Check type + optional scope | ||
| TYPE_PATTERN='^\[([a-z]+(/[a-z]+)*)\] (feat|fix|chore|docs|style|refactor|perf|test|build|ci|revert)(\([a-z-]+\))?: ' | ||
| if [[ -z "${REASON:-}" ]] && ! [[ "$TITLE" =~ $TYPE_PATTERN ]]; then | ||
| REASON="Bad type(scope): block. Expected type: feat, fix, chore, docs, style, refactor, perf, test, build, ci, revert (optionally with scope: type(scope):)" | ||
| fi | ||
|
|
||
| # 3) Check description starts with lowercase letter | ||
| DESC_PATTERN='^\[([a-z]+(/[a-z]+)*)\] (feat|fix|chore|docs|style|refactor|perf|test|build|ci|revert)(\([a-z-]+\))?: [a-z]' | ||
| if [[ -z "${REASON:-}" ]] && ! [[ "$TITLE" =~ $DESC_PATTERN ]]; then | ||
| REASON="Bad description. Must start with a lowercase letter after ': '" | ||
| fi | ||
|
|
||
| # 4) Check issue reference at the end: (#XXX) | ||
| ISSUE_PATTERN='\(#[0-9]+\)$' | ||
| if [[ -z "${REASON:-}" ]] && ! [[ "$TITLE" =~ $ISSUE_PATTERN ]]; then | ||
| REASON="Bad (#XXX) ending block. Missing issue reference" | ||
| fi | ||
|
|
||
| if [[ -z "${REASON:-}" ]]; then | ||
| REASON="Bad title. Does not match the required pattern" | ||
| fi | ||
|
|
||
| echo "❌ Invalid PR title: $REASON" | ||
| echo "Required format:" | ||
| echo "[category] type(scope?): description (#123)" | ||
|
|
||
| OUTPUT_TITLE="$REASON" | ||
| OUTPUT_SUMMARY="❌ Invalid PR title: $REASON. \nRequired: [category] type(scope?): description (#XXX)" | ||
| CONCLUSION="failure" | ||
| fi | ||
| fi | ||
|
|
||
| # Create custom check run | ||
| CHECK_RUN=$( | ||
| curl -sS -X POST \ | ||
| -H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| https://api.github.com/repos/$REPO/check-runs \ | ||
| -d @- <<EOF | ||
| { | ||
| "name": "Validate PR Title", | ||
| "head_sha": "$SHA", | ||
| "status": "in_progress" | ||
| } | ||
| EOF | ||
| ) | ||
|
|
||
| CHECK_RUN_ID=$(echo "$CHECK_RUN" | jq -r '.id') | ||
| echo "Created check run ID: $CHECK_RUN_ID" | ||
|
|
||
| # Complete the check run with conclusion + detailed summary | ||
| curl -sS -X PATCH \ | ||
| -H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| https://api.github.com/repos/$REPO/check-runs/$CHECK_RUN_ID \ | ||
| -d @- <<EOF | ||
| { | ||
| "name": "Validate PR Title", | ||
| "status": "completed", | ||
| "conclusion": "$CONCLUSION", | ||
| "output": { | ||
| "title": "$OUTPUT_TITLE", | ||
| "summary": "$OUTPUT_SUMMARY" | ||
| } | ||
| } | ||
| EOF | ||
|
|
||
| # Do not fail job (continue-on-error is true) | ||
| exit 0 | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this repository, the Renovate message does not follow this format; it is more like “Update …”.