Reputation: 61
I'm struggling to figure out how to create a pull request with autocomplete enabled with using the API if someone can provide an example of the JSON posted to enable the autocomplete that would be awesome.
I've tried setting the autoCompleteSetBy
Property and also have tried a whole bunch of settings within completionOptions
Property as well.
Upvotes: 3
Views: 6984
Reputation: 515
The easiest way is to first create the PR with the desired settings, and then issue an update using the value of the CreatedBy
property to set the value of the AutoCompleteSetBy
property.
If you haven't specified a merge strategy upon PR creation, make sure to set it when updating. Otherwise you will run into an exception.
private static GitPullRequest AutoCompletePullRequest(GitPullRequest existingPullRequest) => new()
{
AutoCompleteSetBy = existingPullRequest.CreatedBy,
CompletionOptions = new GitPullRequestCompletionOptions
{
MergeStrategy = GitPullRequestMergeStrategy.Squash
}
};
followed by a call to UpdatePullRequestAsync()
var pullRequestUpdate = AutoCompletePullRequest(createdPr);
await gitClient.UpdatePullRequestAsync(
pullRequestUpdate,
repository.Id,
createdPr.PullRequestId,
cancellationToken: cancellationToken);
Taken from: https://developercommunity.visualstudio.com/t/how-to-get-identityref-for-the-current-user-or-arb/1129979
Upvotes: 0
Reputation: 5243
Like mentioned in another reply - you indeed need to first create pull request and after that update it's status.
If you're looking for some ready made code - then I can suggest to take a look on following library in C#:
https://github.com/lvermeulen/Conductor/tree/main
Especially what you're asking is happening in this line:
Example of demo application can be found from it's unit tests - which is outdated, but still shows how it should work in theory:
Unfortunately I was not able to find any nuget package for Conductor.AzureDevOps.Api.dll
. Created a ticket on issue.
Upvotes: 0
Reputation: 41595
You can't create a Pull Request with autocomplete enabled when you use the Create PR rest API. you can only update a current PR with autocomplete enabled with the Pull Requests - Update, so you need to create the PR, take the new ID and then update it.
The basic body is to specify the autoCompleteSetBy
with the ID of the user who actually runs the API:
"autoCompleteSetBy": {
"id": "dsafasf-41531tf-safsaf-24124fas-sfasfasf"
}
You can also add additional parameters with completionOptions
like squash merge and more, see here.
If you want to automate of creating Pull Requests process you can install the Create Pull Request extension.
Upvotes: 6