Skip to content

Commit 804f0bf

Browse files
Check that the bottom PR is mergeable (#20)
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
1 parent 85e6cd4 commit 804f0bf

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/stack_pr/cli.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@
143143
144144
If you are trying land the stack, please update it first by calling 'submit'.
145145
146+
PR info from github: {d}
147+
"""
148+
ERROR_STACKINFO_PR_NOT_MERGEABLE = """Associated PR is not mergeable on GitHub!
149+
{e}
150+
151+
Please fix the issues on GitHub.
152+
146153
PR info from github: {d}
147154
"""
148155
ERROR_REPO_DIRTY = """There are uncommitted changes.
@@ -438,7 +445,7 @@ def set_base_branches(st: List[StackEntry], target: str):
438445

439446
def verify(st: List[StackEntry], check_base: bool = False):
440447
log(h("Verifying stack info"), level=1)
441-
for e in st:
448+
for index, e in enumerate(st):
442449
if e.has_missing_info():
443450
error(ERROR_STACKINFO_MISSING.format(**locals()))
444451
raise RuntimeError
@@ -454,7 +461,7 @@ def verify(st: List[StackEntry], check_base: bool = False):
454461
"view",
455462
e.pr,
456463
"--json",
457-
"baseRefName,headRefName,number,state,body,title,url",
464+
"baseRefName,headRefName,number,state,body,title,url,mergeStateStatus",
458465
]
459466
)
460467
d = json.loads(ghinfo)
@@ -483,6 +490,11 @@ def verify(st: List[StackEntry], check_base: bool = False):
483490
error(ERROR_STACKINFO_PR_BASE_MISMATCH.format(**locals()))
484491
raise RuntimeError
485492

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

487499
def print_stack(st: List[StackEntry], links: bool, level=1):
488500
log(b("Stack:"), level=level)

0 commit comments

Comments
 (0)