Skip to content

Commit 5a354f7

Browse files
muirdmfacebook-github-bot
authored andcommitted
pr submit: don't update closed PRs
Summary: If a PR is not open (i.e. merged or closed), "sl pr submit" will now avoid updating it. Previously it didn't consider the PR's state. We emit a warning and a hint pointing the user to "sl pr unlink" if they want to create a new PR. (After disassociating the commit from the existing PR, "sl pr submit" will create a new PR). Fixes #474 Reviewed By: quark-zju Differential Revision: D43208767 fbshipit-source-id: 964381a6fcb9de30b2751bb825509cca2fd68f69
1 parent a050359 commit 5a354f7

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@
4141
autopullpredicate = registrar.autopullpredicate()
4242

4343

44+
hint = registrar.hint()
45+
46+
47+
@hint("unlink-closed-pr")
48+
def unlink_closed_pr_hint() -> str:
49+
return _(
50+
"to create a new PR, disassociate commit(s) using '@prog@ pr unlink' then re-run '@prog@ pr submit'"
51+
)
52+
53+
4454
def extsetup(ui):
4555
pr_status.setup_smartset_prefetch()
4656

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from enum import Enum
1010
from typing import Any, List, Optional, Tuple
1111

12-
from edenscm import error, git
12+
from edenscm import error, git, hintutil
1313
from edenscm.i18n import _
1414
from edenscm.node import hex, nullid
1515
from edenscm.result import Result
@@ -273,6 +273,14 @@ async def rewrite_pull_request_body(
273273
)
274274
pr = head_commit_data.pr
275275
assert pr
276+
277+
if pr.state != PullRequestState.OPEN:
278+
ui.status_err(
279+
_("warning, not updating #%d because it isn't open\n") % pr.number
280+
)
281+
hintutil.triggershow(ui, "unlink-closed-pr")
282+
return
283+
276284
result = await gh_submit.update_pull_request(
277285
repository.hostname, pr.node_id, title, body, base
278286
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This software may be used and distributed according to the terms of the
4+
# GNU General Public License version 2.
5+
6+
from edenscm import extensions
7+
from edenscm.ext.github import submit
8+
from edenscm.ext.github.gh_submit import PullRequestState
9+
from edenscm.ext.github.mock_utils import mock_run_git_command, MockGitHubServer
10+
from ghstack import github_gh_cli
11+
12+
13+
def setup_mock_github_server(ui) -> MockGitHubServer:
14+
github_server = MockGitHubServer()
15+
16+
github_server.expect_get_repository_request().and_respond()
17+
18+
pr_num = 42
19+
20+
github_server.expect_get_pr_details_request(pr_num).and_respond(
21+
f"PR_id_{pr_num}", state=PullRequestState.CLOSED
22+
)
23+
24+
github_server.expect_get_username_request().and_respond()
25+
26+
head = "782e8bee814295e5a3d41eee2e9d823ea83a7c13"
27+
github_server.expect_merge_into_branch(head).and_respond()
28+
29+
return github_server
30+
31+
32+
def uisetup(ui):
33+
mock_github_server = setup_mock_github_server(ui)
34+
extensions.wrapfunction(
35+
github_gh_cli, "_make_request", mock_github_server.make_request
36+
)
37+
extensions.wrapfunction(submit, "run_git_command", mock_run_git_command)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#chg-compatible
2+
#debugruntest-compatible
3+
#inprocess-hg-incompatible
4+
5+
$ enable github
6+
$ export SL_TEST_GH_URL=https://github.com/facebook/test_github_repo.git
7+
$ . $TESTDIR/git.sh
8+
$ configure github.pr-workflow=single
9+
10+
build up a github repo
11+
12+
$ sl init --git repo1
13+
$ cd repo1
14+
$ echo a > a1
15+
$ sl ci -Aqm "Pull Request resolved: https://github.com/facebook/test_github_repo/pull/42"
16+
17+
test we don't try updating a closed pr:
18+
19+
$ sl pr submit --config extensions.pr_submit=$TESTDIR/github/mock_existing_closed_pr.py
20+
pushing 1 to https://github.com/facebook/test_github_repo.git
21+
warning, not updating #42 because it isn't open
22+
hint[unlink-closed-pr]: to create a new PR, disassociate commit(s) using 'sl pr unlink' then re-run 'sl pr submit'

0 commit comments

Comments
 (0)