diff --git a/admin_orgs.go b/admin_orgs.go new file mode 100644 index 0000000..9984ecc --- /dev/null +++ b/admin_orgs.go @@ -0,0 +1,30 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" +) + +type CreateOrgOption struct { + UserName string `json:"username"` + FullName string `json:"full_name"` + Description string `json:"description"` + Website string `json:"website"` + Location string `json:"location"` +} + +func (c *Client) CreateOrg(user string, opt CreateOrgOption) (*Organization, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + org := new(Organization) + return org, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/orgs", user), + http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), org) +} diff --git a/gogs.go b/gogs.go index 84599ac..bd263a1 100644 --- a/gogs.go +++ b/gogs.go @@ -14,7 +14,7 @@ import ( ) func Version() string { - return "0.5.0" + return "0.6.0" } // Client represents a Gogs API client. diff --git a/org.go b/org.go new file mode 100644 index 0000000..4d31461 --- /dev/null +++ b/org.go @@ -0,0 +1,54 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" +) + +type Organization struct { + ID int64 `json:"id"` + UserName string `json:"username"` + FullName string `json:"full_name"` + AvatarUrl string `json:"avatar_url"` + Description string `json:"description"` + Website string `json:"website"` + Location string `json:"location"` +} + +func (c *Client) ListMyOrgs() ([]*Organization, error) { + orgs := make([]*Organization, 0, 5) + return orgs, c.getParsedResponse("GET", "/user/orgs", nil, nil, &orgs) +} + +func (c *Client) ListUserOrgs(user string) ([]*Organization, error) { + orgs := make([]*Organization, 0, 5) + return orgs, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/orgs", user), nil, nil, &orgs) +} + +func (c *Client) GetOrg(orgname string) (*Organization, error) { + org := new(Organization) + return org, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s", orgname), nil, nil, org) +} + +type EditOrgOption struct { + FullName string `json:"full_name"` + Description string `json:"description"` + Website string `json:"website"` + Location string `json:"location"` +} + +func (c *Client) EditOrg(orgname string, opt EditOrgOption) error { + body, err := json.Marshal(&opt) + if err != nil { + return err + } + _, err = c.getResponse("PATCH", fmt.Sprintf("/orgs/%s", orgname), + http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body)) + return err +} diff --git a/repo.go b/repo.go index b79ea22..aa6808f 100644 --- a/repo.go +++ b/repo.go @@ -34,8 +34,7 @@ type Repository struct { // ListMyRepos lists all repositories for the authenticated user that has access to. func (c *Client) ListMyRepos() ([]*Repository, error) { repos := make([]*Repository, 0, 10) - err := c.getParsedResponse("GET", "/user/repos", nil, nil, &repos) - return repos, err + return repos, c.getParsedResponse("GET", "/user/repos", nil, nil, &repos) } type CreateRepoOption struct { @@ -73,8 +72,7 @@ func (c *Client) CreateOrgRepo(org string, opt CreateRepoOption) (*Repository, e // GetRepo returns information of a repository of given owner. func (c *Client) GetRepo(owner, reponame string) (*Repository, error) { repo := new(Repository) - return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame), - http.Header{"content-type": []string{"application/json"}}, nil, repo) + return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame), nil, nil, repo) } // DeleteRepo deletes a repository of user or organization.