-1

I am creating a TFS webhook to set autocomplete by calling UpdatePullRequestAsync when a pull request is created. However, I am getting the error:

Invalid argument value. Parameter name: Invalid pull request auto-complete set by id. Valid values are either the current user identity id or an empty guid (to unset auto complete).

string createdBy = webHookRequest.resource.createdBy.id.Value;
GitHttpClient gitClient = Connection.GetClient<GitHttpClient>();

var pullRequestWithAutoCompleteEnabled = new GitPullRequest
{

    AutoCompleteSetBy = new IdentityRef() { Id = createdBy},
    CompletionOptions = new GitPullRequestCompletionOptions
    {
        SquashMerge = false,
        DeleteSourceBranch = false, // false if prefered otherwise
        MergeCommitMessage = commitMessage
    }
};

GitPullRequest updatedPullrequest = gitClient.UpdatePullRequestAsync(
                pullRequestWithAutoCompleteEnabled,
                repoId,
                prId).Result;
janw
  • 8,758
  • 11
  • 40
  • 62

1 Answers1

1

To set autocomplete for a pull request, you should make sure you have a branch policy set.

Auto-complete is only available if you have a branch policy set, as only branch policies that have not succeeded block the PR from being able to complete at any time. When there are no branch policies set, there is no need to auto-complete, since you can just complete immediately.

You need to specify the same user id (current authorized user) to update the pull request to Auto-Complete through API.

According to your error message,

Invalid argument value. Parameter name: Invalid pull request auto-complete set by id. Valid values are either the current user identity id or an empty guid (to unset auto complete).

I'm afraid this may related to your code:

string createdBy = webHookRequest.resource.createdBy.id.Value;

AutoCompleteSetBy = new IdentityRef() { Id = createdBy};

Suggest you to debug your code row by row, and check the returned value of AutoCompleteSetBy if it's qualified.

You could also take a look at this similar question: How to programmatically set an AzureDevOps PullRequest to complete Automatically? It's using this format:

AutoCompleteSetBy = new IdentityRef { Id = pullRequest.CreatedBy.Id };

Besides, also kindly refer to this blog: Programmatically creating a Pull Request against Visual Studio Team Services. Similar to TFS, which maybe helpful.

Meraj al Maksud
  • 1,528
  • 2
  • 22
  • 36
PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62