Skip to content
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

Add merge command #233

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.0.8
- Add `merge` command

## 1.0.7
- Add `--exclude-missing` when running `auto-pr status`
- Allows you to remove the `Missing PRs` section from the output
Expand Down
48 changes: 48 additions & 0 deletions autopr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,53 @@ def reopen():
click.secho("Finished reopening all closed unmerged pull requests")


@cli.command()
def merge():
"""Merge all mergeable pull requests"""
cfg = workdir.read_config(WORKDIR)
db = workdir.read_database(WORKDIR)
gh = github.create_github_client(cfg.credentials.api_key)

for repository in db.repositories:
if repository.existing_pr is not None:
pr = github.get_pull_request(gh, repository)
if pr.state == github.PullRequestState.OPEN.value:
if pr.mergeable:
commits = list(pr.get_commits())
if len(commits) == 0:
click.secho(f"Pull request {repository.name} has no commits")
break

ok = True
check_suites = commits[-1].get_check_suites()
for check in check_suites:
if check.status == "queued":
continue
if check.status != "completed" or check.conclusion != "success":
check_runs = check.get_check_runs()
for check_run in check_runs:
if (
check_run.status != "completed"
or check_run.conclusion
not in ("success", "skipped")
):
click.secho(
f"Pull request {repository.name} has a check `{check_run.name}` (conclusion: {check_run.conclusion}) that is not successful"
)
ok = False
if not ok:
continue
try:
click.secho(f"Attempting to merge {repository.name}")
pr.merge(merge_method="squash")
click.secho(f"Merged {repository.name}")
except ValueError as e:
click.secho(f"{e}")
else:
click.secho(f"Pull request {repository.name} is not mergeable")
else:
click.secho(f"Pull request {repository.name} is not open")


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "auto-pr"
version = "1.0.7"
version = "1.0.8"
description = "Perform bulk updates across repositories"
license = "Apache-2.0"

Expand Down
Loading