Skip to content

Commit

Permalink
Add --yes option to create-pr
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelLipski committed Nov 30, 2023
1 parent cbfc68d commit 7d5eddd
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 12 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- added: `--removed-from-remote` flag to `git machete slide-out` (contributed by @raylu)
- added: `--title` flag to `git machete github create-pr` that allows for setting PR title explicitly (suggested by @mjgigli)
- added: `--with-urls` flag to `git machete github anno-prs` and `machete.github.annotateWithUrls` git config key that allow for adding the URL of the PR to the annotations (contributed by @guyboltonking)
- added: `--yes` flag to `git machete github create-pr` so that the user isn't asked whether to push the branch (suggested by @mkondratek)
- deprecated: `git machete clean` and `git machete github sync`; use `github checkout-prs --mine`, `delete-unmanaged` and `slide-out --removed-from-remote` instead
- fixed: PR author is now always added to annotation if different from current user (contributed by @guyboltonking)

Expand Down
2 changes: 1 addition & 1 deletion completion/git-machete.completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ _git_machete() {
local discover_opts="-C --checked-out-since= -l --list-commits -r --roots= -y --yes"
local fork_point_opts="--inferred --override-to= --override-to-inferred --override-to-parent --unset-override"
local github_anno_prs_opts="--with-urls"
local github_create_pr_opts="--draft --title="
local github_create_pr_opts="--draft --title= --yes"
local github_checkout_prs_opts="--all --by= --mine"
local github_retarget_pr_opts="-b --branch= --ignore-if-missing"
local reapply_opts="-f --fork-point="
Expand Down
1 change: 1 addition & 0 deletions completion/git-machete.completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ __git_machete_github_subcommands() {
_arguments \
'(--draft)'--draft'[Create the new PR as draft]' \
'(--title)'--title='[Set the title for new PR explicitly]' \
'(--yes)'--yes'[Do not ask for confirmation whether to push the branch]' \
"${common_flags[@]}"
;;

Expand Down
1 change: 1 addition & 0 deletions completion/git-machete.fish
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ complete -c git-machete -n "__fish_seen_subcommand_from github; and __fish_seen_
complete -c git-machete -n "__fish_seen_subcommand_from github; and __fish_seen_subcommand_from checkout-prs; and not __fish_seen_subcommand_from --mine" -x -l mine -d 'Checkout open PRs for the current user associated with the GitHub token'
complete -c git-machete -n "__fish_seen_subcommand_from github; and __fish_seen_subcommand_from create-pr; and not __fish_seen_subcommand_from --draft" -f -l draft -d 'Create the new PR as a draft'
complete -c git-machete -n "__fish_seen_subcommand_from github; and __fish_seen_subcommand_from create-pr; and not __fish_seen_subcommand_from --title" -x -l title -d 'Set the title for new PR explicitly'
complete -c git-machete -n "__fish_seen_subcommand_from github; and __fish_seen_subcommand_from create-pr; and not __fish_seen_subcommand_from --yes" -f -l yes -d 'Do not ask for confirmation whether to push the branch'
complete -c git-machete -n "__fish_seen_subcommand_from github; and __fish_seen_subcommand_from retarget-pr; and not __fish_seen_subcommand_from --branch" -x -l branch -s b -a '(__machete_managed_branches)' -d 'Specify the branch for which the associated PR base will be set to its upstream (parent) branch'
complete -c git-machete -n "__fish_seen_subcommand_from github; and __fish_seen_subcommand_from retarget-pr; and not __fish_seen_subcommand_from --ignore-if-missing" -f -l ignore-if-missing -d 'Ignore errors and quietly terminate execution if there is no PR opened for current (or specified) branch'

Expand Down
5 changes: 4 additions & 1 deletion docs/man/git-machete.1
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ Checkout open PRs for the current user associated with the GitHub token.
.sp
\fB<PR\-number\-1> ... <PR\-number\-N>\fP Pull request numbers to checkout.
.TP
.B \fBcreate\-pr [\-\-draft] [\-\-title=<title>]\fP:
.B \fBcreate\-pr [\-\-draft] [\-\-title=<title>] [\-\-yes]\fP:
Creates a PR for the current branch, using the upstream (parent) branch as the PR base.
Once the PR is successfully created, annotates the current branch with the new PR\(aqs number.
.sp
Expand All @@ -1111,6 +1111,9 @@ Create the new PR as a draft.
.TP
.BI \-\-title\fB= <title>
Set the PR title explicitly (the default is to use the first included commit\(aqs message as the title).
.TP
.B \-\-yes
Do not ask for confirmation whether to push the branch.
.UNINDENT
.TP
.B \fBrestack\-pr\fP:
Expand Down
4 changes: 3 additions & 1 deletion docs/source/cli/github.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Creates, checks out and manages GitHub PRs while keeping them reflected in branc

``<PR-number-1> ... <PR-number-N>`` Pull request numbers to checkout.

``create-pr [--draft] [--title=<title>]``:
``create-pr [--draft] [--title=<title>] [--yes]``:
Creates a PR for the current branch, using the upstream (parent) branch as the PR base.
Once the PR is successfully created, annotates the current branch with the new PR's number.

Expand All @@ -71,6 +71,8 @@ Creates, checks out and manages GitHub PRs while keeping them reflected in branc

--title=<title> Set the PR title explicitly (the default is to use the first included commit's message as the title).

--yes Do not ask for confirmation whether to push the branch.

``restack-pr``:
Perform the following sequence of actions:
1. If the PR for the current branch is ready for review, it gets converted to a draft.
Expand Down
6 changes: 5 additions & 1 deletion git_machete/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def create_cli_parser() -> argparse.ArgumentParser:
github_parser.add_argument('--mine', action='store_true')
github_parser.add_argument('--title')
github_parser.add_argument('--with-urls', action='store_true')
github_parser.add_argument('--yes', action='store_true')

go_parser = subparsers.add_parser(
'go',
Expand Down Expand Up @@ -697,6 +698,8 @@ def print_completion_resource(name: str) -> None:
raise MacheteException("`--title` option is only valid with `create-pr` subcommand.")
if 'with_urls' in parsed_cli and github_subcommand != 'anno-prs':
raise MacheteException("`--with-urls` option is only valid with `anno-prs` subcommand.")
if 'yes' in parsed_cli and github_subcommand != 'create-pr':
raise MacheteException("`--yes` option is only valid with `create-pr` subcommand.")

if github_subcommand == "anno-prs":
machete_client.sync_annotations_to_github_prs(include_urls=cli_opts.opt_with_urls)
Expand All @@ -715,7 +718,8 @@ def print_completion_resource(name: str) -> None:
head=current_branch,
opt_draft=cli_opts.opt_draft,
opt_onto=cli_opts.opt_onto,
opt_title=cli_opts.opt_title)
opt_title=cli_opts.opt_title,
opt_yes=cli_opts.opt_yes)
elif github_subcommand == "restack-pr":
machete_client.restack_github_pr()
elif github_subcommand == "retarget-pr":
Expand Down
7 changes: 4 additions & 3 deletions git_machete/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2429,11 +2429,12 @@ def create_github_pr(
head: LocalBranchShortName,
opt_draft: bool,
opt_onto: Optional[LocalBranchShortName],
opt_title: Optional[str]
opt_title: Optional[str],
opt_yes: bool
) -> None:
# first make sure that head branch is synced with remote
try:
self.__sync_before_creating_pr(opt_onto=opt_onto, opt_yes=False)
self.__sync_before_creating_pr(opt_onto=opt_onto, opt_yes=opt_yes)
except InteractionStopped:
return

Expand All @@ -2456,7 +2457,7 @@ def create_github_pr(
is_called_from_github=True,
opt_push_tracked=False,
opt_push_untracked=True,
opt_yes=False)
opt_yes=opt_yes)
else:
prs_for_base_branch = github_client.get_open_pull_requests_by_head(base)
if len(prs_for_base_branch) >= 1:
Expand Down
5 changes: 4 additions & 1 deletion git_machete/generated_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@
`<PR-number-1> ... <PR-number-N>` Pull request numbers to checkout.
`create-pr [--draft] [--title=<title>]`:
`create-pr [--draft] [--title=<title>] [--yes]`:
Creates a PR for the current branch, using the upstream (parent) branch as the PR base.
Once the PR is successfully created, annotates the current branch with the new PR's number.
Expand All @@ -634,6 +634,9 @@
Set the PR title explicitly (the default is to use the first included commit's message as the title).
<b>--yes</b>
Do not ask for confirmation whether to push the branch.
`restack-pr`:
Perform the following sequence of actions:
Expand Down
2 changes: 1 addition & 1 deletion tests/completion_e2e/test_completion_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"git machete github checkout-prs -":
"--all --by --debug -h --help --mine -v --verbose",
"git machete github create-pr -":
"--debug --draft -h --help --title -v --verbose",
"--debug --draft -h --help --title -v --verbose --yes",
"git machete github retarget-pr --":
"--branch --debug --help --ignore-if-missing --verbose",
"git machete github retarget-pr -b ":
Expand Down
4 changes: 4 additions & 0 deletions tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,9 @@ def test_github_invalid_flag_combinations(self) -> None:
"--ignore-if-missing option is only valid with retarget-pr subcommand.")
assert_failure(["github", "checkout-prs", "--all", "--mine"],
"checkout-prs subcommand must take exactly one of the following options: --all, --by=..., --mine, pr-number(s)")
assert_failure(["github", "checkout-prs", "--title=foo"],
"--title option is only valid with create-pr subcommand.")
assert_failure(["github", "restack-pr", "--with-urls"],
"--with-urls option is only valid with anno-prs subcommand.")
assert_failure(["github", "restack-pr", "--yes"],
"--yes option is only valid with create-pr subcommand.")
5 changes: 2 additions & 3 deletions tests/test_github_create_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ def github_api_state_for_test_create_pr_missing_base_branch_on_remote() -> MockG
)

def test_github_create_pr_missing_base_branch_on_remote(self, mocker: MockerFixture) -> None:
self.patch_symbol(mocker, 'builtins.input', mock_input_returning_y)
self.patch_symbol(mocker, 'git_machete.github.OrganizationAndRepository.from_url', mock_from_url)
self.patch_symbol(mocker, 'git_machete.github.GitHubToken.for_domain', mock_github_token_for_domain_none)
self.patch_symbol(mocker, 'urllib.request.urlopen', mock_urlopen(
Expand Down Expand Up @@ -327,11 +326,11 @@ def test_github_create_pr_missing_base_branch_on_remote(self, mocker: MockerFixt

expected_msg = ("Fetching origin...\n"
"Warn: Base branch for this PR (feature/api_handling) is not found on remote, pushing...\n"
"Push untracked branch feature/api_handling to origin? (y, Q)\n"
"Pushing untracked branch feature/api_handling to origin...\n"
"Creating a PR from feature/api_exception_handling to feature/api_handling... OK, see www.github.com\n")

self.repo_sandbox.set_git_config_key("machete.github.annotateWithUrls", "true")
assert_success(['github', 'create-pr'], expected_msg)
assert_success(['github', 'create-pr', '--yes'], expected_msg)
assert_success(
['status'],
"""
Expand Down

0 comments on commit 7d5eddd

Please sign in to comment.