@@ -10,6 +10,29 @@ import (
10
10
"fmt"
11
11
)
12
12
13
+ // ListCollaborators list a repository's collaborators
14
+ func (c * Client ) ListCollaborators (user , repo string ) ([]* User , error ) {
15
+ collaborators := make ([]* User , 0 , 10 )
16
+ err := c .getParsedResponse ("GET" ,
17
+ fmt .Sprintf ("/repos/%s/%s/collaborators" , user , repo ),
18
+ nil , nil , & collaborators )
19
+ return collaborators , err
20
+ }
21
+
22
+ // IsCollaborator check if a user is a collaborator of a repository
23
+ func (c * Client ) IsCollaborator (user , repo , collaborator string ) (bool , error ) {
24
+ status , err := c .getStatusCode ("GET" ,
25
+ fmt .Sprintf ("/repos/%s/%s/collaborators/%s" , user , repo , collaborator ),
26
+ nil , nil )
27
+ if err != nil {
28
+ return false , err
29
+ }
30
+ if status == 204 {
31
+ return true , nil
32
+ }
33
+ return false , nil
34
+ }
35
+
13
36
// AddCollaboratorOption options when add some user as a collaborator of a repository
14
37
type AddCollaboratorOption struct {
15
38
Permission * string `json:"permission"`
@@ -24,3 +47,11 @@ func (c *Client) AddCollaborator(user, repo, collaborator string, opt AddCollabo
24
47
_ , err = c .getResponse ("PUT" , fmt .Sprintf ("/repos/%s/%s/collaborators/%s" , user , repo , collaborator ), nil , bytes .NewReader (body ))
25
48
return err
26
49
}
50
+
51
+ // DeleteCollaborator remove a collaborator from a repository
52
+ func (c * Client ) DeleteCollaborator (user , repo , collaborator string ) error {
53
+ _ , err := c .getResponse ("DELETE" ,
54
+ fmt .Sprintf ("/repos/%s/%s/collaborators/%s" , user , repo , collaborator ),
55
+ nil , nil )
56
+ return err
57
+ }
0 commit comments