github.com/google/go-github/v49@v49.1.0/github/issues_assignees.go (about) 1 // Copyright 2013 The go-github AUTHORS. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 package github 7 8 import ( 9 "context" 10 "fmt" 11 ) 12 13 // ListAssignees fetches all available assignees (owners and collaborators) to 14 // which issues may be assigned. 15 // 16 // GitHub API docs: https://docs.github.com/en/rest/issues/assignees#list-assignees 17 func (s *IssuesService) ListAssignees(ctx context.Context, owner, repo string, opts *ListOptions) ([]*User, *Response, error) { 18 u := fmt.Sprintf("repos/%v/%v/assignees", owner, repo) 19 u, err := addOptions(u, opts) 20 if err != nil { 21 return nil, nil, err 22 } 23 24 req, err := s.client.NewRequest("GET", u, nil) 25 if err != nil { 26 return nil, nil, err 27 } 28 29 var assignees []*User 30 resp, err := s.client.Do(ctx, req, &assignees) 31 if err != nil { 32 return nil, resp, err 33 } 34 35 return assignees, resp, nil 36 } 37 38 // IsAssignee checks if a user is an assignee for the specified repository. 39 // 40 // GitHub API docs: https://docs.github.com/en/rest/issues/assignees#check-if-a-user-can-be-assigned 41 func (s *IssuesService) IsAssignee(ctx context.Context, owner, repo, user string) (bool, *Response, error) { 42 u := fmt.Sprintf("repos/%v/%v/assignees/%v", owner, repo, user) 43 req, err := s.client.NewRequest("GET", u, nil) 44 if err != nil { 45 return false, nil, err 46 } 47 48 resp, err := s.client.Do(ctx, req, nil) 49 assignee, err := parseBoolResponse(err) 50 return assignee, resp, err 51 } 52 53 // AddAssignees adds the provided GitHub users as assignees to the issue. 54 // 55 // GitHub API docs: https://docs.github.com/en/rest/issues/assignees#add-assignees-to-an-issue 56 func (s *IssuesService) AddAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, *Response, error) { 57 users := &struct { 58 Assignees []string `json:"assignees,omitempty"` 59 }{Assignees: assignees} 60 u := fmt.Sprintf("repos/%v/%v/issues/%v/assignees", owner, repo, number) 61 req, err := s.client.NewRequest("POST", u, users) 62 if err != nil { 63 return nil, nil, err 64 } 65 66 issue := &Issue{} 67 resp, err := s.client.Do(ctx, req, issue) 68 if err != nil { 69 return nil, resp, err 70 } 71 72 return issue, resp, nil 73 } 74 75 // RemoveAssignees removes the provided GitHub users as assignees from the issue. 76 // 77 // GitHub API docs: https://docs.github.com/en/rest/issues/assignees#remove-assignees-from-an-issue 78 func (s *IssuesService) RemoveAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, *Response, error) { 79 users := &struct { 80 Assignees []string `json:"assignees,omitempty"` 81 }{Assignees: assignees} 82 u := fmt.Sprintf("repos/%v/%v/issues/%v/assignees", owner, repo, number) 83 req, err := s.client.NewRequest("DELETE", u, users) 84 if err != nil { 85 return nil, nil, err 86 } 87 88 issue := &Issue{} 89 resp, err := s.client.Do(ctx, req, issue) 90 if err != nil { 91 return nil, resp, err 92 } 93 94 return issue, resp, nil 95 }