Add merge rules engine for validating PRs before landing#317
Open
seemethere wants to merge 2 commits intomasterfrom
Open
Add merge rules engine for validating PRs before landing#317seemethere wants to merge 2 commits intomasterfrom
seemethere wants to merge 2 commits intomasterfrom
Conversation
Collaborator
Author
This was referenced Jan 27, 2026
ezyang
reviewed
Mar 5, 2026
| return github_state(info).repositories[self._repository] | ||
|
|
||
|
|
||
| @dataclass |
Owner
There was a problem hiding this comment.
Recommend adding tests for the fakes
ezyang
reviewed
Mar 5, 2026
| # Merge rules related fields | ||
| files: List[str] = dataclasses.field(default_factory=list) | ||
| reviews: List[PullRequestReview] = dataclasses.field(default_factory=list) | ||
| check_runs: List[CheckRun] = dataclasses.field(default_factory=list) |
Owner
There was a problem hiding this comment.
There doesn't seem to be any API for populating these
ezyang
reviewed
Mar 5, 2026
|
|
||
| This module provides functionality to load, parse, and validate merge rules | ||
| that control when PRs can be landed. Rules specify required approvers and | ||
| CI checks based on file patterns. |
Owner
There was a problem hiding this comment.
Where is the spec for merge rules YAML?
ezyang
reviewed
Mar 5, 2026
| logging.debug("No merge_rules.yaml found in repository") | ||
| return [] | ||
| except Exception as e: | ||
| logging.warning(f"Failed to load merge rules: {e}") |
ezyang
reviewed
Mar 5, 2026
|
|
||
| This module provides functionality to load, parse, and validate merge rules | ||
| that control when PRs can be landed. Rules specify required approvers and | ||
| CI checks based on file patterns. |
Owner
There was a problem hiding this comment.
Need to explain that this is intended to be used by ghstack in a privileged context, not by the user themselves
ezyang
reviewed
Mar 5, 2026
|
|
||
| def get_pr_approvers(self, pr_number: int) -> Set[str]: | ||
| """Get set of users who have approved the PR.""" | ||
| reviews = self.github.get_pr_reviews(self.owner, self.repo, pr_number) |
Owner
There was a problem hiding this comment.
Do I have to worry about pagination for this REST query
ezyang
reviewed
Mar 5, 2026
| if not head_sha: | ||
| return {} | ||
|
|
||
| check_runs = self.github.get_check_runs(self.owner, self.repo, head_sha) |
ezyang
reviewed
Mar 5, 2026
| except Exception as e: | ||
| logging.warning(f"Failed to expand team {team_ref}: {e}") | ||
| # Return as single user if team expansion fails | ||
| return {team_ref} |
Owner
There was a problem hiding this comment.
Suppress exception here seems sloppy
ezyang
reviewed
Mar 5, 2026
|
|
||
| try: | ||
| org, team_slug = team_ref.split("/", 1) | ||
| members = self.github.get_team_members(org, team_slug) |
Owner
There was a problem hiding this comment.
Worried about pagination on this one too
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces a new merge_rules module that provides:
Also adds new GitHub API methods to GitHubEndpoint:
Adds pyyaml dependency for YAML parsing.