From 5a4b928dbe507058f592c32f6b1cc89f6714e807 Mon Sep 17 00:00:00 2001 From: Michael Gibson Date: Thu, 21 Jan 2016 09:41:34 -0700 Subject: [PATCH] updating go-gogs-client vendor codebase --- .../gogits/go-gogs-client/admin_orgs.go | 30 ++++++++ .../gogits/go-gogs-client/admin_repos.go | 22 ++++++ .../gogits/go-gogs-client/admin_users.go | 70 +++++++++++++++++++ .../github.com/gogits/go-gogs-client/gogs.go | 9 ++- .../gogits/go-gogs-client/miscellaneous.go | 11 +++ .../github.com/gogits/go-gogs-client/org.go | 54 ++++++++++++++ .../github.com/gogits/go-gogs-client/repo.go | 37 +++++++++- .../gogits/go-gogs-client/repo_hooks.go | 2 + .../gogits/go-gogs-client/repo_keys.go | 52 ++++++++++++++ .../gogits/go-gogs-client/user_app.go | 2 +- .../gogits/go-gogs-client/user_email.go | 46 ++++++++++++ .../gogits/go-gogs-client/user_follow.go | 47 +++++++++++++ .../gogits/go-gogs-client/user_keys.go | 51 ++++++++++++++ .../github.com/gogits/go-gogs-client/utils.go | 9 +++ 14 files changed, 436 insertions(+), 6 deletions(-) create mode 100644 vendor/github.com/gogits/go-gogs-client/admin_orgs.go create mode 100644 vendor/github.com/gogits/go-gogs-client/admin_repos.go create mode 100644 vendor/github.com/gogits/go-gogs-client/admin_users.go create mode 100644 vendor/github.com/gogits/go-gogs-client/miscellaneous.go create mode 100644 vendor/github.com/gogits/go-gogs-client/org.go create mode 100644 vendor/github.com/gogits/go-gogs-client/repo_keys.go create mode 100644 vendor/github.com/gogits/go-gogs-client/user_email.go create mode 100644 vendor/github.com/gogits/go-gogs-client/user_follow.go create mode 100644 vendor/github.com/gogits/go-gogs-client/user_keys.go create mode 100644 vendor/github.com/gogits/go-gogs-client/utils.go diff --git a/vendor/github.com/gogits/go-gogs-client/admin_orgs.go b/vendor/github.com/gogits/go-gogs-client/admin_orgs.go new file mode 100644 index 00000000..ee29464d --- /dev/null +++ b/vendor/github.com/gogits/go-gogs-client/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" binding:"Required"` + FullName string `json:"full_name"` + Description string `json:"description"` + Website string `json:"website"` + Location string `json:"location"` +} + +func (c *Client) AdminCreateOrg(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/vendor/github.com/gogits/go-gogs-client/admin_repos.go b/vendor/github.com/gogits/go-gogs-client/admin_repos.go new file mode 100644 index 00000000..8a213cb1 --- /dev/null +++ b/vendor/github.com/gogits/go-gogs-client/admin_repos.go @@ -0,0 +1,22 @@ +// 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" +) + +func (c *Client) AdminCreateRepo(user string, opt CreateRepoOption) (*Repository, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + repo := new(Repository) + return repo, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/repos", user), + http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), repo) +} diff --git a/vendor/github.com/gogits/go-gogs-client/admin_users.go b/vendor/github.com/gogits/go-gogs-client/admin_users.go new file mode 100644 index 00000000..f8e26d95 --- /dev/null +++ b/vendor/github.com/gogits/go-gogs-client/admin_users.go @@ -0,0 +1,70 @@ +// 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 CreateUserOption struct { + SourceID int64 `json:"source_id"` + LoginName string `json:"login_name"` + Username string `json:"username" binding:"Required;AlphaDashDot;MaxSize(35)"` + Email string `json:"email" binding:"Required;Email;MaxSize(254)"` + Password string `json:"password" binding:"MaxSize(255)"` + SendNotify bool `json:"send_notify"` +} + +func (c *Client) AdminCreateUser(opt CreateUserOption) (*User, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + user := new(User) + return user, c.getParsedResponse("POST", "/admin/users", + http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), user) +} + +type EditUserOption struct { + SourceID int64 `json:"source_id"` + LoginName string `json:"login_name"` + FullName string `json:"full_name" binding:"MaxSize(100)"` + Email string `json:"email" binding:"Required;Email;MaxSize(254)"` + Password string `json:"password" binding:"MaxSize(255)"` + Website string `json:"website" binding:"MaxSize(50)"` + Location string `json:"location" binding:"MaxSize(50)"` + Active *bool `json:"active"` + Admin *bool `json:"admin"` + AllowGitHook *bool `json:"allow_git_hook"` + AllowImportLocal *bool `json:"allow_import_local"` +} + +func (c *Client) AdminEditUser(user string, opt EditUserOption) error { + body, err := json.Marshal(&opt) + if err != nil { + return err + } + _, err = c.getResponse("PATCH", fmt.Sprintf("/admin/users/%s", user), + http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body)) + return err +} + +func (c *Client) AdminDeleteUser(user string) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s", user), nil, nil) + return err +} + +func (c *Client) AdminCreateUserPublicKey(user string, opt CreateKeyOption) (*PublicKey, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + key := new(PublicKey) + return key, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/keys", user), + http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), key) +} diff --git a/vendor/github.com/gogits/go-gogs-client/gogs.go b/vendor/github.com/gogits/go-gogs-client/gogs.go index f921090f..dba1328d 100644 --- a/vendor/github.com/gogits/go-gogs-client/gogs.go +++ b/vendor/github.com/gogits/go-gogs-client/gogs.go @@ -14,7 +14,7 @@ import ( ) func Version() string { - return "0.0.2" + return "0.7.2" } // Client represents a Gogs API client. @@ -33,6 +33,11 @@ func NewClient(url, token string) *Client { } } +// SetHTTPClient replaces default http.Client with user given one. +func (c *Client) SetHTTPClient(client *http.Client) { + c.client = client +} + func (c *Client) getResponse(method, path string, header http.Header, body io.Reader) ([]byte, error) { req, err := http.NewRequest(method, c.url+"/api/v1"+path, body) if err != nil { @@ -61,7 +66,7 @@ func (c *Client) getResponse(method, path string, header http.Header, body io.Re return nil, errors.New("404 Not Found") } - if resp.StatusCode != 200 && resp.StatusCode != 201 { + if resp.StatusCode/100 != 2 { errMap := make(map[string]interface{}) if err = json.Unmarshal(data, &errMap); err != nil { return nil, err diff --git a/vendor/github.com/gogits/go-gogs-client/miscellaneous.go b/vendor/github.com/gogits/go-gogs-client/miscellaneous.go new file mode 100644 index 00000000..fcf362ce --- /dev/null +++ b/vendor/github.com/gogits/go-gogs-client/miscellaneous.go @@ -0,0 +1,11 @@ +// 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 + +type MarkdownOption struct { + Text string + Mode string + Context string +} diff --git a/vendor/github.com/gogits/go-gogs-client/org.go b/vendor/github.com/gogits/go-gogs-client/org.go new file mode 100644 index 00000000..4d31461e --- /dev/null +++ b/vendor/github.com/gogits/go-gogs-client/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/vendor/github.com/gogits/go-gogs-client/repo.go b/vendor/github.com/gogits/go-gogs-client/repo.go index 5f519448..7f703cba 100644 --- a/vendor/github.com/gogits/go-gogs-client/repo.go +++ b/vendor/github.com/gogits/go-gogs-client/repo.go @@ -34,12 +34,11 @@ 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 { - Name string `json:"name" binding:"Required"` + Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"` Description string `json:"description" binding:"MaxSize(255)"` Private bool `json:"private"` AutoInit bool `json:"auto_init"` @@ -70,8 +69,40 @@ func (c *Client) CreateOrgRepo(org string, opt CreateRepoOption) (*Repository, e http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), repo) } +// 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), nil, nil, repo) +} + // DeleteRepo deletes a repository of user or organization. func (c *Client) DeleteRepo(owner, repo string) error { _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s", owner, repo), nil, nil) return err } + +type MigrateRepoOption struct { + CloneAddr string `json:"clone_addr" binding:"Required"` + AuthUsername string `json:"auth_username"` + AuthPassword string `json:"auth_password"` + UID int `json:"uid" binding:"Required"` + RepoName string `json:"repo_name" binding:"Required"` + Mirror bool `json:"mirror"` + Private bool `json:"private"` + Description string `json:"description"` +} + +// MigrateRepo migrates a repository from other Git hosting sources for the +// authenticated user. +// +// To migrate a repository for a organization, the authenticated user must be a +// owner of the specified organization. +func (c *Client) MigrateRepo(opt MigrateRepoOption) (*Repository, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + repo := new(Repository) + return repo, c.getParsedResponse("POST", "/repos/migrate", + http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), repo) +} diff --git a/vendor/github.com/gogits/go-gogs-client/repo_hooks.go b/vendor/github.com/gogits/go-gogs-client/repo_hooks.go index 89d5ef9a..fa3a1e68 100644 --- a/vendor/github.com/gogits/go-gogs-client/repo_hooks.go +++ b/vendor/github.com/gogits/go-gogs-client/repo_hooks.go @@ -95,6 +95,8 @@ type PayloadRepo struct { ID int64 `json:"id"` Name string `json:"name"` URL string `json:"url"` + SSHURL string `json:"ssh_url"` + CloneURL string `json:"clone_url"` Description string `json:"description"` Website string `json:"website"` Watchers int `json:"watchers"` diff --git a/vendor/github.com/gogits/go-gogs-client/repo_keys.go b/vendor/github.com/gogits/go-gogs-client/repo_keys.go new file mode 100644 index 00000000..dfd15c9e --- /dev/null +++ b/vendor/github.com/gogits/go-gogs-client/repo_keys.go @@ -0,0 +1,52 @@ +// 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" + "time" +) + +type DeployKey struct { + ID int64 `json:"id"` + Key string `json:"key"` + URL string `json:"url"` + Title string `json:"title"` + Created time.Time `json:"created_at"` + ReadOnly bool `json:"read_only"` +} + +func (c *Client) ListDeployKeys(user, repo string) ([]*DeployKey, error) { + keys := make([]*DeployKey, 0, 10) + return keys, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys", user, repo), nil, nil, &keys) +} + +func (c *Client) GetDeployKey(user, repo string, keyID int64) (*DeployKey, error) { + key := new(DeployKey) + return key, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys/%d", user, repo, keyID), nil, nil, &key) +} + +type CreateKeyOption struct { + Title string `json:"title" binding:"Required"` + Key string `json:"key" binding:"Required"` +} + +func (c *Client) CreateDeployKey(user, repo string, opt CreateKeyOption) (*DeployKey, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + key := new(DeployKey) + return key, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/keys", user, repo), + http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), key) +} + +func (c *Client) DeleteDeployKey(owner, repo string, keyID int64) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/keys/%d", owner, repo, keyID), nil, nil) + return err +} diff --git a/vendor/github.com/gogits/go-gogs-client/user_app.go b/vendor/github.com/gogits/go-gogs-client/user_app.go index 152492bf..965ed6eb 100644 --- a/vendor/github.com/gogits/go-gogs-client/user_app.go +++ b/vendor/github.com/gogits/go-gogs-client/user_app.go @@ -29,7 +29,7 @@ func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) { } type CreateAccessTokenOption struct { - Name string `json:"name"` + Name string `json:"name" binding:"Required"` } func (c *Client) CreateAccessToken(user, pass string, opt CreateAccessTokenOption) (*AccessToken, error) { diff --git a/vendor/github.com/gogits/go-gogs-client/user_email.go b/vendor/github.com/gogits/go-gogs-client/user_email.go new file mode 100644 index 00000000..b3465992 --- /dev/null +++ b/vendor/github.com/gogits/go-gogs-client/user_email.go @@ -0,0 +1,46 @@ +// 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" + "net/http" +) + +type Email struct { + Email string `json:"email"` + Verified bool `json:"verified"` + Primary bool `json:"primary"` +} + +func (c *Client) ListEmails() ([]*Email, error) { + emails := make([]*Email, 0, 3) + return emails, c.getParsedResponse("GET", "/user/emails", nil, nil, &emails) +} + +type CreateEmailOption struct { + Emails []string `json:"emails"` +} + +func (c *Client) AddEmail(opt CreateEmailOption) ([]*Email, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + emails := make([]*Email, 0, 3) + return emails, c.getParsedResponse("POST", "/user/emails", + http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), emails) +} + +func (c *Client) DeleteEmail(opt CreateEmailOption) error { + body, err := json.Marshal(&opt) + if err != nil { + return err + } + _, err = c.getResponse("DELETE", "/user/emails", + http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body)) + return err +} diff --git a/vendor/github.com/gogits/go-gogs-client/user_follow.go b/vendor/github.com/gogits/go-gogs-client/user_follow.go new file mode 100644 index 00000000..36cc65d4 --- /dev/null +++ b/vendor/github.com/gogits/go-gogs-client/user_follow.go @@ -0,0 +1,47 @@ +// 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 "fmt" + +func (c *Client) ListMyFollowers(page int) ([]*User, error) { + users := make([]*User, 0, 10) + return users, c.getParsedResponse("GET", fmt.Sprintf("/user/followers?page=%d", page), nil, nil, &users) +} + +func (c *Client) ListFollowers(user string, page int) ([]*User, error) { + users := make([]*User, 0, 10) + return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/followers?page=%d", user, page), nil, nil, &users) +} + +func (c *Client) ListMyFollowing(page int) ([]*User, error) { + users := make([]*User, 0, 10) + return users, c.getParsedResponse("GET", fmt.Sprintf("/user/following?page=%d", page), nil, nil, &users) +} + +func (c *Client) ListFollowing(user string, page int) ([]*User, error) { + users := make([]*User, 0, 10) + return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/following?page=%d", user, page), nil, nil, &users) +} + +func (c *Client) IsFollowing(target string) bool { + _, err := c.getResponse("GET", fmt.Sprintf("/user/following/%s", target), nil, nil) + return err == nil +} + +func (c *Client) IsUserFollowing(user, target string) bool { + _, err := c.getResponse("GET", fmt.Sprintf("/users/%s/following/%s", user, target), nil, nil) + return err == nil +} + +func (c *Client) Follow(target string) error { + _, err := c.getResponse("PUT", fmt.Sprintf("/user/following/%s", target), nil, nil) + return err +} + +func (c *Client) Unfollow(target string) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/user/following/%s", target), nil, nil) + return err +} diff --git a/vendor/github.com/gogits/go-gogs-client/user_keys.go b/vendor/github.com/gogits/go-gogs-client/user_keys.go new file mode 100644 index 00000000..cb217572 --- /dev/null +++ b/vendor/github.com/gogits/go-gogs-client/user_keys.go @@ -0,0 +1,51 @@ +// 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" + "time" +) + +type PublicKey struct { + ID int64 `json:"id"` + Key string `json:"key"` + URL string `json:"url,omitempty"` + Title string `json:"title,omitempty"` + Created time.Time `json:"created_at,omitempty"` +} + +func (c *Client) ListPublicKeys(user string) ([]*PublicKey, error) { + keys := make([]*PublicKey, 0, 10) + return keys, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/keys", user), nil, nil, &keys) +} + +func (c *Client) ListMyPublicKeys(user string) ([]*PublicKey, error) { + keys := make([]*PublicKey, 0, 10) + return keys, c.getParsedResponse("GET", fmt.Sprintf("/user/keys", user), nil, nil, &keys) +} + +func (c *Client) GetPublicKey(keyID int64) (*PublicKey, error) { + key := new(PublicKey) + return key, c.getParsedResponse("GET", fmt.Sprintf("/user/keys/%d", keyID), nil, nil, &key) +} + +func (c *Client) CreatePublicKey(opt CreateKeyOption) (*PublicKey, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + key := new(PublicKey) + return key, c.getParsedResponse("POST", "/user/keys", + http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), key) +} + +func (c *Client) DeletePublicKey(keyID int64) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/user/keys/%d", keyID), nil, nil) + return err +} diff --git a/vendor/github.com/gogits/go-gogs-client/utils.go b/vendor/github.com/gogits/go-gogs-client/utils.go new file mode 100644 index 00000000..134fd8e5 --- /dev/null +++ b/vendor/github.com/gogits/go-gogs-client/utils.go @@ -0,0 +1,9 @@ +// 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 + +func Bool(v bool) *bool { + return &v +}