AddPullRequestReviews adds the given user and team reviewers to a pull request using the REST API. Team identifiers can be in "org/slug" format.
(client *Client, repo ghrepo.Interface, prNumber int, users, teams []string)
| 275 | // AddPullRequestReviews adds the given user and team reviewers to a pull request using the REST API. |
| 276 | // Team identifiers can be in "org/slug" format. |
| 277 | func AddPullRequestReviews(client *Client, repo ghrepo.Interface, prNumber int, users, teams []string) error { |
| 278 | if len(users) == 0 && len(teams) == 0 { |
| 279 | return nil |
| 280 | } |
| 281 | |
| 282 | // The API requires empty arrays instead of null values |
| 283 | if users == nil { |
| 284 | users = []string{} |
| 285 | } |
| 286 | |
| 287 | path := fmt.Sprintf( |
| 288 | "repos/%s/%s/pulls/%d/requested_reviewers", |
| 289 | url.PathEscape(repo.RepoOwner()), |
| 290 | url.PathEscape(repo.RepoName()), |
| 291 | prNumber, |
| 292 | ) |
| 293 | body := struct { |
| 294 | Reviewers []string `json:"reviewers"` |
| 295 | TeamReviewers []string `json:"team_reviewers"` |
| 296 | }{ |
| 297 | Reviewers: users, |
| 298 | TeamReviewers: extractTeamSlugs(teams), |
| 299 | } |
| 300 | buf := &bytes.Buffer{} |
| 301 | if err := json.NewEncoder(buf).Encode(body); err != nil { |
| 302 | return err |
| 303 | } |
| 304 | // The endpoint responds with the updated pull request object; we don't need it here. |
| 305 | return client.REST(repo.RepoHost(), "POST", path, buf, nil) |
| 306 | } |
| 307 | |
| 308 | // RemovePullRequestReviews removes requested reviewers from a pull request using the REST API. |
| 309 | // Team identifiers can be in "org/slug" format. |
no test coverage detected