From 6215ad4954417d2ccbba75cc34a30bb44228ab32 Mon Sep 17 00:00:00 2001 From: Fitzgerald Krudde Date: Wed, 18 May 2022 00:56:25 +0200 Subject: [PATCH 1/5] added option where to branch from (if different than the default branch) --- docs/reference/manual/pr_create.md | 1 + docs/reference/manual/workon.md | 1 + src/doing/pr/commands.py | 11 +++++++++++ src/doing/pr/create_pr.py | 9 +++++++-- src/doing/workon/commands.py | 11 +++++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/reference/manual/pr_create.md b/docs/reference/manual/pr_create.md index feb4e04..0cad22c 100644 --- a/docs/reference/manual/pr_create.md +++ b/docs/reference/manual/pr_create.md @@ -15,6 +15,7 @@ doing pr create 1234 --draft -r "john.doe@company.com jane.doe@company.com" doing pr create 1234 --draft -r "@me jane.doe@company.com" doing pr create 1234 --draft --checkout doing pr create 1234 --delete-source-branch --self-approve --auto-complete +doing pr create 1234 --default-branch develop ``` !!! notes "" diff --git a/docs/reference/manual/workon.md b/docs/reference/manual/workon.md index 45f7799..3c831d0 100644 --- a/docs/reference/manual/workon.md +++ b/docs/reference/manual/workon.md @@ -16,6 +16,7 @@ doing workon "an issue" --parent 12345 doing workon "an issue" --reviewers "john.doe@company.com jane.doe@company.com" doing workon "an issue" --no-auto-complete --no-draft --self-approve doing workon "an issue" --story-points 3 +doing workon "an issue" --default-branch develop ``` ## Options diff --git a/src/doing/pr/commands.py b/src/doing/pr/commands.py index c27fb21..223e1ae 100644 --- a/src/doing/pr/commands.py +++ b/src/doing/pr/commands.py @@ -106,6 +106,15 @@ def close(pr_id): help="Open newly created issue in the web browser.", show_envvar=True, ) +@click.option( + "--default-branch", + "-d", + required=False, + default="", + type=str, + help="The name of the branch to branch from and to, only needed if different that the configured default branch", + show_envvar=True, +) def create( work_item_id: str, draft: bool, @@ -114,6 +123,7 @@ def create( reviewers: str, checkout: bool, delete_source_branch: bool, + default_branch, web: bool, ) -> None: """ @@ -129,6 +139,7 @@ def create( reviewers, checkout, delete_source_branch, + default_branch, **get_common_options(), ) if web: diff --git a/src/doing/pr/create_pr.py b/src/doing/pr/create_pr.py index cf8606f..a206313 100644 --- a/src/doing/pr/create_pr.py +++ b/src/doing/pr/create_pr.py @@ -27,6 +27,7 @@ def cmd_create_pr( reviewers: str, checkout: bool, delete_source_branch: bool, + default_branch: str, team: str, area: str, iteration: str, @@ -80,8 +81,11 @@ def cmd_create_pr( remote_branches = [x.rpartition("/")[2] for x in remote_branches if x.startswith("refs/heads")] # Find the default branch from which to create a new branch and target the pull request to - cmd = f'az repos show --repository "{repo_name}" --org "{organization}" -p "{project}"' - default_branch = run_command(cmd).get("defaultBranch", "refs/heads/master") + if not default_branch: + cmd = f'az repos show --repository "{repo_name}" --org "{organization}" -p "{project}"' + default_branch = run_command(cmd).get("defaultBranch", "refs/heads/master") + else: + default_branch = "refs/heads/" + default_branch # Create a new remote branch, only if it does yet exist cmd = f'az repos ref list --repository "{repo_name}" --query "[?name==\'{default_branch}\'].objectId" ' @@ -129,6 +133,7 @@ def cmd_create_pr( command += f'--draft "{str(draft).lower()}" ' command += f'--work-items "{work_item_id}" ' command += f'--source-branch "{branch_name}" ' + command += f'--target-branch "{default_branch}" ' command += f'--title "{work_item_title}" ' command += f'--project "{project}" --organization "{organization}" ' diff --git a/src/doing/workon/commands.py b/src/doing/workon/commands.py index 07e91f3..2f76f16 100644 --- a/src/doing/workon/commands.py +++ b/src/doing/workon/commands.py @@ -78,6 +78,15 @@ help="The number of story points to assign. Not assigned if not specified.", show_envvar=True, ) +@click.option( + "--default-branch", + "-d", + required=False, + default="", + type=str, + help="The name of the branch to branch from and to, only needed if different that the configured default branch", + show_envvar=True, +) def workon( issue, type, @@ -89,6 +98,7 @@ def workon( checkout: bool, delete_source_branch: bool, story_points, + default_branch, ): """ Create issue with PR and switch git branch. @@ -123,5 +133,6 @@ def workon( reviewers=reviewers, checkout=checkout, delete_source_branch=delete_source_branch, + default_branch=default_branch, **get_common_options(), ) From 430c90745a39aa4711cae228d0cf6a70f1b3076c Mon Sep 17 00:00:00 2001 From: Fitzgerald Krudde Date: Mon, 30 May 2022 17:03:59 +0200 Subject: [PATCH 2/5] improved help text for using another default branch --- src/doing/pr/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doing/pr/commands.py b/src/doing/pr/commands.py index 223e1ae..6ddf069 100644 --- a/src/doing/pr/commands.py +++ b/src/doing/pr/commands.py @@ -112,7 +112,7 @@ def close(pr_id): required=False, default="", type=str, - help="The name of the branch to branch from and to, only needed if different that the configured default branch", + help="The name of the branch to branch from and to. It overrides the repository's default branch.", show_envvar=True, ) def create( From 2b6f5a9779363b20dff14c1d09cfdfd3e5f6d8e3 Mon Sep 17 00:00:00 2001 From: Fitzgerald Krudde Date: Mon, 30 May 2022 17:05:32 +0200 Subject: [PATCH 3/5] updated shortcut for default-branch to -b --- src/doing/pr/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doing/pr/commands.py b/src/doing/pr/commands.py index 6ddf069..b6e7fcb 100644 --- a/src/doing/pr/commands.py +++ b/src/doing/pr/commands.py @@ -108,7 +108,7 @@ def close(pr_id): ) @click.option( "--default-branch", - "-d", + "-b", required=False, default="", type=str, From fce9ff07ca1ea20e1a3fce6f1920821c114ef3d8 Mon Sep 17 00:00:00 2001 From: Fitzgerald Krudde Date: Mon, 30 May 2022 22:26:05 +0200 Subject: [PATCH 4/5] improved text as suggested in comments PR --- docs/reference/manual/pr_create.md | 2 +- src/doing/workon/commands.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/reference/manual/pr_create.md b/docs/reference/manual/pr_create.md index 0cad22c..54e9b57 100644 --- a/docs/reference/manual/pr_create.md +++ b/docs/reference/manual/pr_create.md @@ -22,7 +22,7 @@ doing pr create 1234 --default-branch develop `doing` will create a branch name using the format *{work_item_id}*_*{issue_title}*, where the *{issue_title}* is in lowercase, [snake_case](https://en.wikipedia.org/wiki/Snake_case) with all special characters removed. Example: issue #13 'Fix @ bug !' becomes *13_fix bug*. If that branch already exists on the remote, `doing` will use that one. !!! notes "" - If a new branch is created while doing `pr create`, it will be branched from the default branch in Azure Devops, which usually will be `master`, but might be a different branch. The pull request will target this same branch. + If a new branch is created while doing `pr create`, it will be branched from the default branch in Azure Devops, which usually will be `master`, but might be a different branch. Where to branch from can be overridden by using the option default-branch. This can be The pull request will target this same branch. ## Options diff --git a/src/doing/workon/commands.py b/src/doing/workon/commands.py index 2f76f16..ad2ae4f 100644 --- a/src/doing/workon/commands.py +++ b/src/doing/workon/commands.py @@ -80,11 +80,11 @@ ) @click.option( "--default-branch", - "-d", + "-b", required=False, default="", type=str, - help="The name of the branch to branch from and to, only needed if different that the configured default branch", + help="The name of the branch to branch from and to. It overrides the repository's default branch.", show_envvar=True, ) def workon( From 8530a2e13817526c9858efafb2d41c2b2aba61b1 Mon Sep 17 00:00:00 2001 From: Fitzgerald Krudde Date: Tue, 31 May 2022 13:16:16 +0200 Subject: [PATCH 5/5] improved text as suggested in comments PR --- docs/reference/manual/pr_create.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/reference/manual/pr_create.md b/docs/reference/manual/pr_create.md index 54e9b57..6a0845c 100644 --- a/docs/reference/manual/pr_create.md +++ b/docs/reference/manual/pr_create.md @@ -22,7 +22,8 @@ doing pr create 1234 --default-branch develop `doing` will create a branch name using the format *{work_item_id}*_*{issue_title}*, where the *{issue_title}* is in lowercase, [snake_case](https://en.wikipedia.org/wiki/Snake_case) with all special characters removed. Example: issue #13 'Fix @ bug !' becomes *13_fix bug*. If that branch already exists on the remote, `doing` will use that one. !!! notes "" - If a new branch is created while doing `pr create`, it will be branched from the default branch in Azure Devops, which usually will be `master`, but might be a different branch. Where to branch from can be overridden by using the option default-branch. This can be The pull request will target this same branch. + If a new branch is created while doing `pr create`, it will be branched from the default branch in Azure Devops, which usually will be `master`, but might be a different branch. This can be The pull request will target this same branch. + Where to branch from can be overridden by using the option `-default-branch`. ## Options