Skip to content

Commit

Permalink
add --draft option to sl pr submit
Browse files Browse the repository at this point in the history
Summary:
With this change, running `sl pr submit --draft` will create any *new*
pull requests in draft mode. Commits already associated with a pull
request will not have their draft status changed.

Reviewed By: muirdm

Differential Revision: D42048510

fbshipit-source-id: fd1d1f1f1268b4deb9135f0f75115bbcc48d9ebe
  • Loading branch information
bolinfest authored and facebook-github-bot committed Dec 15, 2022
1 parent 848ed33 commit 6e9c3d7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions eden/scm/edenscm/ext/github/__init__.py
Expand Up @@ -57,6 +57,7 @@ def pull_request_command(ui, repo, *args, **opts):
_("also include draft ancestors"),
),
("m", "message", None, _("message describing changes to updated commits")),
("d", "draft", False, _("mark new pull requests as draft")),
],
)
def submit_cmd(ui, repo, *args, **opts):
Expand Down
10 changes: 9 additions & 1 deletion eden/scm/edenscm/ext/github/gh_submit.py
Expand Up @@ -205,14 +205,22 @@ def get_value(field):


async def create_pull_request(
hostname: str, owner: str, name: str, base: str, head: str, title: str, body: str
hostname: str,
owner: str,
name: str,
base: str,
head: str,
title: str,
body: str,
is_draft: bool = False,
) -> Result:
endpoint = f"repos/{owner}/{name}/pulls"
params: Dict[str, _Params] = {
"base": base,
"head": head,
"title": title,
"body": body,
"draft": is_draft,
}
return await make_request(params, hostname=hostname, endpoint=endpoint)

Expand Down
15 changes: 12 additions & 3 deletions eden/scm/edenscm/ext/github/submit.py
Expand Up @@ -25,7 +25,10 @@
def submit(ui, repo, *args, **opts):
"""Create or update GitHub pull requests."""
github_repo = check_github_repo(repo)
return asyncio.run(update_commits_in_stack(ui, repo, github_repo))
is_draft = opts.get("draft")
return asyncio.run(
update_commits_in_stack(ui, repo, github_repo, is_draft=is_draft)
)


@dataclass
Expand All @@ -51,7 +54,9 @@ def get_msg(self) -> str:
return self.msg


async def update_commits_in_stack(ui, repo, github_repo: GitHubRepo) -> int:
async def update_commits_in_stack(
ui, repo, github_repo: GitHubRepo, is_draft: bool
) -> int:
parents = repo.dirstate.parents()
if parents[0] == nullid:
ui.status_err(_("commit has no parent: currently unsupported\n"))
Expand Down Expand Up @@ -160,7 +165,9 @@ def get_gitdir() -> str:

if pull_requests_to_create:
assert repository is not None
await create_pull_requests(pull_requests_to_create, repository, store, ui)
await create_pull_requests(
pull_requests_to_create, repository, store, ui, is_draft
)

# Now that each pull request has a named branch pushed to GitHub, we can
# create/update the pull request title and body, as appropriate.
Expand Down Expand Up @@ -221,6 +228,7 @@ async def create_pull_requests(
repository: Repository,
store: PullRequestStore,
ui,
is_draft: bool,
):
"""Creates a new pull request for each entry in the `commits` list.
Expand Down Expand Up @@ -248,6 +256,7 @@ async def create_pull_requests(
head=f"{head_ref_prefix}{branch_name}",
title=title,
body=body,
is_draft=is_draft,
)

if response.is_error():
Expand Down

0 comments on commit 6e9c3d7

Please sign in to comment.