Skip to content

feat: support new pre-commit hook check-merge-base #197

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
merged 2 commits into from
Nov 13, 2024

Conversation

shenxianpeng
Copy link
Contributor

@shenxianpeng shenxianpeng commented Nov 13, 2024

closes #195

Summary by CodeRabbit

  • New Features

    • Introduced a new pre-commit hook, check-merge-base, to ensure branches are rebased onto the target branch during commits.
    • Added new hooks for check-author-name and check-author-email, which can be enabled if needed.
  • Documentation

    • Updated README.rst to include the new check-merge-base hook and modified command usage for clarity and consistency.
    • Enhanced descriptions for existing hooks in the documentation for improved clarity.

@shenxianpeng shenxianpeng added the enhancement New feature or request label Nov 13, 2024
Copy link
Contributor

coderabbitai bot commented Nov 13, 2024

Walkthrough

The changes involve the addition of a new pre-commit hook named check-merge-base in the .pre-commit-hooks.yaml file, which enforces that the current branch must be rebased onto the target branch. The README.rst file has also been updated to reflect this new hook, including modifications to the command used in the Git hooks section to incorporate the --merge-base option. Minor formatting adjustments were made to ensure consistency.

Changes

File Change Summary
.pre-commit-hooks.yaml Added new hook check-merge-base with attributes for enforcing rebase onto the target branch. Updated descriptions for existing hooks.
README.rst Updated to include new hook identifier check-merge-base and modified command to include --merge-base.
.pre-commit-config.yaml Updated repository version from v0.8.5 to v0.9.1. Added new hooks check-author-name and check-author-email (commented out).

Assessment against linked issues

Objective Addressed Explanation
Support merge-base in commit-check pre-commit hook (#195)

🐇 In the meadow where rabbits play,
A new hook hops in, brightening the day!
"Rebase," it says, "before you commit,
Keep branches aligned, let’s make it fit!"
With README updated, all clear and neat,
Our commit-check tool is now quite a treat! 🌼✨


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.

@shenxianpeng shenxianpeng marked this pull request as ready for review November 13, 2024 10:06
@shenxianpeng shenxianpeng changed the title feat: support new hook check-merge-base feat: support new pre-commit hook check-merge-base Nov 13, 2024
Copy link
Contributor

@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

🧹 Outside diff range and nitpick comments (3)
.pre-commit-hooks.yaml (1)

37-43: Consider enhancing the hook configuration.

A few suggestions to improve the hook:

  1. Consider adding a stages field to explicitly define when this hook should run (like the check-message hook does).
  2. The description could be more specific about how the target branch is determined.

Example enhancement:

 - id: check-merge-base
   name: check merge base
-  description: requiring to rebase current branch onto target branch
+  description: requiring current branch to be rebased onto the target branch (specified via --target-branch or default)
   entry: commit-check
   args: [--merge-base]
   pass_filenames: false
   language: python
+  stages: [commit, manual]
README.rst (2)

35-35: Fix typo in alternative tools comparison

There's a typo in the word "puglin" which should be "plugin".

-As an alternative to GitHub Enterprise  `Metadata restrictions <https://docs.github.com/en/enterprise-server@3.11/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/available-rules-for-rulesets#metadata-restrictions>`_ and Bitbucket's paid puglin `Yet Another Commit Checker <https://marketplace.atlassian.com/apps/1211854/yet-another-commit-checker?tab=overview&hosting=datacenter>`_, Commit Check stands out by integrating DevOps principles and Infrastructure as Code (IaC).
+As an alternative to GitHub Enterprise  `Metadata restrictions <https://docs.github.com/en/enterprise-server@3.11/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/available-rules-for-rulesets#metadata-restrictions>`_ and Bitbucket's paid plugin `Yet Another Commit Checker <https://marketplace.atlassian.com/apps/1211854/yet-another-commit-checker?tab=overview&hosting=datacenter>`_, Commit Check stands out by integrating DevOps principles and Infrastructure as Code (IaC).

78-78: Add description for the new hook

The new check-merge-base hook is added without any description. Consider adding a brief comment explaining what this hook does, similar to the comment for check-message. This will help users understand its purpose.

        -   id: check-merge-base
+        -   id: check-merge-base  # ensures current branch is rebased onto target branch
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 67a6560 and a47310f.

📒 Files selected for processing (2)
  • .pre-commit-hooks.yaml (1 hunks)
  • README.rst (3 hunks)
🔇 Additional comments (2)
.pre-commit-hooks.yaml (1)

37-43: LGTM! Hook configuration follows established patterns.

The new hook configuration is well-structured and consistent with existing hooks in the file. It properly integrates with the commit-check tool and aligns with the PR objectives.

README.rst (1)

111-111: LGTM! Command updated to support merge-base check

The Git hooks command has been correctly updated to include the new --merge-base option.

Let's verify the command-line option is properly implemented:

✅ Verification successful

LGTM! Command updated to support merge-base check

The Git hooks command has been correctly updated to include the new --merge-base option.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the --merge-base option is implemented in the code

# Search for merge-base option handling in Python files
rg -t py "merge.?base" -A 5

Length of output: 11661

Copy link

@codecov-commenter
Copy link

codecov-commenter commented Nov 13, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.27%. Comparing base (67a6560) to head (6bba256).
Report is 1 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #197   +/-   ##
=======================================
  Coverage   97.27%   97.27%           
=======================================
  Files           7        7           
  Lines         294      294           
=======================================
  Hits          286      286           
  Misses          8        8           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@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

🧹 Outside diff range and nitpick comments (1)
.pre-commit-config.yaml (1)

39-42: LGTM! New hooks are properly configured

The new hooks (check-author-name, check-author-email, and check-merge-base) are:

  • Correctly formatted and consistent with existing patterns
  • Commented out by default, following the established convention
  • Properly aligned with the PR objectives for adding merge-base functionality

Consider adding a comment explaining what the check-merge-base hook does, similar to how other hooks in the file have explanatory comments.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a47310f and 6bba256.

📒 Files selected for processing (2)
  • .pre-commit-config.yaml (1 hunks)
  • .pre-commit-hooks.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .pre-commit-hooks.yaml
🔇 Additional comments (1)
.pre-commit-config.yaml (1)

35-35: Verify the stability of commit-check v0.9.1

Let's ensure this version is stable and contains the new hooks mentioned in the PR.

✅ Verification successful

commit-check v0.9.1 is stable and free of known issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the commit-check version and its changelog

# Check the latest version and tags
gh api repos/commit-check/commit-check/tags --jq '.[0:3] | .[] | {name, commit: .commit.sha}'

# Check for any reported issues with v0.9.1
gh api search/issues -X GET -f q="repo:commit-check/commit-check is:issue label:bug v0.9.1"

Length of output: 455

@shenxianpeng shenxianpeng merged commit 166b751 into main Nov 13, 2024
25 checks passed
@shenxianpeng shenxianpeng deleted the feature/support-new-hook branch November 13, 2024 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support merge-base in commit-check pre-commit hook
2 participants