-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[mergebot] Add all-green option #77660
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -379,6 +379,7 @@ def parse_args() -> Any: | |
| parser = ArgumentParser("Merge PR into default branch") | ||
| parser.add_argument("--dry-run", action="store_true") | ||
| parser.add_argument("--on-green", action="store_true") | ||
| parser.add_argument("--all-green", action="store_true") | ||
| parser.add_argument("--revert", action="store_true") | ||
| parser.add_argument("--force", action="store_true") | ||
| parser.add_argument("--comment-id", type=int) | ||
|
|
@@ -858,7 +859,7 @@ def prefix_with_github_url(suffix_str: str) -> str: | |
| return f"https://github.com/{suffix_str}" | ||
|
|
||
|
|
||
| def merge_on_green(pr_num: int, repo: GitRepo, dry_run: bool = False, timeout_minutes: int = 400) -> None: | ||
| def merge_on_green(pr_num: int, repo: GitRepo, dry_run: bool = False, timeout_minutes: int = 400, all_green: bool = False) -> None: | ||
| repo = GitRepo(get_git_repo_dir(), get_git_remote_name()) | ||
| org, project = repo.gh_owner_and_name() | ||
| start_time = time.time() | ||
|
|
@@ -868,10 +869,25 @@ def merge_on_green(pr_num: int, repo: GitRepo, dry_run: bool = False, timeout_mi | |
| current_time = time.time() | ||
| elapsed_time = current_time - start_time | ||
|
|
||
|
|
||
| pr = GitHubPR(org, project, pr_num) | ||
| try: | ||
| return pr.merge_into(repo, dry_run=dry_run) | ||
| if all_green: | ||
| checks = pr.get_checkrun_conclusions() | ||
| pending_checks = [] | ||
| failed_checks = [] | ||
| for check in checks: | ||
| if checks[check] is None: | ||
| pending_checks.append(check) | ||
| elif checks[check] != 'SUCCESS': | ||
| failed_checks.append(check) | ||
| if len(failed_checks) > 0: | ||
| raise RuntimeError(f"Failed to merge due to failing checks, {','.join(failed_checks)}") | ||
| if len(pending_checks) > 0: | ||
| reject_reason = f"Refusing to merge as mandatory check(s) {','.join(pending_checks)} are missing" | ||
| raise MandatoryChecksMissingError(reject_reason) | ||
| pr.merge_into(repo, dry_run=dry_run) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see, this calls the code that makes the find_matching_merge_rule. In that case go for it lol, but Eli's comment about the API limit is important since we did have SEVs about our GITHUB_TOKEN getting overused. |
||
| else: | ||
| pr.merge_into(repo, dry_run=dry_run) | ||
| except MandatoryChecksMissingError as ex: | ||
| last_exception = str(ex) | ||
| print(f"Merged failed due to: {ex}. Retrying in 60 seconds.") | ||
|
|
@@ -913,9 +929,9 @@ def handle_exception(e: Exception, msg: str = "Merge failed") -> None: | |
| gh_post_comment(org, project, args.pr_num, "Cross-repo ghstack merges are not supported", dry_run=args.dry_run) | ||
| return | ||
|
|
||
| if args.on_green: | ||
| if args.on_green or args._all_green: | ||
| try: | ||
| merge_on_green(args.pr_num, repo, dry_run=args.dry_run) | ||
| merge_on_green(args.pr_num, repo, dry_run=args.dry_run, all_green=args.all_green) | ||
| except Exception as e: | ||
| handle_exception(e) | ||
| else: | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.