Azure / Azure/azure-devops-cli-extension

[Feature Request] `az repos pr create` should allow Azure Repos to dynamically choose targetRef

Open
#1,431 0 comments 0 reactions 0 assignees View on GitHub
Feature
Dominant language
Python
Stars
682
Forks
278
Avg merge
3d 23h
Merged PRs (30d)
3

Description

**Is your feature request related to a problem? Please describe.**

There is a new feature in Azure Repos where a repository can [configure custom target branches](https://learn.microsoft.com/en-us/azure/devops/repos/git/pull-request-targets?view=azure-devops). When these branches are configured, the PR create page in the Web UI will dynamically choose a target branch based on the first-parent commit history.

This issue's request is that this behavior becomes enabled in `az repos pr create` when the user does not specify a target branch in the CLI.

**Describe the solution you'd like**

I have a working implementation in my fork: [see diff here](https://github.com/Azure/azure-devops-cli-extension/compare/master...derrickstolee:dynamic-target-ref). I started creating a PR but then saw that we needed signoff on the approach.

There are two main pieces here:

1. Update the REST API data model to include the new `IgnoreTargetRefAndChooseDynamically` member to the `GitPullRequest` object. Since this is an addition to the object model, it will be included in the POST body of the request to create a PR. Older versions of Azure DevOps Server will ignore this member, but newer versions (and the Azure DevOps cloud service) will recognize it as a signal to ignore the `TargetRef` value and instead enable the new logic, when configured. This parameter was the decision of the Azure Repos team instead of making `TargetRef` optional, which was considered a backwards compatibility break. The current `az repos pr create` logic only interacts with the `v5_0` model, but all existing models are updated. Further, the latest released model does not yet have this parameter (introduced in ~September 2024 clients).
2. When selecting a target ref by falling back to the default ref, indicate that this was a "guess" and not something provided by the user. Then, when this guess occurs, we can set the optional member to indicate that the user has not specified a target and thus the given choice can be ignored.

**Additional context**

I'm the author of this feature in the Azure Repos backend (and of the linked docs). I assisted several major repositories within Microsoft to configure this setting, including the Windows and Office monorepos. I'm contributing client-side changes to `az repos` and the `dev` CLIs as we have users creating PRs with those tools.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.