Debian Codegraph @

github/issues_assignees.go

raw
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/rest/issues/assignees#list-assignees
17 //
18 //meta:operation GET /repos/{owner}/{repo}/assignees
19 func (s *IssuesService) ListAssignees(ctx context.Context, owner, repo string, opts *ListOptions) ([]*User, *Response, error) {
20 u := fmt.Sprintf("repos/%v/%v/assignees", owner, repo)
21 u, err := addOptions(u, opts)
22 if err != nil {
23 return nil, nil, err
24 }
25
26 req, err := s.client.NewRequest("GET", u, nil)
27 if err != nil {
28 return nil, nil, err
29 }
30
31 var assignees []*User
32 resp, err := s.client.Do(ctx, req, &assignees)
33 if err != nil {
34 return nil, resp, err
35 }
36
37 return assignees, resp, nil
38 }
39
40 // IsAssignee checks if a user is an assignee for the specified repository.
41 //
42 // GitHub API docs: https://docs.github.com/rest/issues/assignees#check-if-a-user-can-be-assigned
43 //
44 //meta:operation GET /repos/{owner}/{repo}/assignees/{assignee}
45 func (s *IssuesService) IsAssignee(ctx context.Context, owner, repo, user string) (bool, *Response, error) {
46 u := fmt.Sprintf("repos/%v/%v/assignees/%v", owner, repo, user)
47 req, err := s.client.NewRequest("GET", u, nil)
48 if err != nil {
49 return false, nil, err
50 }
51
52 resp, err := s.client.Do(ctx, req, nil)
53 assignee, err := parseBoolResponse(err)
54 return assignee, resp, err
55 }
56
57 // AddAssignees adds the provided GitHub users as assignees to the issue.
58 //
59 // GitHub API docs: https://docs.github.com/rest/issues/assignees#add-assignees-to-an-issue
60 //
61 //meta:operation POST /repos/{owner}/{repo}/issues/{issue_number}/assignees
62 func (s *IssuesService) AddAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, *Response, error) {
63 users := &struct {
64 Assignees []string `json:"assignees,omitempty"`
65 }{Assignees: assignees}
66 u := fmt.Sprintf("repos/%v/%v/issues/%v/assignees", owner, repo, number)
67 req, err := s.client.NewRequest("POST", u, users)
68 if err != nil {
69 return nil, nil, err
70 }
71
72 issue := &Issue{}
73 resp, err := s.client.Do(ctx, req, issue)
74 if err != nil {
75 return nil, resp, err
76 }
77
78 return issue, resp, nil
79 }
80
81 // RemoveAssignees removes the provided GitHub users as assignees from the issue.
82 //
83 // GitHub API docs: https://docs.github.com/rest/issues/assignees#remove-assignees-from-an-issue
84 //
85 //meta:operation DELETE /repos/{owner}/{repo}/issues/{issue_number}/assignees
86 func (s *IssuesService) RemoveAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, *Response, error) {
87 users := &struct {
88 Assignees []string `json:"assignees,omitempty"`
89 }{Assignees: assignees}
90 u := fmt.Sprintf("repos/%v/%v/issues/%v/assignees", owner, repo, number)
91 req, err := s.client.NewRequest("DELETE", u, users)
92 if err != nil {
93 return nil, nil, err
94 }
95
96 issue := &Issue{}
97 resp, err := s.client.Do(ctx, req, issue)
98 if err != nil {
99 return nil, resp, err
100 }
101
102 return issue, resp, nil
103 }