-
Notifications
You must be signed in to change notification settings - Fork 190
ci: add conventional PR title bot for automated feedback #1767
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
base: main
Are you sure you want to change the base?
ci: add conventional PR title bot for automated feedback #1767
Conversation
Signed-off-by: Ashhar Ahmad Khan <145142826+AshharAhmadKhan@users.noreply.github.com>
WalkthroughAdds a new GitHub Actions bot script that analyzes PR titles for conventional-commit types, formats guidance messages, and posts or updates comments on PRs. Updates the PR title check workflow to invoke the script, support dry-run, and post guidance when the title check fails. Changes
Sequence DiagramsequenceDiagram
participant GitHub as GitHub
participant Workflow as GitHub Actions Workflow
participant BotScript as Bot Script
participant API as GitHub REST API
GitHub->>Workflow: PR event or workflow_dispatch
activate Workflow
Workflow->>BotScript: run(github, context, prNumber, prTitle, dryRun)
activate BotScript
BotScript->>BotScript: suggestConventionalType(prTitle)
BotScript->>BotScript: formatMessage(prTitle, suggestedType, prNumber)
BotScript->>API: GET /repos/.../issues/{prNumber}/comments (paginated)
activate API
API-->>BotScript: comments list
deactivate API
alt Existing bot comment found
BotScript->>API: PATCH /repos/.../comments/{commentId}
else No existing comment
BotScript->>API: POST /repos/.../issues/{prNumber}/comments
end
activate API
API-->>BotScript: comment created/updated
deactivate API
BotScript-->>Workflow: finished
deactivate BotScript
deactivate Workflow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
WalkthroughIntroduces a new GitHub Actions bot script that analyzes PR titles for conventional commit compliance, suggests improvements via keyword-based type detection, and automatically comments on PRs with helpful guidance. Updates the corresponding workflow to integrate the bot and provide user-friendly correction instructions. Changes
Sequence DiagramsequenceDiagram
participant GitHub as GitHub
participant Workflow as GitHub Actions Workflow
participant BotScript as Bot Script
participant API as GitHub API
GitHub->>Workflow: PR event triggered
activate Workflow
Workflow->>BotScript: run(github, context, prNumber, prTitle, dryRun)
activate BotScript
BotScript->>BotScript: suggestConventionalType(prTitle)
BotScript->>BotScript: formatMessage(title, suggestedType, prNumber)
BotScript->>API: GET /repos/.../issues/prNumber/comments
activate API
API-->>BotScript: paginated comments list
deactivate API
alt Existing bot comment found
BotScript->>API: PATCH /repos/.../comments/commentId
else No existing comment
BotScript->>API: POST /repos/.../issues/prNumber/comments
end
activate API
API-->>BotScript: comment created/updated
deactivate API
BotScript-->>Workflow: success
deactivate BotScript
deactivate Workflow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
2 similar comments
WalkthroughIntroduces a new GitHub Actions bot script that analyzes PR titles for conventional commit compliance, suggests improvements via keyword-based type detection, and automatically comments on PRs with helpful guidance. Updates the corresponding workflow to integrate the bot and provide user-friendly correction instructions. Changes
Sequence DiagramsequenceDiagram
participant GitHub as GitHub
participant Workflow as GitHub Actions Workflow
participant BotScript as Bot Script
participant API as GitHub API
GitHub->>Workflow: PR event triggered
activate Workflow
Workflow->>BotScript: run(github, context, prNumber, prTitle, dryRun)
activate BotScript
BotScript->>BotScript: suggestConventionalType(prTitle)
BotScript->>BotScript: formatMessage(title, suggestedType, prNumber)
BotScript->>API: GET /repos/.../issues/prNumber/comments
activate API
API-->>BotScript: paginated comments list
deactivate API
alt Existing bot comment found
BotScript->>API: PATCH /repos/.../comments/commentId
else No existing comment
BotScript->>API: POST /repos/.../issues/prNumber/comments
end
activate API
API-->>BotScript: comment created/updated
deactivate API
BotScript-->>Workflow: success
deactivate BotScript
deactivate Workflow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
WalkthroughIntroduces a new GitHub Actions bot script that analyzes PR titles for conventional commit compliance, suggests improvements via keyword-based type detection, and automatically comments on PRs with helpful guidance. Updates the corresponding workflow to integrate the bot and provide user-friendly correction instructions. Changes
Sequence DiagramsequenceDiagram
participant GitHub as GitHub
participant Workflow as GitHub Actions Workflow
participant BotScript as Bot Script
participant API as GitHub API
GitHub->>Workflow: PR event triggered
activate Workflow
Workflow->>BotScript: run(github, context, prNumber, prTitle, dryRun)
activate BotScript
BotScript->>BotScript: suggestConventionalType(prTitle)
BotScript->>BotScript: formatMessage(title, suggestedType, prNumber)
BotScript->>API: GET /repos/.../issues/prNumber/comments
activate API
API-->>BotScript: paginated comments list
deactivate API
alt Existing bot comment found
BotScript->>API: PATCH /repos/.../comments/commentId
else No existing comment
BotScript->>API: POST /repos/.../issues/prNumber/comments
end
activate API
API-->>BotScript: comment created/updated
deactivate API
BotScript-->>Workflow: success
deactivate BotScript
deactivate Workflow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 6
| function generateFixInstructions(suggestedType, escapedTitle, prNumber) { | ||
| return `### How to Fix This | ||
|
|
||
| #### Option 1: Via GitHub UI | ||
| 1. Go to the top of this PR page | ||
| 2. Click on the title to edit it | ||
| 3. Add the type prefix (e.g., \`${suggestedType}:\`) before your current title | ||
| 4. Save the changes | ||
|
|
||
| #### Option 2: Via Command Line | ||
| \`\`\`bash | ||
| # Note: Adjust the title as needed if it contains special characters | ||
| gh pr edit ${prNumber} --title "${suggestedType}: ${escapedTitle}" | ||
| \`\`\` | ||
|
|
||
| --- | ||
| `; | ||
| } |
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.
Shell-escape on line 154 doesn't neutralize single quotes or newlines in the CLI example.
While the bash snippet is only displayed (not executed), a title containing newlines would produce a broken multi-line command in the code block. Consider also replacing \n and \r with spaces in the shell-escaped variant for a clean CLI example.
| # Workflow to check PR titles follow conventional commit format | ||
| # and provide automated guidance when titles are invalid | ||
|
|
||
| name: PR Formatting |
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.
Workflow filename and script filename don't share a matching name.
The workflow is pr-check-title.yml but the script is bot-conventional-pr-title.js. Per coding guidelines, "Workflow filenames and their primary scripts SHOULD share a clear, matching name." Consider aligning them — e.g., renaming the script to pr-check-title.js or the workflow to bot-conventional-pr-title.yml.
As per coding guidelines, "Workflow filenames and their primary scripts SHOULD share a clear, matching name."
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.
this is correct please
|
Caution Review failedFailed to post review comments WalkthroughIntroduces a new GitHub Actions bot script that analyzes PR titles for conventional commit compliance, suggests improvements via keyword-based type detection, and automatically comments on PRs with helpful guidance. Updates the corresponding workflow to integrate the bot and provide user-friendly correction instructions. Changes
Sequence DiagramsequenceDiagram
participant GitHub as GitHub
participant Workflow as GitHub Actions Workflow
participant BotScript as Bot Script
participant API as GitHub API
GitHub->>Workflow: PR event triggered
activate Workflow
Workflow->>BotScript: run(github, context, prNumber, prTitle, dryRun)
activate BotScript
BotScript->>BotScript: suggestConventionalType(prTitle)
BotScript->>BotScript: formatMessage(title, suggestedType, prNumber)
BotScript->>API: GET /repos/.../issues/prNumber/comments
activate API
API-->>BotScript: paginated comments list
deactivate API
alt Existing bot comment found
BotScript->>API: PATCH /repos/.../comments/commentId
else No existing comment
BotScript->>API: POST /repos/.../issues/prNumber/comments
end
activate API
API-->>BotScript: comment created/updated
deactivate API
BotScript-->>Workflow: success
deactivate BotScript
deactivate Workflow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
3 similar comments
|
Caution Review failedFailed to post review comments WalkthroughIntroduces a new GitHub Actions bot script that analyzes PR titles for conventional commit compliance, suggests improvements via keyword-based type detection, and automatically comments on PRs with helpful guidance. Updates the corresponding workflow to integrate the bot and provide user-friendly correction instructions. Changes
Sequence DiagramsequenceDiagram
participant GitHub as GitHub
participant Workflow as GitHub Actions Workflow
participant BotScript as Bot Script
participant API as GitHub API
GitHub->>Workflow: PR event triggered
activate Workflow
Workflow->>BotScript: run(github, context, prNumber, prTitle, dryRun)
activate BotScript
BotScript->>BotScript: suggestConventionalType(prTitle)
BotScript->>BotScript: formatMessage(title, suggestedType, prNumber)
BotScript->>API: GET /repos/.../issues/prNumber/comments
activate API
API-->>BotScript: paginated comments list
deactivate API
alt Existing bot comment found
BotScript->>API: PATCH /repos/.../comments/commentId
else No existing comment
BotScript->>API: POST /repos/.../issues/prNumber/comments
end
activate API
API-->>BotScript: comment created/updated
deactivate API
BotScript-->>Workflow: success
deactivate BotScript
deactivate Workflow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Caution Review failedFailed to post review comments WalkthroughIntroduces a new GitHub Actions bot script that analyzes PR titles for conventional commit compliance, suggests improvements via keyword-based type detection, and automatically comments on PRs with helpful guidance. Updates the corresponding workflow to integrate the bot and provide user-friendly correction instructions. Changes
Sequence DiagramsequenceDiagram
participant GitHub as GitHub
participant Workflow as GitHub Actions Workflow
participant BotScript as Bot Script
participant API as GitHub API
GitHub->>Workflow: PR event triggered
activate Workflow
Workflow->>BotScript: run(github, context, prNumber, prTitle, dryRun)
activate BotScript
BotScript->>BotScript: suggestConventionalType(prTitle)
BotScript->>BotScript: formatMessage(title, suggestedType, prNumber)
BotScript->>API: GET /repos/.../issues/prNumber/comments
activate API
API-->>BotScript: paginated comments list
deactivate API
alt Existing bot comment found
BotScript->>API: PATCH /repos/.../comments/commentId
else No existing comment
BotScript->>API: POST /repos/.../issues/prNumber/comments
end
activate API
API-->>BotScript: comment created/updated
deactivate API
BotScript-->>Workflow: success
deactivate BotScript
deactivate Workflow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Caution Review failedFailed to post review comments WalkthroughIntroduces a new GitHub Actions bot script that analyzes PR titles for conventional commit compliance, suggests improvements via keyword-based type detection, and automatically comments on PRs with helpful guidance. Updates the corresponding workflow to integrate the bot and provide user-friendly correction instructions. Changes
Sequence DiagramsequenceDiagram
participant GitHub as GitHub
participant Workflow as GitHub Actions Workflow
participant BotScript as Bot Script
participant API as GitHub API
GitHub->>Workflow: PR event triggered
activate Workflow
Workflow->>BotScript: run(github, context, prNumber, prTitle, dryRun)
activate BotScript
BotScript->>BotScript: suggestConventionalType(prTitle)
BotScript->>BotScript: formatMessage(title, suggestedType, prNumber)
BotScript->>API: GET /repos/.../issues/prNumber/comments
activate API
API-->>BotScript: paginated comments list
deactivate API
alt Existing bot comment found
BotScript->>API: PATCH /repos/.../comments/commentId
else No existing comment
BotScript->>API: POST /repos/.../issues/prNumber/comments
end
activate API
API-->>BotScript: comment created/updated
deactivate API
BotScript-->>Workflow: success
deactivate BotScript
deactivate Workflow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Signed-off-by: Ashhar Ahmad Khan <145142826+AshharAhmadKhan@users.noreply.github.com>
- Fix missing closing brace in formatMessage function - Add COMMENT_IDENTIFIER constant definition - Add feat keyword detection for feature-related titles - Implement markdown injection prevention via escapeForMarkdown - Fix parameter naming (safeTitle vs currentTitle) - Reduce formatMessage complexity to 12 lines Signed-off-by: Ashhar Ahmad Khan <145142826+AshharAhmadKhan@users.noreply.github.com>
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.
Actionable comments posted: 1
| function escapeForMarkdown(text) { | ||
| return text | ||
| .replace(/```/g, 'ʼʼʼ') | ||
| .replace(/\r?\n|\r/g, ' ') | ||
| .trim(); | ||
| } |
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.
Unicode lookalike replacement (ʼʼʼ U+02BC) can silently corrupt copy-pasted text.
The suggested title on line 86 (${suggestedType}: ${safeTitle}) uses safeTitle, so anyone who copies the suggestion from the code block gets modifier-letter apostrophes instead of backticks. Replacing with ASCII single quotes (''') or simply stripping backticks is more transparent and avoids invisible corruption.
Proposed fix
function escapeForMarkdown(text) {
return text
- .replace(/```/g, 'ʼʼʼ')
+ .replace(/`/g, "'")
.replace(/\r?\n|\r/g, ' ')
.trim();
}- Replace multiple if-statements with loop-based pattern matching - Reduces complexity from 15 to 4 (well below Codacy limit of 12) - Maintains all functionality and keyword detection - Addresses Codacy static analysis concerns Signed-off-by: Ashhar Ahmad Khan <145142826+AshharAhmadKhan@users.noreply.github.com>
|
Hi, this is MergeConflictBot. Please resolve these conflicts locally and push the changes. Quick Fix for CHANGELOG.md ConflictsIf your conflict is only in CHANGELOG.md, you can resolve it easily using the GitHub web editor:
For all other merge conflicts, please read: Thank you for contributing! |
exploreriii
left a comment
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.
Hi @AshharAhmadKhan
Thank you for spending the time into making this and I like all the details you have added
Unfortunately, this is is a major refactor, you have even changed the underlying package we use for the title check
There are a few errors I see already with the packages you are using, so this will benefit from more research into what each package does and what is the latest release and what it entails
In this case, we have to require major testing
please do merge this to your fork, once corrections are made
Fork the repo
Create a branch in the fork
Open a PR
Trigger your invalid title
Watch what the job does
test various edge case scenarios, like a correct title
Then please link your test results
Thank you
| # Workflow to check PR titles follow conventional commit format | ||
| # and provide automated guidance when titles are invalid | ||
|
|
||
| name: PR Formatting |
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.
this is correct please
| - name: Harden the runner (Audit all outbound calls) | ||
| uses: step-security/harden-runner@e3f713f2d8f53843e71c69a996d56f51aa9adfb9 # v2.14.1 | ||
| - name: Harden Runner | ||
| uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 |
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.
Why are you suggesting 2.10.2?
https://github.com/step-security/harden-runner
Please check latest releases -- extract the commit hash
docs/sdk_developers/how-to-pin-github-actions.md
| - name: Check PR Title | ||
| uses: step-security/conventional-pr-title-action@cb1c5657ccf4c42f5c0a6c0708cb8251b960d902 # v3.2.5 | ||
| - name: Check PR title format | ||
| uses: amannn/action-semantic-pull-request@0723387faaf9b38adef4775cd42cfd5155ed6017 # v5.5.3 |
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.
if you are suggesting a change from one action package to another, we expect thorough testing please
|
|
||
| - name: Checkout repository | ||
| if: failure() | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
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.
you are consistently using outdated packages
| # Workflow to check PR titles follow conventional commit format | ||
| # and provide automated guidance when titles are invalid | ||
|
|
||
| name: PR Formatting |
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.
if you want to do dry run, it is probably better to pass it in the yml rather than construct it in the logic script
MonaaEid
left a comment
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.
could you please provide a test link for the implementation in your fork? Thank you!
Overview
This PR adds an automated bot that comments on PRs when the conventional title check fails, providing helpful guidance to contributors.
Changes
.github/scripts/bot-conventional-pr-title.js- Bot script with intelligent title suggestions.github/workflows/pr-check-title.yml- Integrated bot to run on title check failureCHANGELOG.md- Added entry under [Unreleased] → Added sectionFeatures
✅ Detects when PR title validation fails
✅ Shows current (invalid) title
✅ Suggests appropriate conventional type based on keywords
✅ Provides both UI and CLI instructions for fixing
✅ Prevents duplicate comments by updating existing ones
✅ Links to Conventional Commits documentation
Implementation Details
Bot Logic (
bot-conventional-pr-title.js)Workflow Integration (
pr-check-title.yml)pull-requests: writepermission for bot to commentif: failure())actions/github-script@v7to run bot in workflow contextRelated issue(s)
Fixes #1705
Notes for reviewer
This is a fresh, clean implementation created in response to PR #1710 being closed due to pollution.
Changes from previous PR:
upstream/main(commit11bb2f9)Testing:
bot-*.js)What to test in this PR:
Checklist