Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option where to branch from (if different than the default branch) #107

Merged
merged 5 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/reference/manual/pr_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ 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 ""
FitzgeraldKrudde marked this conversation as resolved.
Show resolved Hide resolved
`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. 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

Expand Down
1 change: 1 addition & 0 deletions docs/reference/manual/workon.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/doing/pr/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ def close(pr_id):
help="Open newly created issue in the web browser.",
show_envvar=True,
)
@click.option(
"--default-branch",
operte marked this conversation as resolved.
Show resolved Hide resolved
"-b",
required=False,
default="",
type=str,
help="The name of the branch to branch from and to. It overrides the repository's default branch.",
show_envvar=True,
)
def create(
work_item_id: str,
draft: bool,
Expand All @@ -114,6 +123,7 @@ def create(
reviewers: str,
checkout: bool,
delete_source_branch: bool,
default_branch,
web: bool,
) -> None:
"""
Expand All @@ -129,6 +139,7 @@ def create(
reviewers,
checkout,
delete_source_branch,
default_branch,
**get_common_options(),
)
if web:
Expand Down
9 changes: 7 additions & 2 deletions src/doing/pr/create_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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" '
Expand Down Expand Up @@ -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}" '
operte marked this conversation as resolved.
Show resolved Hide resolved
command += f'--target-branch "{default_branch}" '
FitzgeraldKrudde marked this conversation as resolved.
Show resolved Hide resolved
command += f'--title "{work_item_title}" '
command += f'--project "{project}" --organization "{organization}" '

Expand Down
11 changes: 11 additions & 0 deletions src/doing/workon/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@
help="The number of story points to assign. Not assigned if not specified.",
show_envvar=True,
)
@click.option(
"--default-branch",
"-b",
required=False,
default="",
type=str,
help="The name of the branch to branch from and to. It overrides the repository's default branch.",
show_envvar=True,
)
def workon(
issue,
type,
Expand All @@ -89,6 +98,7 @@ def workon(
checkout: bool,
delete_source_branch: bool,
story_points,
default_branch,
):
"""
Create issue with PR and switch git branch.
Expand Down Expand Up @@ -123,5 +133,6 @@ def workon(
reviewers=reviewers,
checkout=checkout,
delete_source_branch=delete_source_branch,
default_branch=default_branch,
**get_common_options(),
)