Skip to content

Commit 30a98ed

Browse files
committed
add orgs
1 parent 6cc168c commit 30a98ed

File tree

4 files changed

+87
-5
lines changed

4 files changed

+87
-5
lines changed

admin_orgs.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
5+
package gogs
6+
7+
import (
8+
"bytes"
9+
"encoding/json"
10+
"fmt"
11+
"net/http"
12+
)
13+
14+
type CreateOrgOption struct {
15+
UserName string `json:"username"`
16+
FullName string `json:"full_name"`
17+
Description string `json:"description"`
18+
Website string `json:"website"`
19+
Location string `json:"location"`
20+
}
21+
22+
func (c *Client) CreateOrg(user string, opt CreateOrgOption) (*Organization, error) {
23+
body, err := json.Marshal(&opt)
24+
if err != nil {
25+
return nil, err
26+
}
27+
org := new(Organization)
28+
return org, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/orgs", user),
29+
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), org)
30+
}

gogs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func Version() string {
17-
return "0.5.0"
17+
return "0.6.0"
1818
}
1919

2020
// Client represents a Gogs API client.

org.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
5+
package gogs
6+
7+
import (
8+
"bytes"
9+
"encoding/json"
10+
"fmt"
11+
"net/http"
12+
)
13+
14+
type Organization struct {
15+
ID int64 `json:"id"`
16+
UserName string `json:"username"`
17+
FullName string `json:"full_name"`
18+
AvatarUrl string `json:"avatar_url"`
19+
Description string `json:"description"`
20+
Website string `json:"website"`
21+
Location string `json:"location"`
22+
}
23+
24+
func (c *Client) ListMyOrgs() ([]*Organization, error) {
25+
orgs := make([]*Organization, 0, 5)
26+
return orgs, c.getParsedResponse("GET", "/user/orgs", nil, nil, &orgs)
27+
}
28+
29+
func (c *Client) ListUserOrgs(user string) ([]*Organization, error) {
30+
orgs := make([]*Organization, 0, 5)
31+
return orgs, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/orgs", user), nil, nil, &orgs)
32+
}
33+
34+
func (c *Client) GetOrg(orgname string) (*Organization, error) {
35+
org := new(Organization)
36+
return org, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s", orgname), nil, nil, org)
37+
}
38+
39+
type EditOrgOption struct {
40+
FullName string `json:"full_name"`
41+
Description string `json:"description"`
42+
Website string `json:"website"`
43+
Location string `json:"location"`
44+
}
45+
46+
func (c *Client) EditOrg(orgname string, opt EditOrgOption) error {
47+
body, err := json.Marshal(&opt)
48+
if err != nil {
49+
return err
50+
}
51+
_, err = c.getResponse("PATCH", fmt.Sprintf("/orgs/%s", orgname),
52+
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body))
53+
return err
54+
}

repo.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ type Repository struct {
3434
// ListMyRepos lists all repositories for the authenticated user that has access to.
3535
func (c *Client) ListMyRepos() ([]*Repository, error) {
3636
repos := make([]*Repository, 0, 10)
37-
err := c.getParsedResponse("GET", "/user/repos", nil, nil, &repos)
38-
return repos, err
37+
return repos, c.getParsedResponse("GET", "/user/repos", nil, nil, &repos)
3938
}
4039

4140
type CreateRepoOption struct {
@@ -73,8 +72,7 @@ func (c *Client) CreateOrgRepo(org string, opt CreateRepoOption) (*Repository, e
7372
// GetRepo returns information of a repository of given owner.
7473
func (c *Client) GetRepo(owner, reponame string) (*Repository, error) {
7574
repo := new(Repository)
76-
return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame),
77-
http.Header{"content-type": []string{"application/json"}}, nil, repo)
75+
return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame), nil, nil, repo)
7876
}
7977

8078
// DeleteRepo deletes a repository of user or organization.

0 commit comments

Comments
 (0)