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