Skip to content

feat: Add automerge command and functionality#812

Merged
myakove merged 4 commits intomainfrom
automerge-command
Jun 21, 2025
Merged

feat: Add automerge command and functionality#812
myakove merged 4 commits intomainfrom
automerge-command

Conversation

@myakove
Copy link
Copy Markdown
Collaborator

@myakove myakove commented Jun 21, 2025

This commit introduces a new /automerge command that allows authorized users (maintainers and approvers) to enable automatic merging for a pull request once all requirements are met.
The automerge label is added to the pull request upon successful command execution. The webhook server will then monitor the PR's status and merge it automatically when all checks and approval requirements are satisfied.
Key changes include:
Implemented the /automerge command logic in IssueCommentHandler.
Added permission checks to ensure only authorized users can use the command.
Updated PullRequestHandler and CheckRunHandler to support the automerge workflow.
Fixed existing tests that failed due to recent refactoring.
Updated the README.md and the pull request welcome message to document the new command.

Summary by CodeRabbit

  • New Features

    • Introduced a new /automerge command, allowing maintainers and approvers to enable automatic merging of pull requests when all requirements are met.
    • Pull requests labeled "automerge" now merge automatically after successful checks.
  • Documentation

    • Updated the README to document the new /automerge command and other user commands, including usage examples for review, approval, and testing workflows.
  • Tests

    • Removed obsolete tests related to signature verification.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 21, 2025

Warning

Rate limit exceeded

@myakove has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 15 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 33a69e8 and 9b361d5.

📒 Files selected for processing (2)
  • webhook_server/libs/check_run_handler.py (3 hunks)
  • webhook_server/libs/issue_comment_handler.py (4 hunks)

Walkthrough

This change introduces a new /automerge user command and the corresponding automerge label, enabling automatic merging of pull requests when all requirements are met. The update modifies multiple backend handlers to support the automerge workflow, and expands the README documentation with new user commands and testing instructions.

Changes

Files / Grouped Files Change Summary
README.md Added documentation for /automerge and /retest <test-name> commands under new "Review & Approval" and "Testing & Validation" subsections.
webhook_server/libs/check_run_handler.py Updated CheckRunHandler to accept OwnersFileHandler, process automerge logic, and merge PRs with the automerge label when checks succeed.
webhook_server/libs/github_api.py Refactored check run event handling to pass OwnersFileHandler to CheckRunHandler and process automerge logic.
webhook_server/libs/issue_comment_handler.py Added handling for /automerge user command, restricting its use to maintainers or approvers, and applying the automerge label.
webhook_server/libs/pull_request_handler.py Integrated automerge label into PR processing and welcome comment; updated logic to trigger merge checks on automerge label changes.
webhook_server/libs/runner_handler.py Ensured OwnersFileHandler is always available in RunnerHandler and passed to CheckRunHandler.
webhook_server/tests/test_app.py Removed tests related to signature verification and the corresponding import.
webhook_server/utils/constants.py Added COMMAND_AUTOMERGE_STR and AUTOMERGE_LABEL_STR constants; registered automerge label in USER_LABELS_DICT.

Possibly related issues

Possibly related PRs

Suggested labels

size/M, verified

Suggested reviewers

  • rnetser
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@myakove-bot
Copy link
Copy Markdown
Collaborator

Report bugs in Issues

Welcome! 🎉

This pull request will be automatically processed with the following features:

🔄 Automatic Actions

  • Reviewer Assignment: Reviewers are automatically assigned based on the OWNERS file in the repository root
  • Size Labeling: PR size labels (XS, S, M, L, XL, XXL) are automatically applied based on changes
  • Issue Creation: A tracking issue is created for this PR and will be closed when the PR is merged or closed
  • Pre-commit Checks: pre-commit runs automatically if .pre-commit-config.yaml exists
  • Branch Labeling: Branch-specific labels are applied to track the target branch
  • Auto-verification: Auto-verified users have their PRs automatically marked as verified

📋 Available Commands

PR Status Management

  • /wip - Mark PR as work in progress (adds WIP: prefix to title)
  • /wip cancel - Remove work in progress status
  • /hold - Block PR merging (approvers only)
  • /hold cancel - Unblock PR merging
  • /verified - Mark PR as verified
  • /verified cancel - Remove verification status

Review & Approval

  • /lgtm - Approve changes (looks good to me)
  • /approve - Approve PR (approvers only)
  • /assign-reviewers - Assign reviewers based on OWNERS file
  • /assign-reviewer @username - Assign specific reviewer
  • /check-can-merge - Check if PR meets merge requirements

Testing & Validation

  • /retest tox - Run Python test suite with tox
  • /retest build-container - Rebuild and test container image
  • /retest python-module-install - Test Python package installation
  • /retest pre-commit - Run pre-commit hooks and checks
  • /retest conventional-title - Validate commit message format
  • /retest all - Run all available tests

Container Operations

  • /build-and-push-container - Build and push container image (tagged with PR number)
    • Supports additional build arguments: /build-and-push-container --build-arg KEY=value

Cherry-pick Operations

  • /cherry-pick <branch> - Schedule cherry-pick to target branch when PR is merged
    • Multiple branches: /cherry-pick branch1 branch2 branch3

Label Management

  • /<label-name> - Add a label to the PR
  • /<label-name> cancel - Remove a label from the PR

✅ Merge Requirements

This PR will be automatically approved when the following conditions are met:

  1. Approval: /approve from at least one approver
  2. LGTM Count: Minimum 1 /lgtm from reviewers
  3. Status Checks: All required status checks must pass
  4. No Blockers: No WIP, hold, or conflict labels
  5. Verified: PR must be marked as verified (if verification is enabled)

📊 Review Process

Approvers and Reviewers

Approvers:

Reviewers:

Available Labels
  • hold
  • verified
  • wip
  • lgtm
  • approve

💡 Tips

  • WIP Status: Use /wip when your PR is not ready for review
  • Verification: The verified label is automatically removed on each new commit
  • Cherry-picking: Cherry-pick labels are processed when the PR is merged
  • Container Builds: Container images are automatically tagged with the PR number
  • Permission Levels: Some commands require approver permissions
  • Auto-verified Users: Certain users have automatic verification and merge privileges

For more information, please refer to the project documentation or contact the maintainers.

@myakove
Copy link
Copy Markdown
Collaborator Author

myakove commented Jun 21, 2025

/retest tox

1 similar comment
@myakove
Copy link
Copy Markdown
Collaborator Author

myakove commented Jun 21, 2025

/retest tox

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

🔭 Outside diff range comments (1)
webhook_server/libs/issue_comment_handler.py (1)

358-358: Use constant instead of hardcoded string.

Replace the hardcoded "automerge" string with the AUTOMERGE_LABEL_STR constant for consistency.

-        if automerge:
-            await self.labels_handler._add_label(pull_request=pull_request, label="automerge")
+        if automerge:
+            await self.labels_handler._add_label(pull_request=pull_request, label=AUTOMERGE_LABEL_STR)
🧹 Nitpick comments (1)
README.md (1)

626-642: Fix markdown line length violations.

The documentation content is excellent, but several lines exceed the 120-character limit as flagged by markdownlint.

Apply these line breaks to fix the formatting:

-| `/automerge`         | Enable automatic merging when all requirements are met (maintainers/approvers only) | `/automerge`         |
+| `/automerge`         | Enable automatic merging when all requirements are met (maintainers and approvers only) | `/automerge`         |
-| `/assign-reviewer`   | Assign specific reviewer                                                   | `/assign-reviewer @username` |
+| `/assign-reviewer`   | Assign specific reviewer                                                   | `/assign-reviewer @username` |
-| `/check-can-merge`   | Checks if the pull request meets all merge requirements                        | `/check-can-merge`   |
+| `/check-can-merge`   | Check if PR meets merge requirements                                       | `/check-can-merge`   |
-| `/retest <test-name>` | Run specific tests like `tox` or `pre-commit`                              | `/retest <test-name>` |
+| `/retest <test-name>` | Run specific tests like `tox` or `pre-commit`                             | `/retest <test-name>` |
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ac42f0e and 249f300.

📒 Files selected for processing (8)
  • README.md (1 hunks)
  • webhook_server/libs/check_run_handler.py (3 hunks)
  • webhook_server/libs/github_api.py (1 hunks)
  • webhook_server/libs/issue_comment_handler.py (3 hunks)
  • webhook_server/libs/pull_request_handler.py (4 hunks)
  • webhook_server/libs/runner_handler.py (1 hunks)
  • webhook_server/tests/test_app.py (1 hunks)
  • webhook_server/utils/constants.py (2 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
README.md

628-628: Line length
Expected: 120; Actual: 123

(MD013, line-length)


630-630: Line length
Expected: 120; Actual: 122

(MD013, line-length)


631-631: Line length
Expected: 120; Actual: 123

(MD013, line-length)


632-632: Line length
Expected: 120; Actual: 133

(MD013, line-length)


633-633: Line length
Expected: 120; Actual: 126

(MD013, line-length)


634-634: Line length
Expected: 120; Actual: 132

(MD013, line-length)


635-635: Line length
Expected: 120; Actual: 128

(MD013, line-length)


639-639: Line length
Expected: 120; Actual: 123

(MD013, line-length)


641-641: Line length
Expected: 120; Actual: 126

(MD013, line-length)

🪛 Pylint (3.3.7)
webhook_server/libs/check_run_handler.py

[error] 8-8: Cannot import 'webhook_server.libs.owners_files_handler' due to 'f-string expression part cannot include a backslash (webhook_server.libs.owners_files_handler, line 269)'

(E0001)


[error] 8-8: No name 'owners_files_handler' in module 'webhook_server.libs'

(E0611)

⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: tox
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: conventional-title
  • GitHub Check: python-module-install
  • GitHub Check: build-container
  • GitHub Check: pre-commit
  • GitHub Check: tox
🔇 Additional comments (11)
webhook_server/tests/test_app.py (1)

13-13: Verify that signature verification functionality is still adequately tested.

The removal of verify_signature from the imports (along with the mentioned removal of its direct unit tests) suggests this function was refactored or relocated. While signature verification is still tested indirectly through integration tests like test_process_webhook_signature_verification_failure, ensure that:

  1. The signature verification functionality hasn't been accidentally removed
  2. Test coverage for signature verification edge cases remains comprehensive
  3. The refactored implementation maintains the same security guarantees
#!/bin/bash
# Description: Verify signature verification functionality still exists and is tested
# Expected: Find signature verification logic in the codebase and confirm test coverage

echo "=== Searching for signature verification logic ==="
rg -A 10 -B 5 "signature.*verif|verif.*signature" --type py

echo -e "\n=== Searching for webhook signature handling ==="
rg -A 10 -B 5 "x-hub-signature|hub.signature|hmac.*sha256" --type py

echo -e "\n=== Checking for any remaining verify_signature references ==="
rg "verify_signature" --type py
webhook_server/utils/constants.py (1)

31-47: LGTM! Clean and consistent constant definitions.

The new automerge constants follow the established naming patterns and the color choice ("0E8A16") appropriately matches other approval-related labels.

webhook_server/libs/runner_handler.py (2)

30-30: Good defensive programming approach.

The fallback initialization ensures owners_file_handler is always available, which supports the new automerge functionality reliably.


36-38: LGTM! Proper dependency injection.

Passing the owners_file_handler to CheckRunHandler enables the automerge functionality while maintaining clean separation of concerns.

webhook_server/libs/pull_request_handler.py (3)

52-54: LGTM! Consistent with dependency injection pattern.

Passing owners_file_handler to CheckRunHandler aligns with the changes in other handlers and enables automerge functionality.


166-166: Good integration with existing label logic.

Adding AUTOMERGE_LABEL_STR to the merge check trigger condition alongside WIP_STR and HOLD_LABEL_STR is logical since all these labels affect merge eligibility.


231-231: Clear documentation for users.

The welcome message properly documents the new command with appropriate permission restrictions noted.

webhook_server/libs/issue_comment_handler.py (1)

219-219: Good exclusion logic for automerge command.

Properly excluding AUTOMERGE_LABEL_STR from generic label handling since it has dedicated logic above.

webhook_server/libs/github_api.py (1)

158-165: LGTM! Consistent pattern with other event handlers.

The changes follow the same pattern established for other webhook event handlers (issue_comment, pull_request, pull_request_review) by initializing the OwnersFileHandler and passing it to the respective handler. This enables the automerge functionality for check run events.

webhook_server/libs/check_run_handler.py (2)

30-41: LGTM! Constructor changes follow good patterns.

The constructor changes properly handle the optional OwnersFileHandler and conditionally create the LabelsHandler. The type checking and conditional initialization are implemented correctly.


7-8: Address import issues flagged by static analysis.

Static analysis tools are reporting import errors for owners_files_handler module, suggesting there may be syntax issues (f-string with backslash at line 269) in the imported module.

#!/bin/bash
# Description: Check for syntax issues in the owners_files_handler module
# Expected: Find any f-string syntax issues or import problems

# Check for f-string syntax issues with backslashes
rg -n "f[\"'][^\"']*\\\\[^\"']*[\"']" webhook_server/libs/owners_files_handler.py

# Check if the module can be imported properly
python -c "
try:
    from webhook_server.libs.owners_files_handler import OwnersFileHandler
    print('Import successful')
except Exception as e:
    print(f'Import failed: {e}')
"

Comment thread webhook_server/libs/issue_comment_handler.py
Comment thread webhook_server/libs/check_run_handler.py
@myakove myakove merged commit a902e8d into main Jun 21, 2025
6 of 10 checks passed
@myakove myakove deleted the automerge-command branch June 21, 2025 18:08
@myakove-bot
Copy link
Copy Markdown
Collaborator

New container for ghcr.io/myk-org/github-webhook-server:latest published

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.

2 participants