Skip to content

Commit

Permalink
Check that the bottom PR is mergeable
Browse files Browse the repository at this point in the history
GitHub lets you check if a PR is actually mergeable via the `gh` CLI by
retrieving the `mergeStateStatus` field. This field has a bunch of
values (see the [API documentation][1] linked below), but the one we care
about is `CLEAN`, indicating that the PR has no merge conflicts and has
passed PR checks.

I'd like to eventually add this information to `stack-pr view`, but it will
require some extra piping, and will slow down the command due to the
extra network request.

1: https://docs.github.com/en/graphql/reference/enums#mergestatestatus
  • Loading branch information
AmaranthineCodices committed Aug 23, 2024
1 parent 495a5f8 commit f2d6833
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/stack_pr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@
If you are trying land the stack, please update it first by calling 'submit'.
PR info from github: {d}
"""
ERROR_STACKINFO_PR_NOT_MERGEABLE = """Associated PR is not mergeable on GitHub!
{e}
Please fix the issues on GitHub.
PR info from github: {d}
"""
ERROR_REPO_DIRTY = """There are uncommitted changes.
Expand Down Expand Up @@ -424,7 +431,7 @@ def set_base_branches(st: List[StackEntry], target: str):

def verify(st: List[StackEntry], check_base: bool = False):
log(h("Verifying stack info"), level=1)
for e in st:
for index, e in enumerate(st):
if e.has_missing_info():
error(ERROR_STACKINFO_MISSING.format(**locals()))
raise RuntimeError
Expand All @@ -440,7 +447,7 @@ def verify(st: List[StackEntry], check_base: bool = False):
"view",
e.pr,
"--json",
"baseRefName,headRefName,number,state,body,title,url",
"baseRefName,headRefName,number,state,body,title,url,mergeStateStatus",
]
)
d = json.loads(ghinfo)
Expand Down Expand Up @@ -469,6 +476,11 @@ def verify(st: List[StackEntry], check_base: bool = False):
error(ERROR_STACKINFO_PR_BASE_MISMATCH.format(**locals()))
raise RuntimeError

# The first entry on the stack needs to be actually mergeable on GitHub.
if check_base and index == 0 and d["mergeStateStatus"] != "CLEAN":
error(ERROR_STACKINFO_PR_NOT_MERGEABLE.format(**locals()))
raise RuntimeError


def print_stack(st: List[StackEntry], level=1):
log(b("Stack:"), level=level)
Expand Down

0 comments on commit f2d6833

Please sign in to comment.