org.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2015 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 Organization struct {
  11. ID int64 `json:"id"`
  12. UserName string `json:"username"`
  13. FullName string `json:"full_name"`
  14. AvatarUrl string `json:"avatar_url"`
  15. Description string `json:"description"`
  16. Website string `json:"website"`
  17. Location string `json:"location"`
  18. }
  19. func (c *Client) ListMyOrgs() ([]*Organization, error) {
  20. orgs := make([]*Organization, 0, 5)
  21. return orgs, c.getParsedResponse("GET", "/user/orgs", nil, nil, &orgs)
  22. }
  23. func (c *Client) ListUserOrgs(user string) ([]*Organization, error) {
  24. orgs := make([]*Organization, 0, 5)
  25. return orgs, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/orgs", user), nil, nil, &orgs)
  26. }
  27. func (c *Client) GetOrg(orgname string) (*Organization, error) {
  28. org := new(Organization)
  29. return org, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s", orgname), nil, nil, org)
  30. }
  31. type CreateOrgOption struct {
  32. UserName string `json:"username" binding:"Required"`
  33. FullName string `json:"full_name"`
  34. Description string `json:"description"`
  35. Website string `json:"website"`
  36. Location string `json:"location"`
  37. }
  38. type EditOrgOption struct {
  39. FullName string `json:"full_name"`
  40. Description string `json:"description"`
  41. Website string `json:"website"`
  42. Location string `json:"location"`
  43. }
  44. func (c *Client) EditOrg(orgname string, opt EditOrgOption) error {
  45. body, err := json.Marshal(&opt)
  46. if err != nil {
  47. return err
  48. }
  49. _, err = c.getResponse("PATCH", fmt.Sprintf("/orgs/%s", orgname), jsonHeader, bytes.NewReader(body))
  50. return err
  51. }