Skip to content

feat: add conventional-title check to check pr title#666

Merged
myakove merged 3 commits intomainfrom
conventional-commit-msg-enforce
Feb 25, 2025
Merged

feat: add conventional-title check to check pr title#666
myakove merged 3 commits intomainfrom
conventional-commit-msg-enforce

Conversation

@myakove
Copy link
Copy Markdown
Collaborator

@myakove myakove commented Feb 25, 2025

Summary by CodeRabbit

  • New Features
    • Introduced an automated validation for pull request titles. Now, pull request titles must start with one of the allowed conventional prefixes (e.g., ci, docs, feat, fix, refactor, test, release) to pass the check. This ensures consistency and improves the quality of submissions.
    • Added a new configuration option for specifying the conventional title prefixes in the repository settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 25, 2025

Walkthrough

This pull request introduces a new configuration option, conventional-title, to validate pull request titles against allowed conventional prefixes. The update spans configuration files and schema definitions, enhancing the GitHub API integration with a constant, new methods for status management, and corresponding validations. The changes focus solely on adding and utilizing the new conventional title check without modifying existing functionality.

Changes

Files Change Summary
example.config.yaml, webhook_server_container/config/schema.yaml Added a new conventional-title option in the configuration file and as a string property in the schema definition for validating PR title prefixes.
webhook_server_container/libs/github_api.py, webhook_server_container/utils/constants.py Introduced the constant CONVENTIONAL_TITLE_STR and added several methods to handle PR title check status updates and validations in the GitHub API integration.

Possibly related PRs

  • myk-org/github-webhook-server#608: Enhances PR title and status check management in the GitHub API, sharing similar code-level adjustments with this PR.

Suggested labels

verified, can-be-merged, approved-rnetser

Suggested reviewers

  • rnetser
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@myakove-bot
Copy link
Copy Markdown
Collaborator

Report bugs in Issues

The following are automatically added:

  • Add reviewers from OWNER file (in the root of the repository) under reviewers section.
  • Set PR size label.
  • New issue is created for the PR. (Closed when PR is merged/closed)
  • Run pre-commit if .pre-commit-config.yaml exists in the repo.

Available user actions:

  • To mark PR as WIP comment /wip to the PR, To remove it from the PR comment /wip cancel to the PR.
  • To block merging of PR comment /hold, To un-block merging of PR comment /hold cancel.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
  • To cherry pick a merged PR comment /cherry-pick <target branch to cherry-pick to> in the PR.
    • Multiple target branches can be cherry-picked, separated by spaces. (/cherry-pick branch1 branch2)
    • Cherry-pick will be started when PR is merged
  • To build and push container image command /build-and-push-container in the PR (tag will be the PR number).
    • You can add extra args to the Podman build command
      • Example: /build-and-push-container --build-arg OPENSHIFT_PYTHON_WRAPPER_COMMIT=<commit_hash>
  • To add a label by comment use /<label name>, to remove, use /<label name> cancel
  • To assign reviewers based on OWNERS file use /assign-reviewers
  • To check if PR can be merged use /check-can-merge
  • to assign reviewer to PR use /assign-reviewer @<reviewer>
Supported /retest check runs
  • /retest tox: Retest tox
  • /retest build-container: Retest build-container
  • /retest python-module-install: Retest python-module-install
  • /retest pre-commit: Retest pre-commit
  • /retest all: Retest all
Supported labels
  • hold
  • verified
  • wip
  • lgtm

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
webhook_server_container/config/schema.yaml (1)

151-152: Improve the conventional-title schema definition.

The property definition is missing the proper schema structure that would make it consistent with other properties in the file. Consider adding type definition and description for better documentation.

-  conventional-title: string
+  conventional-title:
+    type: string
+    description: Comma-separated list of conventional prefixes allowed in pull request titles
webhook_server_container/libs/github_api.py (1)

2253-2269: Enhance conventional title validation to match full conventional commit format.

The current implementation only checks if the PR title starts with any of the allowed prefixes, but it doesn't verify the full conventional format which typically requires a colon after the prefix (e.g., "feat: Add new feature").

Consider updating the validation to check for the complete format:

-            if any([title.startswith(_name) for _name in allowed_names]):
+            if any([title.startswith(f"{_name}: ") for _name in allowed_names]):
                 self.set_conventional_title_success(output=output)

Also, update the error message to be more specific:

-                output["text"] = f"pull_request title must starts with allowed title: {', '.join(allowed_names)}"
+                output["text"] = f"Pull request title must follow the conventional format: '{prefix}: Description' where prefix is one of: {', '.join(allowed_names)}"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e03168 and 5224df1.

📒 Files selected for processing (4)
  • example.config.yaml (1 hunks)
  • webhook_server_container/config/schema.yaml (1 hunks)
  • webhook_server_container/libs/github_api.py (6 hunks)
  • webhook_server_container/utils/constants.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build-container
  • GitHub Check: python-module-install
  • GitHub Check: tox
  • GitHub Check: pre-commit
🔇 Additional comments (7)
webhook_server_container/utils/constants.py (1)

16-16: LGTM!

The new constant follows the naming convention and is appropriately placed in the constants list.

example.config.yaml (1)

96-96: LGTM!

The configuration is well-documented with a clear comment explaining the purpose of the conventional title check.

webhook_server_container/libs/github_api.py (5)

47-47: LGTM!

The import is correctly added to the alphabetically sorted list of constants.


431-433: LGTM!

The implementation correctly retrieves the configuration value using the same pattern as other configuration options.


750-760: LGTM!

The status management methods follow the same consistent pattern as other similar methods in the file.


1727-1729: LGTM!

The implementation correctly adds the conventional title check to the required status checks when configured.


868-869: LGTM!

The implementation correctly integrates the conventional title check into the pull request webhook processing flow.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a 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

🧹 Nitpick comments (2)
webhook_server_container/libs/github_api.py (2)

2253-2269: Complete implementation of conventional title check logic.

The implementation correctly validates that PR titles start with one of the allowed prefixes specified in the configuration. The logic is simple and effective.

A couple of potential improvements to consider:

  1. The check could be more robust by splitting on : and checking only the prefix part
  2. The allowed prefixes could be trimmed of whitespace for better user experience
-            allowed_names = self.conventional_title.split(",")
-            title = self.pull_request.title
-            if any([title.startswith(_name) for _name in allowed_names]):
+            allowed_names = [name.strip() for name in self.conventional_title.split(",")]
+            title = self.pull_request.title
+            # Check if title starts with any allowed prefix (optionally followed by ":")
+            if any([title.startswith(_name) or title.startswith(f"{_name}:") for _name in allowed_names]):

2256-2259: Consider adding more detailed output for successful checks.

Currently, the success case doesn't provide any feedback in the output. Consider adding informative text to acknowledge which convention was matched.

             output: Dict[str, str] = {
                 "title": "Conventional Title",
                 "summary": "",
                 "text": "",
             }
             self.set_conventional_title_in_progress()
             allowed_names = self.conventional_title.split(",")
             title = self.pull_request.title
             if any([title.startswith(_name) for _name in allowed_names]):
+                output["summary"] = "Success"
+                output["text"] = f"Pull request title follows the conventional format."
                 self.set_conventional_title_success(output=output)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5224df1 and 90ae1ee.

📒 Files selected for processing (1)
  • webhook_server_container/libs/github_api.py (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: tox
  • GitHub Check: build-container
  • GitHub Check: pre-commit
  • GitHub Check: python-module-install
🔇 Additional comments (5)
webhook_server_container/libs/github_api.py (5)

47-47: Import of new constant looks good.

The constant CONVENTIONAL_TITLE_STR is properly imported from the constants module.


431-433: Good implementation of configuration retrieval.

The code correctly retrieves the conventional-title configuration using the existing get_value_from_dicts helper function, which handles fallbacks between repository-specific and global configurations.


750-761: Status management methods follow consistent patterns.

These new methods for managing the conventional title check status follow the same pattern as other similar status methods in the codebase, which is good for consistency and maintainability.


868-869: Appropriate placement of check initiation.

The conventional title check is correctly initiated in the process_pull_request_webhook_data method, which ensures it runs when pull requests are opened or updated.


1727-1729: Correctly added to required status checks.

The conventional title check is properly added to the list of required status checks when it's enabled in the configuration, which ensures PRs can't be merged without passing this check.

Comment thread webhook_server_container/libs/github_api.py
Comment thread webhook_server_container/libs/github_api.py Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
webhook_server_container/libs/github_api.py (2)

2267-2268: Improve error message readability.

The current error message format may be confusing to users. The ': ,'.join(allowed_names) will produce output like feat: ,fix: ,docs which isn't the clearest way to present the allowed prefixes.

-                output["text"] = f"Pull request title must starts with allowed title: {': ,'.join(allowed_names)}"
+                output["text"] = f"Pull request title must start with one of the allowed prefixes followed by a colon: {', '.join(allowed_names)}"

2262-2264: Consider adding additional validation for conventional titles.

The current implementation only checks if the title starts with an allowed prefix followed by a colon. For a more robust implementation, you might want to consider additional validations such as:

  1. Ensuring there's content after the prefix and colon (e.g., "feat: add new feature" rather than just "feat:")
  2. Checking for proper spacing after the colon
  3. Supporting scopes in parentheses (e.g., "feat(scope): description")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 90ae1ee and a3b102a.

📒 Files selected for processing (1)
  • webhook_server_container/libs/github_api.py (6 hunks)
🧰 Additional context used
🧠 Learnings (1)
webhook_server_container/libs/github_api.py (1)
Learnt from: myakove
PR: myk-org/github-webhook-server#666
File: webhook_server_container/libs/github_api.py:2254-2255
Timestamp: 2025-02-25T12:01:42.999Z
Learning: In the ProcessGithubWehook class, the `self.conventional_title` attribute is set during initialization by the `_repo_data_from_config()` method, and doesn't need additional existence checks.
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: python-module-install
  • GitHub Check: tox
  • GitHub Check: pre-commit
  • GitHub Check: build-container
🔇 Additional comments (1)
webhook_server_container/libs/github_api.py (1)

2253-2270: The conventional title check implementation looks good.

The implementation properly validates PR titles against configured conventional prefixes and follows the same patterns as other checks in the codebase. It clearly reports success or failure depending on whether the PR title starts with an allowed prefix followed by a colon.

@myakove
Copy link
Copy Markdown
Collaborator Author

myakove commented Feb 25, 2025

/verified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants