Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit 46f52f7

Browse files
authored
Merge pull request #27 from ethantkoenig/collaborators
Functions for Collaborators
2 parents 76837c0 + 54a391b commit 46f52f7

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

gitea/repo_collaborator.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,29 @@ import (
1010
"fmt"
1111
)
1212

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+
1336
// AddCollaboratorOption options when add some user as a collaborator of a repository
1437
type AddCollaboratorOption struct {
1538
Permission *string `json:"permission"`
@@ -24,3 +47,11 @@ func (c *Client) AddCollaborator(user, repo, collaborator string, opt AddCollabo
2447
_, err = c.getResponse("PUT", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, bytes.NewReader(body))
2548
return err
2649
}
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

Comments
 (0)