repo_collaborator.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2016 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package gogs
  5. import (
  6. "bytes"
  7. "encoding/json"
  8. "fmt"
  9. )
  10. type Collaborator struct {
  11. *User
  12. Permissions Permission `json:"permissions"`
  13. }
  14. type AddCollaboratorOption struct {
  15. Permission *string `json:"permission"`
  16. }
  17. func (c *Client) ListCollaborator(user, repo string) ([]*Collaborator, error) {
  18. collabs := make([]*Collaborator, 0, 10)
  19. return collabs, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/collaborators", user, repo), nil, nil, &collabs)
  20. }
  21. func (c *Client) AddCollaborator(user, repo, collaborator string, opt AddCollaboratorOption) error {
  22. body, err := json.Marshal(&opt)
  23. if err != nil {
  24. return err
  25. }
  26. _, err = c.getResponse("PUT", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, bytes.NewReader(body))
  27. return err
  28. }
  29. func (c *Client) DeleteCollaborator(user, repo, collaborator string) error {
  30. _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, nil)
  31. return err
  32. }
  33. func (c *Client) IsCollaborator(user, repo, collaborator string) error {
  34. _, err := c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, nil)
  35. return err
  36. }