Skip to content

Commit 117e4dc

Browse files
discentemfacebook-github-bot
authored andcommitted
add status err if linked PR was closed when submitting (#356)
Summary: add status err if linked PR was closed when submitting --- Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/sapling/pull/356). * __->__ #356 Pull Request resolved: #356 Reviewed By: akushner Differential Revision: D42299786 Pulled By: bolinfest fbshipit-source-id: dfc2e0b95bca998f3fdb2e87cf6649f622d0621b
1 parent f1f7d1b commit 117e4dc

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

eden/scm/edenscm/ext/github/consts/query.py

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
pullRequest(number: $number) {
4141
id
4242
url
43+
state
4344
baseRefOid
4445
baseRefName
4546
headRefOid

eden/scm/edenscm/ext/github/gh_submit.py

+14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
(2) do more work in parallel.
1111
"""
1212

13+
import enum
1314
from dataclasses import dataclass
1415
from typing import Dict, Optional, Tuple, Union
1516

@@ -89,6 +90,17 @@ async def get_repository(
8990
return _parse_repository_from_dict(repo, hostname=hostname, upstream=upstream)
9091

9192

93+
class PullRequestState(enum.Enum):
94+
"""https://docs.github.com/en/graphql/reference/enums#pullrequeststate"""
95+
96+
"""A pull request that has been closed without being merged."""
97+
CLOSED = enum.auto()
98+
"""A pull request that has been closed by being merged."""
99+
MERGED = enum.auto()
100+
"""A pull request that is still open."""
101+
OPEN = enum.auto()
102+
103+
92104
@dataclass
93105
class PullRequestDetails:
94106
node_id: str
@@ -103,6 +115,7 @@ class PullRequestDetails:
103115
# bodyText: plaintext version of body with Markdown markup removed
104116
# bodyHTML: body rendered as "safe" HTML
105117
body: str
118+
state: PullRequestState
106119

107120

108121
async def get_pull_request_details(
@@ -129,6 +142,7 @@ async def get_pull_request_details(
129142
head_oid=data["headRefOid"],
130143
head_branch_name=data["headRefName"],
131144
body=data["body"],
145+
state=PullRequestState[data["state"]],
132146
)
133147
)
134148

eden/scm/edenscm/ext/github/mock_utils.py

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import Any, Callable, Dict, List, Optional, Union
99

1010
from edenscm.ext.github.consts import query
11+
from edenscm.ext.github.gh_submit import PullRequestState
1112
from edenscm.ext.github.pull_request_body import firstline
1213
from edenscm.result import Ok, Result
1314

@@ -401,6 +402,7 @@ def __init__(self, key: str, owner: str, name: str, pr_number: int) -> None:
401402
def and_respond(
402403
self,
403404
pr_id: str,
405+
state: PullRequestState = PullRequestState.OPEN,
404406
head_ref_name: str = "",
405407
head_ref_oid: str = "",
406408
base_ref_name: str = "main",
@@ -416,6 +418,7 @@ def and_respond(
416418
"pullRequest": {
417419
"id": pr_id,
418420
"url": f"https://github.com/{self._owner}/{self._name}/pull/{self._pr_number}",
421+
"state": state.name,
419422
"headRefOid": head_ref_oid,
420423
"headRefName": head_ref_name,
421424
"baseRefOid": base_ref_oid,

eden/scm/edenscm/ext/github/submit.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from . import gh_submit, github_repo_util
1717
from .archive_commit import add_commit_to_archives
18-
from .gh_submit import PullRequestDetails, Repository
18+
from .gh_submit import PullRequestDetails, PullRequestState, Repository
1919
from .github_repo_util import check_github_repo, GitHubRepo
2020
from .none_throws import none_throws
2121
from .pr_parser import get_pull_request_for_context
@@ -440,7 +440,12 @@ async def create_placeholder_strategy_params(
440440
pr = commit.pr
441441
if pr:
442442
if pr.head_oid == hex(commit.node):
443-
ui.status_err(_("#%d is up-to-date\n") % pr.number)
443+
if pr.state == PullRequestState.CLOSED:
444+
ui.status_err(_("%s was closed.\n") % pr.url)
445+
elif pr.state == PullRequestState.MERGED:
446+
ui.status_err(_("%s was merged.\n") % pr.url)
447+
else:
448+
ui.status_err(_("#%d is up-to-date\n") % pr.number)
444449
else:
445450
refs_to_update.append(
446451
f"{hex(commit.node)}:refs/heads/{pr.head_branch_name}"

0 commit comments

Comments
 (0)