MCPcopy Create free account
hub / github.com/cli/cli / AddPullRequestReviews

Function AddPullRequestReviews

api/queries_pr_review.go:278–312  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
278func 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.

Callers 1

Calls 7

JoinPathFunction · 0.92
extractTeamSlugsFunction · 0.85
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected