Skip to content

feat: support merge-base option #86

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 12 commits into from
Nov 12, 2024
Merged

Conversation

shenxianpeng
Copy link
Contributor

@shenxianpeng shenxianpeng commented Nov 12, 2024

closes #85

related to commit-check/commit-check#191

Summary by CodeRabbit

  • New Features

    • Introduced a new optional input parameter merge-base for checking if the current branch is rebased onto the target branch.
    • Enhanced GitHub Actions workflow to include the merge-base parameter for improved functionality.
  • Documentation

    • Updated README.md to include details about the new merge-base parameter and its default state.
    • Clarified descriptions for existing parameters in the documentation.
  • Bug Fixes

    • Improved error messaging for branch rebasing checks to guide users effectively.

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

coderabbitai bot commented Nov 12, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes introduced in this pull request enhance the Commit Check GitHub Action by adding a new optional input parameter, merge-base, which checks if the current branch is rebased onto the target branch. This feature is reflected in multiple files, including the workflow configuration, action metadata, and documentation. Additionally, a new environment variable, MERGE_BASE, is incorporated into the script to support this functionality. Overall, the modifications aim to improve the validation process for branch rebasing without altering existing checks or workflows.

Changes

File Change Summary
.github/workflows/commit-check.yml Added merge-base: true parameter to self-test action step. Added fetch-depth: 0 to checkout action.
action.yml Introduced new optional input parameter merge-base with default value false.
README.md Updated to include merge-base parameter details, modified descriptions for consistency, and clarified pr-comments.
main.py Added new environment variable MERGE_BASE and updated run_commit_check function to include --merge-base in command arguments.

Assessment against linked issues

Objective Addressed Explanation
Support new option merge_base (#85)

🐇 In the meadow, I hop with glee,
A new merge-base for you and me!
With checks in place, we’ll never stray,
Branches aligned, come what may!
So let’s commit and push with cheer,
For rebased paths, we hold so dear! 🌼


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
Contributor

github-actions bot commented Nov 12, 2024

Commit-Check ✔️

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 (7)
.github/workflows/commit-check.yml (1)

27-27: Add inline documentation for the merge-base parameter

The purpose and behavior of this new parameter should be documented in the workflow file for better maintainability.

Add a comment explaining the parameter:

+          # Validates if the current branch is properly rebased onto the target branch
           merge-base: true
.commit-check.yml (2)

26-26: Remove unnecessary empty line

The empty line between checks affects readability and isn't consistent with the spacing between other checks.

   suggest: run command `git config user.email yourname@example.com`
-

  - check: merge_base

29-30: Improve error and suggestion messages with more specific guidance

The current messages could be more helpful by including specific commands and the target branch name.

-    error: Current branch is not rebased onto target branch
-    suggest: please ensure your branch is rebased with the target branch
+    error: Current branch is not rebased onto the target branch (${TARGET_BRANCH})
+    suggest: Run these commands to rebase:\n  git fetch origin ${TARGET_BRANCH}\n  git rebase origin/${TARGET_BRANCH}
action.yml (1)

Line range hint 52-61: Critical: Missing environment variable for merge-base input

The merge-base input parameter needs to be passed to the Python script through an environment variable, similar to other inputs.

Add the missing environment variable mapping:

      env:
        MESSAGE: ${{ inputs.message }}
        BRANCH: ${{ inputs.branch }}
        AUTHOR_NAME: ${{ inputs.author-name }}
        AUTHOR_EMAIL: ${{ inputs.author-email }}
        COMMIT_SIGNOFF: ${{ inputs.commit-signoff }}
        DRY_RUN: ${{ inputs.dry-run }}
        JOB_SUMMARY: ${{ inputs.job-summary }}
        PR_COMMENTS: ${{ inputs.pr-comments }}
+       MERGE_BASE: ${{ inputs.merge-base }}
main.py (1)

Line range hint 41-63: Consider adding docstring for merge-base functionality

While the implementation is solid, it would be helpful to add documentation explaining:

  • The purpose of the merge-base check
  • Expected values and behavior
  • Impact on the overall commit check process

Add a docstring to explain the merge-base functionality:

 def run_commit_check() -> int:
-    """Runs the commit-check command and logs the result."""
+    """Runs the commit-check command and logs the result.
+    
+    The following checks are performed:
+    - Message format validation
+    - Branch naming convention
+    - Author name and email verification
+    - Commit sign-off requirement
+    - Merge base validation (ensures current branch is rebased onto target branch)
+    
+    Returns:
+        int: The return code from the commit-check command execution
+    """
README.md (2)

76-82: Improve documentation clarity and fix grammar issues.

The documentation for the new merge-base parameter needs some improvements:

  1. Fix grammar: "disable" should be "disabled"
  2. Fix capitalization: "by default" should be "By default"
  3. Add more context about what "rebased onto target branch" means and its implications

Apply this diff:

 ### `merge-base`

 - **Description**: check current branch is rebased onto target branch.
 - Default: 'false'

 > [!IMPORTANT]
-> `merge-base` is an experimental feature. by default it's disable.
+> `merge-base` is an experimental feature. By default it's disabled. When enabled, it ensures your branch contains all commits from the target branch, helping prevent merge conflicts and maintain a clean git history.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~82-~82: A comma is probably missing here.
Context: ...ge-baseis an experimental feature. by default it's disable. ###dry-run` - **Descr...

(MISSING_COMMA_AFTER_INTRODUCTORY_PHRASE)


100-102: Fix grammar and capitalization in the important notice.

The notice about the experimental pr-comments feature needs some improvements:

Apply this diff:

 > [!IMPORTANT]
-> `pr-comments` is an experimental feature. by default it's disable. To use it you need to set `GITHUB_TOKEN` in the GitHub Action.
+> `pr-comments` is an experimental feature. By default it's disabled. To use it, you need to set `GITHUB_TOKEN` in the GitHub Action.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~100-~100: A comma is probably missing here.
Context: ...omments` is an experimental feature. by default it's disable. To use it you need to set...

(MISSING_COMMA_AFTER_INTRODUCTORY_PHRASE)


[typographical] ~100-~100: It seems that a comma is missing.
Context: ...eature. by default it's disable. To use it you need to set GITHUB_TOKEN in the G...

(IN_ORDER_TO_VB_COMMA)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 92872c1 and 3d0d663.

📒 Files selected for processing (5)
  • .commit-check.yml (1 hunks)
  • .github/workflows/commit-check.yml (1 hunks)
  • README.md (2 hunks)
  • action.yml (1 hunks)
  • main.py (3 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[uncategorized] ~82-~82: A comma is probably missing here.
Context: ...ge-baseis an experimental feature. by default it's disable. ###dry-run` - **Descr...

(MISSING_COMMA_AFTER_INTRODUCTORY_PHRASE)


[uncategorized] ~100-~100: A comma is probably missing here.
Context: ...omments` is an experimental feature. by default it's disable. To use it you need to set...

(MISSING_COMMA_AFTER_INTRODUCTORY_PHRASE)


[typographical] ~100-~100: It seems that a comma is missing.
Context: ...eature. by default it's disable. To use it you need to set GITHUB_TOKEN in the G...

(IN_ORDER_TO_VB_COMMA)

🔇 Additional comments (8)
.github/workflows/commit-check.yml (1)

27-27: 🛠️ Refactor suggestion

Inconsistent parameter naming across files

The parameter uses hyphenated format (merge-base) in workflow but the AI summary indicates underscore format (merge_base) in implementation. This inconsistency could lead to confusion.

Let's verify the naming convention across files:

#!/bin/bash
# Description: Check naming consistency
# Expected: Should show all occurrences of both merge-base and merge_base

# Search for both naming conventions
echo "Hyphenated format:"
rg "merge-base"

echo -e "\nUnderscore format:"
rg "merge_base"

Standardize the naming convention across all files to either:

  • Hyphenated format: merge-base (GitHub Actions convention)
  • Underscore format: merge_base (Python convention)
.commit-check.yml (1)

27-30: Verify integration with action implementation

The merge-base check configuration looks good, but let's verify its integration with the action implementation.

action.yml (1)

28-31: LGTM: Well-structured input parameter definition

The new merge-base input parameter is properly defined with clear description, required flag, and default value, following the same pattern as other input parameters.

main.py (3)

19-19: LGTM: Environment variable declaration follows established patterns

The new MERGE_BASE environment variable is correctly declared with appropriate default value, maintaining consistency with other boolean flags in the codebase.


36-36: LGTM: Logging implementation is consistent

The logging of MERGE_BASE follows the established pattern and is properly placed within the log_env_vars function.


50-56: Verify commit-check CLI support for --merge-base flag

The implementation correctly adds the merge-base option to the command arguments. However, we should verify that the commit-check command supports this new flag.

README.md (2)

42-42: LGTM! Example configuration is clear and well-placed.

The new merge-base parameter is appropriately added to the example configuration with a safe default value of false.


63-63: LGTM! Parameter descriptions are consistent and clear.

The updated descriptions maintain a consistent style with proper punctuation.

Also applies to: 68-68, 73-73, 91-91, 96-96

@shenxianpeng shenxianpeng force-pushed the feature/support-merge-base branch from 3d0d663 to 28387a7 Compare November 12, 2024 15:40
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: 1

🧹 Outside diff range and nitpick comments (2)
README.md (2)

76-84: Fix grammatical issues in merge-base documentation

There are several grammatical issues in the documentation that should be addressed.

- > `merge-base` is an experimental feature. by default it's disable.
- > To use this feature, you need fetch all history for all branches by setting `fetch-depth: 0` in `actions/checkout`.
+ > `merge-base` is an experimental feature. By default, it's disabled.
+ > To use this feature, you need to fetch all history for all branches by setting `fetch-depth: 0` in `actions/checkout`.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~82-~82: A comma is probably missing here.
Context: ...ge-base` is an experimental feature. by default it's disable. > > To use this feature,...

(MISSING_COMMA_AFTER_INTRODUCTORY_PHRASE)


[grammar] ~84-~84: The verb “fetch” needs to be in the to-infinitive form.
Context: ... disable. > > To use this feature, you need fetch all history for all branches by setting...

(MISSING_TO_BEFORE_A_VERB)


102-104: Fix grammatical issues in PR comments documentation

Similar grammatical issues need to be addressed in the PR comments section.

- > `pr-comments` is an experimental feature. by default it's disable. To use it you need to set `GITHUB_TOKEN` in the GitHub Action.
+ > `pr-comments` is an experimental feature. By default, it's disabled. To use it, you need to set `GITHUB_TOKEN` in the GitHub Action.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~102-~102: A comma is probably missing here.
Context: ...omments` is an experimental feature. by default it's disable. To use it you need to set...

(MISSING_COMMA_AFTER_INTRODUCTORY_PHRASE)


[typographical] ~102-~102: It seems that a comma is missing.
Context: ...eature. by default it's disable. To use it you need to set GITHUB_TOKEN in the G...

(IN_ORDER_TO_VB_COMMA)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3d0d663 and e55fd3c.

📒 Files selected for processing (5)
  • .commit-check.yml (1 hunks)
  • .github/workflows/commit-check.yml (2 hunks)
  • README.md (2 hunks)
  • action.yml (2 hunks)
  • main.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • .commit-check.yml
  • action.yml
  • main.py
🧰 Additional context used
🪛 LanguageTool
README.md

[uncategorized] ~82-~82: A comma is probably missing here.
Context: ...ge-base` is an experimental feature. by default it's disable. > > To use this feature,...

(MISSING_COMMA_AFTER_INTRODUCTORY_PHRASE)


[grammar] ~84-~84: The verb “fetch” needs to be in the to-infinitive form.
Context: ... disable. > > To use this feature, you need fetch all history for all branches by setting...

(MISSING_TO_BEFORE_A_VERB)


[uncategorized] ~102-~102: A comma is probably missing here.
Context: ...omments` is an experimental feature. by default it's disable. To use it you need to set...

(MISSING_COMMA_AFTER_INTRODUCTORY_PHRASE)


[typographical] ~102-~102: It seems that a comma is missing.
Context: ...eature. by default it's disable. To use it you need to set GITHUB_TOKEN in the G...

(IN_ORDER_TO_VB_COMMA)

🔇 Additional comments (4)
.github/workflows/commit-check.yml (2)

18-18: LGTM: Required for merge-base functionality

Setting fetch-depth: 0 is necessary to fetch the complete git history, which is required for determining the merge-base between branches.


28-28: Consider the implications of enabling experimental feature in self-test

The previous review comment about the experimental status of merge-base is still valid.

#!/bin/bash
# Description: Verify merge-base parameter configuration
# Expected: Should show merge-base marked as experimental with default: false

# Check action.yml for merge-base input configuration
rg -A 5 "merge-base:" action.yml
README.md (2)

63-63: LGTM: Documentation style improvements

The updates maintain consistency by ensuring all parameter descriptions end with periods.

Also applies to: 68-68, 73-73


93-93: LGTM: Documentation style improvements

The updates maintain consistency by ensuring all parameter descriptions end with periods.

Also applies to: 98-98

@shenxianpeng shenxianpeng merged commit 8d507e1 into main Nov 12, 2024
1 of 2 checks passed
@shenxianpeng shenxianpeng deleted the feature/support-merge-base branch November 12, 2024 18:36
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 new option merge_base
1 participant