Skip to content
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

ci: Add GH workflow to validate that PR titles follow Conventional Commits. #2

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

kirkrodrigues
Copy link
Member

@kirkrodrigues kirkrodrigues commented Oct 29, 2024

Description

Convention Commits is a specification for writing commit messages (or in our case, PR titles) that makes it easy to see at a glance what change the commit makes which in turn makes it easier to generate release notes.

This PR adds a workflow to check PR titles match the spec. Specifically, we use the amannn/action-semantic-pull-request action which defaults to using the types specified in commitizen/conventional-commit-types.

NOTE :This PR is a copy of y-scope/spider#1 but with additional comments in the workflow file.

Validation performed

This specific PR hasn't been validated but the code was validated in y-scope/spider#1.

Summary by CodeRabbit

  • New Features

    • Introduced a new GitHub Actions workflow for pull request title checks to enhance contribution guidelines.
  • Chores

    • Added configuration for improved handling of pull requests from external contributors.

Copy link

coderabbitai bot commented Oct 29, 2024

Walkthrough

A new GitHub Actions workflow file named pr-title-checks.yaml has been added to the repository. This workflow is triggered on pull requests targeting the main branch when they are edited, opened, or reopened. It uses the pull_request_target event to ensure proper permissions for external contributors and includes a job that utilizes the amannn/action-semantic-pull-request@v5 action to validate pull request titles according to the Conventional Commits specification.

Changes

File Change Summary
.github/pr-title-checks.yaml Introduced a new GitHub Actions workflow for validating pull request titles using semantic checks.

Possibly related PRs

  • chore: Add GitHub pull request and issue templates. #1: The introduction of a pull request template in this PR emphasizes adherence to the Conventional Commits specification, which aligns with the new workflow in the main PR that utilizes the semantic pull request action to validate titles.

Suggested reviewers

  • jackluo923

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 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.

Copy link

@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: 2

🧹 Outside diff range and nitpick comments (1)
.github/pr-title-checks.yaml (1)

28-30: Consider documenting supported commit types.

While the configuration is correct, it would be helpful to document the supported commit types in comments or in the repository's contributing guidelines. The action also supports customizing error messages and allowed types through optional inputs.

Add documentation above the step:

    steps:
+      # Validates PR titles against Conventional Commits spec
+      # Supported types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
+      # For more options, see: https://github.com/amannn/action-semantic-pull-request#configuration
      - uses: "amannn/action-semantic-pull-request@v5"
        env:
          GITHUB_TOKEN: "${{secrets.GITHUB_TOKEN}}"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between dc8421d and bf82fa3.

📒 Files selected for processing (1)
  • .github/pr-title-checks.yaml (1 hunks)
🔇 Additional comments (2)
.github/pr-title-checks.yaml (2)

14-16: LGTM! Well-configured permissions.

The permissions follow security best practices by implementing the principle of least privilege, requesting only the minimal "read" access required for the semantic PR action.


1-30: LGTM! Implementation aligns perfectly with PR objectives.

The workflow successfully implements PR title validation using Conventional Commits specification while properly handling external contributor permissions. The configuration is secure and efficient.

Comment on lines +10 to +12
pull_request_target:
branches: ["main"]
types: ["edited", "opened", "reopened"]
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding "synchronize" to trigger types.

The workflow currently triggers on "edited", "opened", and "reopened" events. Adding "synchronize" would ensure the title is validated when PRs are updated with new commits.

  pull_request_target:
    branches: ["main"]
-    types: ["edited", "opened", "reopened"]
+    types: ["edited", "opened", "reopened", "synchronize"]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pull_request_target:
branches: ["main"]
types: ["edited", "opened", "reopened"]
pull_request_target:
branches: ["main"]
types: ["edited", "opened", "reopened", "synchronize"]

Comment on lines +18 to +22
concurrency:
group: "${{github.workflow}}-${{github.ref}}"

# Cancel in-progress jobs for efficiency
cancel-in-progress: true
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix YAML indentation for cancel-in-progress.

The cancel-in-progress property should be aligned with the group property under concurrency.

concurrency:
  group: "${{github.workflow}}-${{github.ref}}"
-
-  # Cancel in-progress jobs for efficiency
-  cancel-in-progress: true
+  # Cancel in-progress jobs for efficiency
+  cancel-in-progress: true
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
concurrency:
group: "${{github.workflow}}-${{github.ref}}"
# Cancel in-progress jobs for efficiency
cancel-in-progress: true
concurrency:
group: "${{github.workflow}}-${{github.ref}}"
# Cancel in-progress jobs for efficiency
cancel-in-progress: true

Copy link

@anlowee anlowee left a comment

Choose a reason for hiding this comment

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

All changes make sense. But how does it get tested before this PR get merged? I guess only the PR get merged then we can use a different test PR to test this change?

@kirkrodrigues
Copy link
Member Author

All changes make sense. But how does it get tested before this PR get merged? I guess only the PR get merged then we can use a different test PR to test this change?

Yeah, you can only test it after merging the PR. So that's why in y-scope/spider#1, I validated it as follows:

  • Merged this PR into my fork.
  • Created a PR to kirkrodrigues/spider/main, triggering the workflow.
  • Validated that changing the PR title triggered the workflow.
  • Validated that the workflow detected invalid PR titles (e.g., starting with a capital letter, using an unknown type, etc.).

@kirkrodrigues kirkrodrigues changed the title ci: Add GH workflow to validate PR titles follow Conventional Commits. ci: Add GH workflow to validate that PR titles follow Conventional Commits. Oct 30, 2024
@kirkrodrigues kirkrodrigues merged commit 50183d3 into y-scope:main Oct 30, 2024
1 check passed
@kirkrodrigues kirkrodrigues deleted the add-pr-title-gh-workflow branch October 30, 2024 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants