Skip to content

Add approved status check#608

Merged
myakove merged 4 commits intomainfrom
approved-status-check
Oct 28, 2024
Merged

Add approved status check#608
myakove merged 4 commits intomainfrom
approved-status-check

Conversation

@myakove
Copy link
Copy Markdown
Collaborator

@myakove myakove commented Oct 27, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced approval process for pull requests with new methods for managing approval check statuses.
    • Added new constants for various pull request states to improve labeling.
  • Bug Fixes

    • Corrected string formatting in Slack messages for better clarity.
  • Chores

    • Updated .gitignore to exclude .envrc files.

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 27, 2024

Walkthrough

The pull request introduces modifications to the ProcessGithubWehook class in github_api.py, enhancing approval check handling and check run status management. New methods for queuing and confirming approval checks are added, simplifying the merge eligibility logic by focusing on the APPROVED_LABEL_STR. Additionally, new string constants related to approval and status checks are introduced in constants.py and github_repository_settings.py, updating the relevant dictionaries to incorporate these constants.

Changes

File Path Change Summary
webhook_server_container/libs/github_api.py Added methods set_approved_check_queued and set_approved_check_success to manage approval checks. Updated process_pull_request_webhook_data to utilize new methods. Minor formatting fix in send_slack_message.
webhook_server_container/utils/constants.py Added new constants: APPROVED_LABEL_STR, NEEDS_REBASE_LABEL_STR, HAS_CONFLICTS_LABEL_STR, and HOLD_LABEL_STR. Updated STATIC_LABELS_DICT and DYNAMIC_LABELS_DICT to include new constants.
webhook_server_container/utils/github_repository_settings.py Added APPROVED_LABEL_STR to default_status_checks in set_repositories_settings function.
.gitignore Added entry for .envrc to ignore environment variable files.

Possibly related issues

Possibly related PRs

Suggested labels

size/M, verified, commented-coderabbitai[bot], commented-myakove

Suggested reviewers

  • rnetser

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
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 and nitpick comments (2)
webhook_server_container/utils/constants.py (1)

27-30: LGTM! Note about HOLD_LABEL_STR usage.

The new constants follow proper naming conventions and align with GitHub label format. However, while HOLD_LABEL_STR is defined here, it appears to be redundantly defined as it's already present in USER_LABELS_DICT above.

Consider removing the duplicate definition of HOLD_LABEL_STR since it's already defined in USER_LABELS_DICT.

webhook_server_container/libs/github_api.py (1)

965-973: Simplify approval logic by removing unnecessary _approved flag

Since _approved is only set to True when _reviewer in self.approvers and used immediately afterward, you can simplify the code by directly calling self.set_approved_check_success(output=_approved_output) within the if block. This reduces the number of variables and makes the logic clearer.

Apply this diff to simplify the code:

                 _approved_output: Dict[str, Any] = {"title": "Approved", "summary": "", "text": ""}
-                _approved = False
                 if _reviewer in self.approvers:
                     _check_for_merge = True
-                    _approved = True
                     _approved_output["text"] += f"Approved by {_reviewer}.\n"

-                if _approved:
+                    self.set_approved_check_success(output=_approved_output)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c62daa8 and 4ac227f.

📒 Files selected for processing (3)
  • webhook_server_container/libs/github_api.py (7 hunks)
  • webhook_server_container/utils/constants.py (1 hunks)
  • webhook_server_container/utils/github_repository_settings.py (2 hunks)
🔇 Additional comments (5)
webhook_server_container/utils/constants.py (2)

Line range hint 44-67: LGTM! Dictionary updates are well-structured.

The new labels are appropriately categorized in their respective dictionaries with semantically meaningful colors (red for warning states, green for approval states).


Line range hint 27-67: Verify the integration of new constants.

Let's ensure these new constants are properly integrated across the codebase.

✅ Verification successful

Constants are properly integrated and used across the codebase

The verification shows that:

  • All constants (APPROVED_LABEL_STR, NEEDS_REBASE_LABEL_STR, HAS_CONFLICTS_LABEL_STR) are properly imported and used in relevant files
  • No hardcoded string values were found that should be using these constants instead
  • The constants are used consistently in both github_api.py and github_repository_settings.py
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of new constants in related files

echo "Checking usage of new constants..."
rg "APPROVED_LABEL_STR|NEEDS_REBASE_LABEL_STR|HAS_CONFLICTS_LABEL_STR" \
   --type python \
   -g '!**/constants.py'

echo -e "\nChecking for any hardcoded strings that should use these constants..."
rg "'approved'|'needs-rebase'|'has-conflicts'" \
   --type python \
   -g '!**/constants.py' \
   -g '!**/test_*.py'

Length of output: 526


Script:

#!/bin/bash
# Let's try without the --type python flag since it's not recognized
# First, check usage of the constants
echo "Checking usage of new constants..."
rg "APPROVED_LABEL_STR|NEEDS_REBASE_LABEL_STR|HAS_CONFLICTS_LABEL_STR" \
   --glob '!**/constants.py'

echo -e "\nChecking for potential hardcoded values..."
rg "'approved'|'needs-rebase'|'has-conflicts'" \
   --glob '!**/constants.py' \
   --glob '!**/test_*.py'

# Let's also check the imports of these constants
echo -e "\nChecking imports from constants..."
rg "from.*constants.*import.*|import.*constants" \
   --glob '!**/constants.py' \
   --glob '!**/test_*.py'

Length of output: 1885

webhook_server_container/utils/github_repository_settings.py (2)

17-17: LGTM!

The import of APPROVED_LABEL_STR is properly placed with related constants.


165-168: Verify the impact of adding APPROVED_LABEL_STR to status checks.

The addition of APPROVED_LABEL_STR to default status checks looks good. This will ensure that PRs require approval before merging.

Let's verify the usage and impact:

✅ Verification successful

The addition of APPROVED_LABEL_STR to default status checks is correctly implemented and safe

The verification shows that:

  • APPROVED_LABEL_STR is properly defined in constants.py and used consistently across the codebase
  • The status check integration is well-designed with:
    • Proper handling in github_api.py through dedicated methods like set_approved_check_success
    • Support for both approval labels and status checks
    • Clean integration with the existing branch protection system
  • No conflicts found with existing approval mechanisms
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of APPROVED_LABEL_STR in branch protection settings

# Test 1: Check if APPROVED_LABEL_STR is defined in constants.py
echo "Checking APPROVED_LABEL_STR definition:"
rg "APPROVED_LABEL_STR\s*=" webhook_server_container/utils/constants.py

# Test 2: Check if there are any other places where status checks are configured
echo -e "\nChecking other status check configurations:"
rg "status_checks|required_status_checks" --type py

# Test 3: Check for any potential conflicts with existing approval checks
echo -e "\nChecking for existing approval-related code:"
rg -i "approv" --type py

Length of output: 11773

webhook_server_container/libs/github_api.py (1)

700-705: New methods for approval check status are correctly implemented

The methods set_approved_check_queued and set_approved_check_success are consistent with existing check status methods and correctly manage the approval check run statuses.

Comment thread webhook_server_container/libs/github_api.py Outdated
Comment thread webhook_server_container/libs/github_api.py
@myakove-bot myakove-bot added size/S and removed size/M labels Oct 27, 2024
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

🧹 Outside diff range and nitpick comments (1)
webhook_server_container/libs/github_api.py (1)

965-973: Consider enhancing the approval status output.

The approval status output could be more informative by including a summary of the approval status.

Consider updating the output dictionary to include a descriptive summary:

 _approved_output: Dict[str, Any] = {
     "title": "Approved",
-    "summary": "",
+    "summary": "Checking approval status from repository approvers",
     "text": ""
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 17a198c and 005f65d.

📒 Files selected for processing (2)
  • .gitignore (1 hunks)
  • webhook_server_container/libs/github_api.py (7 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .gitignore
🔇 Additional comments (3)
webhook_server_container/libs/github_api.py (3)

700-705: LGTM! New approval check methods are well-implemented.

The new methods set_approved_check_queued and set_approved_check_success follow the established pattern for check status management and are consistent with other similar methods in the class.


1636-1636: LGTM! Approval check initialization is properly integrated.

The set_approved_check_queued is correctly added to the parallel execution workflow, consistent with other check initializations.


700-705: Verify the approval check implementation across the codebase.

The approval check system appears well-implemented, but let's verify its usage and integration points.

Also applies to: 965-973, 1636-1636

✅ Verification successful

Let me gather more information about the approval check system to ensure its complete verification.


Let me try one more search pattern to locate these constants and their usage.


Based on the comprehensive search results, I can now generate the final response.

Approval check implementation is correctly integrated and consistent

The approval check system is well-implemented with proper state management:

  • Initializes as queued via set_approved_check_queued() when PR is opened/synchronized
  • Updates to success via set_approved_check_success() when approved by an approver
  • Integrates with the GitHub check runs system using set_check_run_status()
  • Properly handles approval workflow through labels (APPROVED_BY_LABEL_PREFIX) and check status
  • Correctly manages state transitions in the PR lifecycle
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the approval check implementation

# Test 1: Check for any other uses of APPROVED_LABEL_STR in check runs
echo "Checking for other uses of APPROVED_LABEL_STR in check runs..."
rg "set_check_run_status.*APPROVED_LABEL_STR"

# Test 2: Verify the constant definition
echo "Verifying APPROVED_LABEL_STR constant definition..."
rg "APPROVED_LABEL_STR\s*="

# Test 3: Check for any potential conflicting approval checks
echo "Checking for potential conflicting approval checks..."
rg "approved.*check"

Length of output: 1214


Script:

#!/bin/bash
# Search for APPROVED_LABEL_STR constant definition
echo "Searching for APPROVED_LABEL_STR constant definition..."
rg "APPROVED_LABEL_STR\s*=" -B 2 -A 2

# Search for check run status constants
echo "Searching for check run status constants..."
rg "(QUEUED_STR|SUCCESS_STR)\s*=" -B 2 -A 2

# Search for approval check related function calls
echo "Searching for approval check function calls..."
ast-grep --pattern 'self.set_approved_check_$_($$$)'

Length of output: 461


Script:

#!/bin/bash
# Search for constants in a broader context
echo "Searching for check-related constants..."
rg -l "APPROVED_LABEL|QUEUED_STR|SUCCESS_STR" | xargs cat

# Search for check run related functions
echo "Searching for check run related functions..."
rg "def set_check_run" -B 2 -A 10

# Search for approval workflow
echo "Searching for approval workflow..."
rg "approved" -B 5 -A 5

Length of output: 119425

@myakove
Copy link
Copy Markdown
Collaborator Author

myakove commented Oct 28, 2024

/verified

@myakove myakove enabled auto-merge (squash) October 28, 2024 08:04
@myakove myakove merged commit dc1aeff into main Oct 28, 2024
@myakove myakove deleted the approved-status-check branch October 28, 2024 08:04
@myakove-bot
Copy link
Copy Markdown
Collaborator

New container for quay.io/myakove/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.

3 participants