add orgs
This commit is contained in:
parent
6cc168ca78
commit
30a98edc71
4 changed files with 87 additions and 5 deletions
30
admin_orgs.go
Normal file
30
admin_orgs.go
Normal file
|
@ -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)
|
||||||
|
}
|
2
gogs.go
2
gogs.go
|
@ -14,7 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Version() string {
|
func Version() string {
|
||||||
return "0.5.0"
|
return "0.6.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client represents a Gogs API client.
|
// Client represents a Gogs API client.
|
||||||
|
|
54
org.go
Normal file
54
org.go
Normal file
|
@ -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
|
||||||
|
}
|
6
repo.go
6
repo.go
|
@ -34,8 +34,7 @@ type Repository struct {
|
||||||
// ListMyRepos lists all repositories for the authenticated user that has access to.
|
// ListMyRepos lists all repositories for the authenticated user that has access to.
|
||||||
func (c *Client) ListMyRepos() ([]*Repository, error) {
|
func (c *Client) ListMyRepos() ([]*Repository, error) {
|
||||||
repos := make([]*Repository, 0, 10)
|
repos := make([]*Repository, 0, 10)
|
||||||
err := c.getParsedResponse("GET", "/user/repos", nil, nil, &repos)
|
return repos, c.getParsedResponse("GET", "/user/repos", nil, nil, &repos)
|
||||||
return repos, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateRepoOption struct {
|
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.
|
// GetRepo returns information of a repository of given owner.
|
||||||
func (c *Client) GetRepo(owner, reponame string) (*Repository, error) {
|
func (c *Client) GetRepo(owner, reponame string) (*Repository, error) {
|
||||||
repo := new(Repository)
|
repo := new(Repository)
|
||||||
return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame),
|
return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame), nil, nil, repo)
|
||||||
http.Header{"content-type": []string{"application/json"}}, nil, repo)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRepo deletes a repository of user or organization.
|
// DeleteRepo deletes a repository of user or organization.
|
||||||
|
|
Loading…
Reference in a new issue