简体   繁体   中英

C# GitHub API - How Can I Add/Remove Pull Request Assignees?

I'm trying to Add/Remove assigned users to a pull request in a .NET 5 console app.

I'm using the library octokit.net and I'm able to get a PR and see the actual users assigned but it is a read-only collection and I can't find a way to update it.

the PullRequest.Update() method has only a few fields to update like title, body, and state but nothing else.

Any help would be appreciated, thanks!

I found out how to implement this and leave the answer to help if someone has the same question.

In octokit.net you can get the assignees of a pull request through issues, even if you didn't create an issue in GitHub.

Example of adding and removing assignees:

    var productInformation = new ProductHeaderValue("owner");
    var credentials = new Credentials("your token");            
    var gitHubClient = new GitHubClient(productInformation) { Credentials = credentials };

    await gitHubClient.Issue.Assignee.RemoveAssignees("owner", "name", PrNumber, new AssigneesUpdate(new List<string>() { "userLogin" }));

    await gitHubClient.Issue.Assignee.AddAssignees("owner", "name", PrNumber, new AssigneesUpdate(new List<string>() { "userLogin" }));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM