mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-24 08:02:18 +02:00
Update gogs client (#487)
* update github.com/gogits/go-gogs-client * migrate * fix test & use DefaultBranch
This commit is contained in:
parent
e3033015ae
commit
473a05d5b5
2
go.mod
2
go.mod
@ -23,7 +23,7 @@ require (
|
||||
github.com/gin-gonic/gin v1.7.4
|
||||
github.com/go-playground/validator/v10 v10.9.0 // indirect
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
github.com/gogits/go-gogs-client v0.0.0-20160212212711-d584b1e0fb4d
|
||||
github.com/gogits/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85
|
||||
github.com/golang-jwt/jwt/v4 v4.1.0
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/google/go-github/v39 v39.1.0
|
||||
|
4
go.sum
4
go.sum
@ -322,8 +322,8 @@ github.com/godbus/dbus v0.0.0-20180201030542-885f9cc04c9c/go.mod h1:/YcGZj5zSblf
|
||||
github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
|
||||
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/gogits/go-gogs-client v0.0.0-20160212212711-d584b1e0fb4d h1:2sle18csjgDC8lnX5SHBwoyBlE1QLj8A8vgDxd2Mwbw=
|
||||
github.com/gogits/go-gogs-client v0.0.0-20160212212711-d584b1e0fb4d/go.mod h1:cY2AIrMgHm6oOHmR7jY+9TtjzSjQ3iG7tURJG3Y6XH0=
|
||||
github.com/gogits/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85 h1:04sojTxgYxu1L4Hn7Tgf7UVtIosVa6CuHtvNY+7T1K4=
|
||||
github.com/gogits/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85/go.mod h1:cY2AIrMgHm6oOHmR7jY+9TtjzSjQ3iG7tURJG3Y6XH0=
|
||||
github.com/gogo/googleapis v1.2.0/go.mod h1:Njal3psf3qN6dwBtQfUmBZh2ybovJ0tlu3o/AC7HYjU=
|
||||
github.com/gogo/googleapis v1.4.0/go.mod h1:5YRNX2z1oM5gXdAkurHa942MDgEJyk02w4OecKY87+c=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
|
@ -31,7 +31,7 @@ import (
|
||||
func toRepo(from *gogs.Repository, privateMode bool) *model.Repo {
|
||||
name := strings.Split(from.FullName, "/")[1]
|
||||
avatar := expandAvatar(
|
||||
from.HtmlUrl,
|
||||
from.HTMLURL,
|
||||
from.Owner.AvatarUrl,
|
||||
)
|
||||
private := from.Private
|
||||
@ -44,15 +44,15 @@ func toRepo(from *gogs.Repository, privateMode bool) *model.Repo {
|
||||
Owner: from.Owner.UserName,
|
||||
FullName: from.FullName,
|
||||
Avatar: avatar,
|
||||
Link: from.HtmlUrl,
|
||||
Link: from.HTMLURL,
|
||||
IsPrivate: private,
|
||||
Clone: from.CloneUrl,
|
||||
Branch: "master",
|
||||
Clone: from.CloneURL,
|
||||
Branch: from.DefaultBranch,
|
||||
}
|
||||
}
|
||||
|
||||
// helper function that converts a Gogs permission to a Woodpecker permission.
|
||||
func toPerm(from gogs.Permission) *model.Perm {
|
||||
func toPerm(from *gogs.Permission) *model.Perm {
|
||||
return &model.Perm{
|
||||
Pull: from.Pull,
|
||||
Push: from.Push,
|
||||
|
@ -144,7 +144,7 @@ func Test_parse(t *testing.T) {
|
||||
})
|
||||
|
||||
g.It("Should return a Perm struct from a Gogs Perm", func() {
|
||||
perms := []gogs.Permission{
|
||||
perms := []*gogs.Permission{
|
||||
{Admin: true, Pull: true, Push: true},
|
||||
{Admin: true, Pull: true, Push: false},
|
||||
{Admin: true, Push: false, Pull: false},
|
||||
@ -171,21 +171,22 @@ func Test_parse(t *testing.T) {
|
||||
g.It("Should return a Repo struct from a Gogs Repo", func() {
|
||||
from := gogs.Repository{
|
||||
FullName: "gophers/hello-world",
|
||||
Owner: gogs.User{
|
||||
Owner: &gogs.User{
|
||||
UserName: "gordon",
|
||||
AvatarUrl: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87",
|
||||
},
|
||||
CloneUrl: "http://gogs.golang.org/gophers/hello-world.git",
|
||||
HtmlUrl: "http://gogs.golang.org/gophers/hello-world",
|
||||
CloneURL: "http://gogs.golang.org/gophers/hello-world.git",
|
||||
HTMLURL: "http://gogs.golang.org/gophers/hello-world",
|
||||
Private: true,
|
||||
DefaultBranch: "master",
|
||||
}
|
||||
repo := toRepo(&from, false)
|
||||
g.Assert(repo.FullName).Equal(from.FullName)
|
||||
g.Assert(repo.Owner).Equal(from.Owner.UserName)
|
||||
g.Assert(repo.Name).Equal("hello-world")
|
||||
g.Assert(repo.Branch).Equal("master")
|
||||
g.Assert(repo.Link).Equal(from.HtmlUrl)
|
||||
g.Assert(repo.Clone).Equal(from.CloneUrl)
|
||||
g.Assert(repo.Link).Equal(from.HTMLURL)
|
||||
g.Assert(repo.Clone).Equal(from.CloneURL)
|
||||
g.Assert(repo.Avatar).Equal(from.Owner.AvatarUrl)
|
||||
g.Assert(repo.IsPrivate).Equal(from.Private)
|
||||
})
|
||||
|
43
vendor/github.com/gogits/go-gogs-client/admin_org.go
generated
vendored
Normal file
43
vendor/github.com/gogits/go-gogs-client/admin_org.go
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
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),
|
||||
jsonHeader, bytes.NewReader(body), org)
|
||||
}
|
||||
|
||||
func (c *Client) AdminCreateTeam(user string, opt CreateTeamOption) (*Team, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
team := new(Team)
|
||||
return team, c.getParsedResponse("POST", fmt.Sprintf("/admin/orgs/%s/teams", user),
|
||||
jsonHeader, bytes.NewReader(body), team)
|
||||
}
|
||||
|
||||
func (c *Client) AdminAddTeamMembership(teamID int64, user string) error {
|
||||
_, err := c.getResponse("PUT", fmt.Sprintf("/admin/teams/%d/members/%s", teamID, user),
|
||||
jsonHeader, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) AdminAddTeamRepository(teamID int64, repo string) error {
|
||||
_, err := c.getResponse("PUT", fmt.Sprintf("/admin/teams/%d/repos/%s", teamID, repo),
|
||||
jsonHeader, nil)
|
||||
return err
|
||||
}
|
30
vendor/github.com/gogits/go-gogs-client/admin_orgs.go
generated
vendored
30
vendor/github.com/gogits/go-gogs-client/admin_orgs.go
generated
vendored
@ -1,30 +0,0 @@
|
||||
// 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)
|
||||
}
|
@ -8,7 +8,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (c *Client) AdminCreateRepo(user string, opt CreateRepoOption) (*Repository, error) {
|
||||
@ -18,5 +17,5 @@ func (c *Client) AdminCreateRepo(user string, opt CreateRepoOption) (*Repository
|
||||
}
|
||||
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)
|
||||
jsonHeader, bytes.NewReader(body), repo)
|
||||
}
|
@ -8,13 +8,13 @@ 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)"`
|
||||
FullName string `json:"full_name" binding:"MaxSize(100)"`
|
||||
Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
|
||||
Password string `json:"password" binding:"MaxSize(255)"`
|
||||
SendNotify bool `json:"send_notify"`
|
||||
@ -26,8 +26,7 @@ func (c *Client) AdminCreateUser(opt CreateUserOption) (*User, error) {
|
||||
return nil, err
|
||||
}
|
||||
user := new(User)
|
||||
return user, c.getParsedResponse("POST", "/admin/users",
|
||||
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), user)
|
||||
return user, c.getParsedResponse("POST", "/admin/users", jsonHeader, bytes.NewReader(body), user)
|
||||
}
|
||||
|
||||
type EditUserOption struct {
|
||||
@ -42,6 +41,7 @@ type EditUserOption struct {
|
||||
Admin *bool `json:"admin"`
|
||||
AllowGitHook *bool `json:"allow_git_hook"`
|
||||
AllowImportLocal *bool `json:"allow_import_local"`
|
||||
MaxRepoCreation *int `json:"max_repo_creation"`
|
||||
}
|
||||
|
||||
func (c *Client) AdminEditUser(user string, opt EditUserOption) error {
|
||||
@ -49,8 +49,7 @@ func (c *Client) AdminEditUser(user string, opt EditUserOption) error {
|
||||
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))
|
||||
_, err = c.getResponse("PATCH", fmt.Sprintf("/admin/users/%s", user), jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
}
|
||||
|
||||
@ -65,6 +64,5 @@ func (c *Client) AdminCreateUserPublicKey(user string, opt CreateKeyOption) (*Pu
|
||||
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)
|
||||
return key, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/keys", user), jsonHeader, bytes.NewReader(body), key)
|
||||
}
|
12
vendor/github.com/gogits/go-gogs-client/gogs.go
generated
vendored
12
vendor/github.com/gogits/go-gogs-client/gogs.go
generated
vendored
@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func Version() string {
|
||||
return "0.7.3"
|
||||
return "0.13.0"
|
||||
}
|
||||
|
||||
// Client represents a Gogs API client.
|
||||
@ -24,7 +24,7 @@ type Client struct {
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
// NewClient initializes and returns a API client.
|
||||
// NewClient initializes and returns an API client.
|
||||
func NewClient(url, token string) *Client {
|
||||
return &Client{
|
||||
url: strings.TrimSuffix(url, "/"),
|
||||
@ -38,7 +38,7 @@ 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) {
|
||||
func (c *Client) doRequest(method, path string, header http.Header, body io.Reader) (*http.Response, error) {
|
||||
req, err := http.NewRequest(method, c.url+"/api/v1"+path, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -48,7 +48,11 @@ func (c *Client) getResponse(method, path string, header http.Header, body io.Re
|
||||
req.Header[k] = v
|
||||
}
|
||||
|
||||
resp, err := c.client.Do(req)
|
||||
return c.client.Do(req)
|
||||
}
|
||||
|
||||
func (c *Client) getResponse(method, path string, header http.Header, body io.Reader) ([]byte, error) {
|
||||
resp, err := c.doRequest(method, path, header, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
103
vendor/github.com/gogits/go-gogs-client/issue.go
generated
vendored
Normal file
103
vendor/github.com/gogits/go-gogs-client/issue.go
generated
vendored
Normal file
@ -0,0 +1,103 @@
|
||||
// Copyright 2016 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"
|
||||
"time"
|
||||
)
|
||||
|
||||
type StateType string
|
||||
|
||||
const (
|
||||
STATE_OPEN StateType = "open"
|
||||
STATE_CLOSED StateType = "closed"
|
||||
)
|
||||
|
||||
type PullRequestMeta struct {
|
||||
HasMerged bool `json:"merged"`
|
||||
Merged *time.Time `json:"merged_at"`
|
||||
}
|
||||
|
||||
type Issue struct {
|
||||
ID int64 `json:"id"`
|
||||
Index int64 `json:"number"`
|
||||
Poster *User `json:"user"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Labels []*Label `json:"labels"`
|
||||
Milestone *Milestone `json:"milestone"`
|
||||
Assignee *User `json:"assignee"`
|
||||
State StateType `json:"state"`
|
||||
Comments int `json:"comments"`
|
||||
Created time.Time `json:"created_at"`
|
||||
Updated time.Time `json:"updated_at"`
|
||||
|
||||
PullRequest *PullRequestMeta `json:"pull_request"`
|
||||
}
|
||||
|
||||
type ListIssueOption struct {
|
||||
Page int
|
||||
State string
|
||||
}
|
||||
|
||||
func (c *Client) ListIssues(opt ListIssueOption) ([]*Issue, error) {
|
||||
issues := make([]*Issue, 0, 10)
|
||||
return issues, c.getParsedResponse("GET", fmt.Sprintf("/issues?page=%d&state=%s", opt.Page, opt.State), nil, nil, &issues)
|
||||
}
|
||||
|
||||
func (c *Client) ListUserIssues(opt ListIssueOption) ([]*Issue, error) {
|
||||
issues := make([]*Issue, 0, 10)
|
||||
return issues, c.getParsedResponse("GET", fmt.Sprintf("/user/issues?page=%d&state=%s", opt.Page, opt.State), nil, nil, &issues)
|
||||
}
|
||||
|
||||
func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Issue, error) {
|
||||
issues := make([]*Issue, 0, 10)
|
||||
return issues, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues?page=%d&state=%s", owner, repo, opt.Page, opt.State), nil, nil, &issues)
|
||||
}
|
||||
|
||||
func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, error) {
|
||||
issue := new(Issue)
|
||||
return issue, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), nil, nil, issue)
|
||||
}
|
||||
|
||||
type CreateIssueOption struct {
|
||||
Title string `json:"title" binding:"Required"`
|
||||
Body string `json:"body"`
|
||||
Assignee string `json:"assignee"`
|
||||
Milestone int64 `json:"milestone"`
|
||||
Labels []int64 `json:"labels"`
|
||||
Closed bool `json:"closed"`
|
||||
}
|
||||
|
||||
func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
issue := new(Issue)
|
||||
return issue, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues", owner, repo),
|
||||
jsonHeader, bytes.NewReader(body), issue)
|
||||
}
|
||||
|
||||
type EditIssueOption struct {
|
||||
Title string `json:"title"`
|
||||
Body *string `json:"body"`
|
||||
Assignee *string `json:"assignee"`
|
||||
Milestone *int64 `json:"milestone"`
|
||||
State *string `json:"state"`
|
||||
}
|
||||
|
||||
func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption) (*Issue, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
issue := new(Issue)
|
||||
return issue, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index),
|
||||
jsonHeader, bytes.NewReader(body), issue)
|
||||
}
|
70
vendor/github.com/gogits/go-gogs-client/issue_comment.go
generated
vendored
Normal file
70
vendor/github.com/gogits/go-gogs-client/issue_comment.go
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
// Copyright 2016 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"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Comment represents a comment in commit and issue page.
|
||||
type Comment struct {
|
||||
ID int64 `json:"id"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
Poster *User `json:"user"`
|
||||
Body string `json:"body"`
|
||||
Created time.Time `json:"created_at"`
|
||||
Updated time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// ListIssueComments list comments on an issue.
|
||||
func (c *Client) ListIssueComments(owner, repo string, index int64) ([]*Comment, error) {
|
||||
comments := make([]*Comment, 0, 10)
|
||||
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), nil, nil, &comments)
|
||||
}
|
||||
|
||||
// ListRepoIssueComments list comments for a given repo.
|
||||
func (c *Client) ListRepoIssueComments(owner, repo string) ([]*Comment, error) {
|
||||
comments := make([]*Comment, 0, 10)
|
||||
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments", owner, repo), nil, nil, &comments)
|
||||
}
|
||||
|
||||
// CreateIssueCommentOption is option when creating an issue comment.
|
||||
type CreateIssueCommentOption struct {
|
||||
Body string `json:"body" binding:"Required"`
|
||||
}
|
||||
|
||||
// CreateIssueComment create comment on an issue.
|
||||
func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateIssueCommentOption) (*Comment, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
comment := new(Comment)
|
||||
return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment)
|
||||
}
|
||||
|
||||
// EditIssueCommentOption is option when editing an issue comment.
|
||||
type EditIssueCommentOption struct {
|
||||
Body string `json:"body" binding:"Required"`
|
||||
}
|
||||
|
||||
// EditIssueComment edits an issue comment.
|
||||
func (c *Client) EditIssueComment(owner, repo string, index, commentID int64, opt EditIssueCommentOption) (*Comment, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
comment := new(Comment)
|
||||
return comment, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d/comments/%d", owner, repo, index, commentID), jsonHeader, bytes.NewReader(body), comment)
|
||||
}
|
||||
|
||||
// DeleteIssueComment deletes an issue comment.
|
||||
func (c *Client) DeleteIssueComment(owner, repo string, index, commentID int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/comments/%d", owner, repo, index, commentID), nil, nil)
|
||||
return err
|
||||
}
|
99
vendor/github.com/gogits/go-gogs-client/issue_label.go
generated
vendored
Normal file
99
vendor/github.com/gogits/go-gogs-client/issue_label.go
generated
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
// Copyright 2016 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"
|
||||
)
|
||||
|
||||
type Label struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Color string `json:"color"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
func (c *Client) ListRepoLabels(owner, repo string) ([]*Label, error) {
|
||||
labels := make([]*Label, 0, 10)
|
||||
return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels", owner, repo), nil, nil, &labels)
|
||||
}
|
||||
|
||||
func (c *Client) GetRepoLabel(owner, repo string, id int64) (*Label, error) {
|
||||
label := new(Label)
|
||||
return label, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil, label)
|
||||
}
|
||||
|
||||
type CreateLabelOption struct {
|
||||
Name string `json:"name" binding:"Required"`
|
||||
Color string `json:"color" binding:"Required;Size(7)"`
|
||||
}
|
||||
|
||||
func (c *Client) CreateLabel(owner, repo string, opt CreateLabelOption) (*Label, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
label := new(Label)
|
||||
return label, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/labels", owner, repo),
|
||||
jsonHeader, bytes.NewReader(body), label)
|
||||
}
|
||||
|
||||
type EditLabelOption struct {
|
||||
Name *string `json:"name"`
|
||||
Color *string `json:"color"`
|
||||
}
|
||||
|
||||
func (c *Client) EditLabel(owner, repo string, id int64, opt EditLabelOption) (*Label, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
label := new(Label)
|
||||
return label, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), label)
|
||||
}
|
||||
|
||||
func (c *Client) DeleteLabel(owner, repo string, id int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
type IssueLabelsOption struct {
|
||||
Labels []int64 `json:"labels"`
|
||||
}
|
||||
|
||||
func (c *Client) GetIssueLabels(owner, repo string, index int64) ([]*Label, error) {
|
||||
labels := make([]*Label, 0, 5)
|
||||
return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil, &labels)
|
||||
}
|
||||
|
||||
func (c *Client) AddIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
labels := make([]*Label, 0)
|
||||
return labels, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels)
|
||||
}
|
||||
|
||||
func (c *Client) ReplaceIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
labels := make([]*Label, 0)
|
||||
return labels, c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels)
|
||||
}
|
||||
|
||||
func (c *Client) DeleteIssueLabel(owner, repo string, index, label int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels/%d", owner, repo, index, label), nil, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) ClearIssueLabels(owner, repo string, index int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil)
|
||||
return err
|
||||
}
|
69
vendor/github.com/gogits/go-gogs-client/issue_milestone.go
generated
vendored
Normal file
69
vendor/github.com/gogits/go-gogs-client/issue_milestone.go
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
// Copyright 2016 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"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Milestone struct {
|
||||
ID int64 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
State StateType `json:"state"`
|
||||
OpenIssues int `json:"open_issues"`
|
||||
ClosedIssues int `json:"closed_issues"`
|
||||
Closed *time.Time `json:"closed_at"`
|
||||
Deadline *time.Time `json:"due_on"`
|
||||
}
|
||||
|
||||
func (c *Client) ListRepoMilestones(owner, repo string) ([]*Milestone, error) {
|
||||
milestones := make([]*Milestone, 0, 10)
|
||||
return milestones, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), nil, nil, &milestones)
|
||||
}
|
||||
|
||||
func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, error) {
|
||||
milestone := new(Milestone)
|
||||
return milestone, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil, milestone)
|
||||
}
|
||||
|
||||
type CreateMilestoneOption struct {
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Deadline *time.Time `json:"due_on"`
|
||||
}
|
||||
|
||||
func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption) (*Milestone, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
milestone := new(Milestone)
|
||||
return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), jsonHeader, bytes.NewReader(body), milestone)
|
||||
}
|
||||
|
||||
type EditMilestoneOption struct {
|
||||
Title string `json:"title"`
|
||||
Description *string `json:"description"`
|
||||
State *string `json:"state"`
|
||||
Deadline *time.Time `json:"due_on"`
|
||||
}
|
||||
|
||||
func (c *Client) EditMilestone(owner, repo string, id int64, opt EditMilestoneOption) (*Milestone, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
milestone := new(Milestone)
|
||||
return milestone, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), milestone)
|
||||
}
|
||||
|
||||
func (c *Client) DeleteMilestone(owner, repo string, id int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil)
|
||||
return err
|
||||
}
|
9
vendor/github.com/gogits/go-gogs-client/media_types.go
generated
vendored
Normal file
9
vendor/github.com/gogits/go-gogs-client/media_types.go
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
// Copyright 2018 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
|
||||
|
||||
const (
|
||||
MediaApplicationSHA = "application/vnd.gogs.sha"
|
||||
)
|
1
vendor/github.com/gogits/go-gogs-client/miscellaneous.go
generated
vendored
1
vendor/github.com/gogits/go-gogs-client/miscellaneous.go
generated
vendored
@ -6,6 +6,5 @@ package gogs
|
||||
|
||||
type MarkdownOption struct {
|
||||
Text string
|
||||
Mode string
|
||||
Context string
|
||||
}
|
||||
|
21
vendor/github.com/gogits/go-gogs-client/org.go
generated
vendored
21
vendor/github.com/gogits/go-gogs-client/org.go
generated
vendored
@ -8,7 +8,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Organization struct {
|
||||
@ -36,6 +35,14 @@ func (c *Client) GetOrg(orgname string) (*Organization, error) {
|
||||
return org, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s", orgname), nil, nil, org)
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
type EditOrgOption struct {
|
||||
FullName string `json:"full_name"`
|
||||
Description string `json:"description"`
|
||||
@ -43,12 +50,20 @@ type EditOrgOption struct {
|
||||
Location string `json:"location"`
|
||||
}
|
||||
|
||||
func (c *Client) CreateOrg(opt CreateOrgOption) (*Organization, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
org := new(Organization)
|
||||
return org, c.getParsedResponse("POST", "/user/orgs", jsonHeader, bytes.NewReader(body), org)
|
||||
}
|
||||
|
||||
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))
|
||||
_, err = c.getResponse("PATCH", fmt.Sprintf("/orgs/%s", orgname), jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
}
|
||||
|
24
vendor/github.com/gogits/go-gogs-client/org_member.go
generated
vendored
Normal file
24
vendor/github.com/gogits/go-gogs-client/org_member.go
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2016 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"
|
||||
)
|
||||
|
||||
type AddOrgMembershipOption struct {
|
||||
Role string `json:"role" binding:"Required"`
|
||||
}
|
||||
|
||||
func (c *Client) AddOrgMembership(org, user string, opt AddOrgMembershipOption) error {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.getResponse("PUT", fmt.Sprintf("/orgs/%s/membership/%s", org, user), jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
}
|
25
vendor/github.com/gogits/go-gogs-client/org_team.go
generated
vendored
Normal file
25
vendor/github.com/gogits/go-gogs-client/org_team.go
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2016 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"
|
||||
|
||||
type Team struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Permission string `json:"permission"`
|
||||
}
|
||||
|
||||
type CreateTeamOption struct {
|
||||
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
|
||||
Description string `json:"description" binding:"MaxSize(255)"`
|
||||
Permission string `json:"permission"`
|
||||
}
|
||||
|
||||
func (c *Client) ListTeams(name string) ([]*Team, error) {
|
||||
teams := make([]*Team, 0, 5)
|
||||
return teams, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/teams", name), nil, nil, &teams)
|
||||
}
|
37
vendor/github.com/gogits/go-gogs-client/pull.go
generated
vendored
Normal file
37
vendor/github.com/gogits/go-gogs-client/pull.go
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright 2016 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 (
|
||||
"time"
|
||||
)
|
||||
|
||||
// PullRequest represents a pull reqesut API object.
|
||||
type PullRequest struct {
|
||||
// Copied from issue.go
|
||||
ID int64 `json:"id"`
|
||||
Index int64 `json:"number"`
|
||||
Poster *User `json:"user"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Labels []*Label `json:"labels"`
|
||||
Milestone *Milestone `json:"milestone"`
|
||||
Assignee *User `json:"assignee"`
|
||||
State StateType `json:"state"`
|
||||
Comments int `json:"comments"`
|
||||
|
||||
HeadBranch string `json:"head_branch"`
|
||||
HeadRepo *Repository `json:"head_repo"`
|
||||
BaseBranch string `json:"base_branch"`
|
||||
BaseRepo *Repository `json:"base_repo"`
|
||||
|
||||
HTMLURL string `json:"html_url"`
|
||||
|
||||
Mergeable *bool `json:"mergeable"`
|
||||
HasMerged bool `json:"merged"`
|
||||
Merged *time.Time `json:"merged_at"`
|
||||
MergedCommitID *string `json:"merge_commit_sha"`
|
||||
MergedBy *User `json:"merged_by"`
|
||||
}
|
22
vendor/github.com/gogits/go-gogs-client/release.go
generated
vendored
Normal file
22
vendor/github.com/gogits/go-gogs-client/release.go
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2017 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 (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Release represents a release API object.
|
||||
type Release struct {
|
||||
ID int64 `json:"id"`
|
||||
TagName string `json:"tag_name"`
|
||||
TargetCommitish string `json:"target_commitish"`
|
||||
Name string `json:"name"`
|
||||
Body string `json:"body"`
|
||||
Draft bool `json:"draft"`
|
||||
Prerelease bool `json:"prerelease"`
|
||||
Author *User `json:"author"`
|
||||
Created time.Time `json:"created_at"`
|
||||
}
|
90
vendor/github.com/gogits/go-gogs-client/repo.go
generated
vendored
90
vendor/github.com/gogits/go-gogs-client/repo.go
generated
vendored
@ -8,7 +8,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Permission represents a API permission.
|
||||
@ -20,15 +20,30 @@ type Permission struct {
|
||||
|
||||
// Repository represents a API repository.
|
||||
type Repository struct {
|
||||
Id int64 `json:"id"`
|
||||
Owner User `json:"owner"`
|
||||
ID int64 `json:"id"`
|
||||
Owner *User `json:"owner"`
|
||||
Name string `json:"name"`
|
||||
FullName string `json:"full_name"`
|
||||
Description string `json:"description"`
|
||||
Private bool `json:"private"`
|
||||
Unlisted bool `json:"unlisted"`
|
||||
Fork bool `json:"fork"`
|
||||
HtmlUrl string `json:"html_url"`
|
||||
CloneUrl string `json:"clone_url"`
|
||||
SshUrl string `json:"ssh_url"`
|
||||
Permissions Permission `json:"permissions"`
|
||||
Parent *Repository `json:"parent"`
|
||||
Empty bool `json:"empty"`
|
||||
Mirror bool `json:"mirror"`
|
||||
Size int64 `json:"size"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
SSHURL string `json:"ssh_url"`
|
||||
CloneURL string `json:"clone_url"`
|
||||
Website string `json:"website"`
|
||||
Stars int `json:"stars_count"`
|
||||
Forks int `json:"forks_count"`
|
||||
Watchers int `json:"watchers_count"`
|
||||
OpenIssues int `json:"open_issues_count"`
|
||||
DefaultBranch string `json:"default_branch"`
|
||||
Created time.Time `json:"created_at"`
|
||||
Updated time.Time `json:"updated_at"`
|
||||
Permissions *Permission `json:"permissions,omitempty"`
|
||||
}
|
||||
|
||||
// ListMyRepos lists all repositories for the authenticated user that has access to.
|
||||
@ -37,10 +52,21 @@ func (c *Client) ListMyRepos() ([]*Repository, error) {
|
||||
return repos, c.getParsedResponse("GET", "/user/repos", nil, nil, &repos)
|
||||
}
|
||||
|
||||
func (c *Client) ListUserRepos(user string) ([]*Repository, error) {
|
||||
repos := make([]*Repository, 0, 10)
|
||||
return repos, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/repos", user), nil, nil, &repos)
|
||||
}
|
||||
|
||||
func (c *Client) ListOrgRepos(org string) ([]*Repository, error) {
|
||||
repos := make([]*Repository, 0, 10)
|
||||
return repos, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/repos", org), nil, nil, &repos)
|
||||
}
|
||||
|
||||
type CreateRepoOption struct {
|
||||
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
|
||||
Description string `json:"description" binding:"MaxSize(255)"`
|
||||
Private bool `json:"private"`
|
||||
Unlisted bool `json:"unlisted"`
|
||||
AutoInit bool `json:"auto_init"`
|
||||
Gitignores string `json:"gitignores"`
|
||||
License string `json:"license"`
|
||||
@ -54,8 +80,7 @@ func (c *Client) CreateRepo(opt CreateRepoOption) (*Repository, error) {
|
||||
return nil, err
|
||||
}
|
||||
repo := new(Repository)
|
||||
return repo, c.getParsedResponse("POST", "/user/repos",
|
||||
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), repo)
|
||||
return repo, c.getParsedResponse("POST", "/user/repos", jsonHeader, bytes.NewReader(body), repo)
|
||||
}
|
||||
|
||||
// CreateOrgRepo creates an organization repository for authenticated user.
|
||||
@ -65,8 +90,7 @@ func (c *Client) CreateOrgRepo(org string, opt CreateRepoOption) (*Repository, e
|
||||
return nil, err
|
||||
}
|
||||
repo := new(Repository)
|
||||
return repo, c.getParsedResponse("POST", fmt.Sprintf("/org/%s/repos", org),
|
||||
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), repo)
|
||||
return repo, c.getParsedResponse("POST", fmt.Sprintf("/org/%s/repos", org), jsonHeader, bytes.NewReader(body), repo)
|
||||
}
|
||||
|
||||
// GetRepo returns information of a repository of given owner.
|
||||
@ -89,6 +113,7 @@ type MigrateRepoOption struct {
|
||||
RepoName string `json:"repo_name" binding:"Required"`
|
||||
Mirror bool `json:"mirror"`
|
||||
Private bool `json:"private"`
|
||||
Unlisted bool `json:"unlisted"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
@ -103,6 +128,45 @@ func (c *Client) MigrateRepo(opt MigrateRepoOption) (*Repository, error) {
|
||||
return nil, err
|
||||
}
|
||||
repo := new(Repository)
|
||||
return repo, c.getParsedResponse("POST", "/repos/migrate",
|
||||
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), repo)
|
||||
return repo, c.getParsedResponse("POST", "/repos/migrate", jsonHeader, bytes.NewReader(body), repo)
|
||||
}
|
||||
|
||||
type EditIssueTrackerOption struct {
|
||||
EnableIssues *bool `json:"enable_issues"`
|
||||
EnableExternalTracker *bool `json:"enable_external_tracker"`
|
||||
ExternalTrackerURL *string `json:"external_tracker_url"`
|
||||
TrackerURLFormat *string `json:"tracker_url_format"`
|
||||
TrackerIssueStyle *string `json:"tracker_issue_style"`
|
||||
}
|
||||
|
||||
// EditIssueTracker updates issue tracker options of the repository.
|
||||
func (c *Client) EditIssueTracker(owner, repo string, opt EditIssueTrackerOption) error {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.getResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issue-tracker", owner, repo), jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
}
|
||||
|
||||
type EditWikiOption struct {
|
||||
EnableWiki *bool `json:"enable_wiki"`
|
||||
AllowPublicWiki *bool `json:"allow_public_wiki"`
|
||||
EnableExternalWiki *bool `json:"enable_external_wiki"`
|
||||
ExternalWikiURL *string `json:"external_wiki_url"`
|
||||
}
|
||||
|
||||
// EditWiki updates wiki options of the repository.
|
||||
func (c *Client) EditWiki(owner, repo string, opt EditWikiOption) error {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.getResponse("PATCH", fmt.Sprintf("/repos/%s/%s/wiki", owner, repo), jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) MirrorSync(owner, repo string) error {
|
||||
_, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/mirror-sync", owner, repo), jsonHeader, nil)
|
||||
return err
|
||||
}
|
||||
|
44
vendor/github.com/gogits/go-gogs-client/repo_collaborator.go
generated
vendored
Normal file
44
vendor/github.com/gogits/go-gogs-client/repo_collaborator.go
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright 2016 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"
|
||||
)
|
||||
|
||||
type Collaborator struct {
|
||||
*User
|
||||
Permissions Permission `json:"permissions"`
|
||||
}
|
||||
|
||||
type AddCollaboratorOption struct {
|
||||
Permission *string `json:"permission"`
|
||||
}
|
||||
|
||||
func (c *Client) ListCollaborator(user, repo string) ([]*Collaborator, error) {
|
||||
collabs := make([]*Collaborator, 0, 10)
|
||||
return collabs, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/collaborators", user, repo), nil, nil, &collabs)
|
||||
}
|
||||
|
||||
func (c *Client) AddCollaborator(user, repo, collaborator string, opt AddCollaboratorOption) error {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.getResponse("PUT", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) DeleteCollaborator(user, repo, collaborator string) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) IsCollaborator(user, repo, collaborator string) error {
|
||||
_, err := c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, nil)
|
||||
return err
|
||||
}
|
53
vendor/github.com/gogits/go-gogs-client/repo_commit.go
generated
vendored
Normal file
53
vendor/github.com/gogits/go-gogs-client/repo_commit.go
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
// Copyright 2018 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"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// CommitMeta contains meta information of a commit in terms of API.
|
||||
type CommitMeta struct {
|
||||
URL string `json:"url"`
|
||||
SHA string `json:"sha"`
|
||||
}
|
||||
|
||||
// CommitUser contains information of a user in the context of a commit.
|
||||
type CommitUser struct {
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Date string `json:"date"`
|
||||
}
|
||||
|
||||
// RepoCommit contains information of a commit in the context of a repository.
|
||||
type RepoCommit struct {
|
||||
URL string `json:"url"`
|
||||
Author *CommitUser `json:"author"`
|
||||
Committer *CommitUser `json:"committer"`
|
||||
Message string `json:"message"`
|
||||
Tree *CommitMeta `json:"tree"`
|
||||
}
|
||||
|
||||
// Commit contains information generated from a Git commit.
|
||||
type Commit struct {
|
||||
*CommitMeta
|
||||
HTMLURL string `json:"html_url"`
|
||||
RepoCommit *RepoCommit `json:"commit"`
|
||||
Author *User `json:"author"`
|
||||
Committer *User `json:"committer"`
|
||||
Parents []*CommitMeta `json:"parents"`
|
||||
}
|
||||
|
||||
func (c *Client) GetSingleCommit(user, repo, commitID string) (*Commit, error) {
|
||||
commit := new(Commit)
|
||||
return commit, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s", user, repo, commitID), nil, nil, &commit)
|
||||
}
|
||||
|
||||
func (c *Client) GetReferenceSHA(user, repo, ref string) (string, error) {
|
||||
data, err := c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s", user, repo, ref),
|
||||
http.Header{"Accept": []string{MediaApplicationSHA}}, nil)
|
||||
return string(data), err
|
||||
}
|
8
vendor/github.com/gogits/go-gogs-client/repo_file.go
generated
vendored
8
vendor/github.com/gogits/go-gogs-client/repo_file.go
generated
vendored
@ -13,3 +13,11 @@ import (
|
||||
func (c *Client) GetFile(user, repo, ref, tree string) ([]byte, error) {
|
||||
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s/%s", user, repo, ref, tree), nil, nil)
|
||||
}
|
||||
|
||||
// GetArchive downloads the full contents of a repository. Ref can be a branch/tag/commit.
|
||||
func (c *Client) GetArchive(user, repo, ref, format string) ([]byte, error) {
|
||||
if format != ".zip" && format != ".tar.gz" {
|
||||
return nil, fmt.Errorf("invalid format: %s (must be .zip or .tar.gz)", format)
|
||||
}
|
||||
return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/archive/%s%s", user, repo, ref, format), nil, nil)
|
||||
}
|
||||
|
345
vendor/github.com/gogits/go-gogs-client/repo_hook.go
generated
vendored
Normal file
345
vendor/github.com/gogits/go-gogs-client/repo_hook.go
generated
vendored
Normal file
@ -0,0 +1,345 @@
|
||||
// Copyright 2014 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"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidReceiveHook = errors.New("invalid JSON payload received over webhook")
|
||||
)
|
||||
|
||||
type Hook struct {
|
||||
ID int64 `json:"id"`
|
||||
Type string `json:"type"`
|
||||
URL string `json:"-"`
|
||||
Config map[string]string `json:"config"`
|
||||
Events []string `json:"events"`
|
||||
Active bool `json:"active"`
|
||||
Updated time.Time `json:"updated_at"`
|
||||
Created time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (c *Client) ListRepoHooks(user, repo string) ([]*Hook, error) {
|
||||
hooks := make([]*Hook, 0, 10)
|
||||
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), nil, nil, &hooks)
|
||||
}
|
||||
|
||||
type CreateHookOption struct {
|
||||
Type string `json:"type" binding:"Required"`
|
||||
Config map[string]string `json:"config" binding:"Required"`
|
||||
Events []string `json:"events"`
|
||||
Active bool `json:"active"`
|
||||
}
|
||||
|
||||
func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
h := new(Hook)
|
||||
return h, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), jsonHeader, bytes.NewReader(body), h)
|
||||
}
|
||||
|
||||
type EditHookOption struct {
|
||||
Config map[string]string `json:"config"`
|
||||
Events []string `json:"events"`
|
||||
Active *bool `json:"active"`
|
||||
}
|
||||
|
||||
func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) error {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.getResponse("PATCH", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) DeleteRepoHook(user, repo string, id int64) error {
|
||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), nil, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
type Payloader interface {
|
||||
JSONPayload() ([]byte, error)
|
||||
}
|
||||
|
||||
type PayloadUser struct {
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
UserName string `json:"username"`
|
||||
}
|
||||
|
||||
// FIXME: consider use same format as API when commits API are added.
|
||||
type PayloadCommit struct {
|
||||
ID string `json:"id"`
|
||||
Message string `json:"message"`
|
||||
URL string `json:"url"`
|
||||
Author *PayloadUser `json:"author"`
|
||||
Committer *PayloadUser `json:"committer"`
|
||||
|
||||
Added []string `json:"added"`
|
||||
Removed []string `json:"removed"`
|
||||
Modified []string `json:"modified"`
|
||||
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
}
|
||||
|
||||
var (
|
||||
_ Payloader = &CreatePayload{}
|
||||
_ Payloader = &DeletePayload{}
|
||||
_ Payloader = &ForkPayload{}
|
||||
_ Payloader = &PushPayload{}
|
||||
_ Payloader = &IssuesPayload{}
|
||||
_ Payloader = &IssueCommentPayload{}
|
||||
_ Payloader = &PullRequestPayload{}
|
||||
)
|
||||
|
||||
// _________ __
|
||||
// \_ ___ \_______ ____ _____ _/ |_ ____
|
||||
// / \ \/\_ __ \_/ __ \\__ \\ __\/ __ \
|
||||
// \ \____| | \/\ ___/ / __ \| | \ ___/
|
||||
// \______ /|__| \___ >____ /__| \___ >
|
||||
// \/ \/ \/ \/
|
||||
|
||||
type CreatePayload struct {
|
||||
Ref string `json:"ref"`
|
||||
RefType string `json:"ref_type"`
|
||||
Sha string `json:"sha"`
|
||||
DefaultBranch string `json:"default_branch"`
|
||||
Repo *Repository `json:"repository"`
|
||||
Sender *User `json:"sender"`
|
||||
}
|
||||
|
||||
func (p *CreatePayload) JSONPayload() ([]byte, error) {
|
||||
return json.MarshalIndent(p, "", " ")
|
||||
}
|
||||
|
||||
// ParseCreateHook parses create event hook content.
|
||||
func ParseCreateHook(raw []byte) (*CreatePayload, error) {
|
||||
hook := new(CreatePayload)
|
||||
if err := json.Unmarshal(raw, hook); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// it is possible the JSON was parsed, however,
|
||||
// was not from Gogs (maybe was from Bitbucket)
|
||||
// So we'll check to be sure certain key fields
|
||||
// were populated
|
||||
switch {
|
||||
case hook.Repo == nil:
|
||||
return nil, ErrInvalidReceiveHook
|
||||
case len(hook.Ref) == 0:
|
||||
return nil, ErrInvalidReceiveHook
|
||||
}
|
||||
return hook, nil
|
||||
}
|
||||
|
||||
// ________ .__ __
|
||||
// \______ \ ____ | | _____/ |_ ____
|
||||
// | | \_/ __ \| | _/ __ \ __\/ __ \
|
||||
// | ` \ ___/| |_\ ___/| | \ ___/
|
||||
// /_______ /\___ >____/\___ >__| \___ >
|
||||
// \/ \/ \/ \/
|
||||
|
||||
type PusherType string
|
||||
|
||||
const (
|
||||
PUSHER_TYPE_USER PusherType = "user"
|
||||
)
|
||||
|
||||
type DeletePayload struct {
|
||||
Ref string `json:"ref"`
|
||||
RefType string `json:"ref_type"`
|
||||
PusherType PusherType `json:"pusher_type"`
|
||||
Repo *Repository `json:"repository"`
|
||||
Sender *User `json:"sender"`
|
||||
}
|
||||
|
||||
func (p *DeletePayload) JSONPayload() ([]byte, error) {
|
||||
return json.MarshalIndent(p, "", " ")
|
||||
}
|
||||
|
||||
// ___________ __
|
||||
// \_ _____/__________| | __
|
||||
// | __)/ _ \_ __ \ |/ /
|
||||
// | \( <_> ) | \/ <
|
||||
// \___ / \____/|__| |__|_ \
|
||||
// \/ \/
|
||||
|
||||
type ForkPayload struct {
|
||||
Forkee *Repository `json:"forkee"`
|
||||
Repo *Repository `json:"repository"`
|
||||
Sender *User `json:"sender"`
|
||||
}
|
||||
|
||||
func (p *ForkPayload) JSONPayload() ([]byte, error) {
|
||||
return json.MarshalIndent(p, "", " ")
|
||||
}
|
||||
|
||||
// __________ .__
|
||||
// \______ \__ __ _____| |__
|
||||
// | ___/ | \/ ___/ | \
|
||||
// | | | | /\___ \| Y \
|
||||
// |____| |____//____ >___| /
|
||||
// \/ \/
|
||||
|
||||
// PushPayload represents a payload information of push event.
|
||||
type PushPayload struct {
|
||||
Ref string `json:"ref"`
|
||||
Before string `json:"before"`
|
||||
After string `json:"after"`
|
||||
CompareURL string `json:"compare_url"`
|
||||
Commits []*PayloadCommit `json:"commits"`
|
||||
Repo *Repository `json:"repository"`
|
||||
Pusher *User `json:"pusher"`
|
||||
Sender *User `json:"sender"`
|
||||
}
|
||||
|
||||
func (p *PushPayload) JSONPayload() ([]byte, error) {
|
||||
return json.MarshalIndent(p, "", " ")
|
||||
}
|
||||
|
||||
// ParsePushHook parses push event hook content.
|
||||
func ParsePushHook(raw []byte) (*PushPayload, error) {
|
||||
hook := new(PushPayload)
|
||||
if err := json.Unmarshal(raw, hook); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch {
|
||||
case hook.Repo == nil:
|
||||
return nil, ErrInvalidReceiveHook
|
||||
case len(hook.Ref) == 0:
|
||||
return nil, ErrInvalidReceiveHook
|
||||
}
|
||||
return hook, nil
|
||||
}
|
||||
|
||||
// Branch returns branch name from a payload
|
||||
func (p *PushPayload) Branch() string {
|
||||
return strings.Replace(p.Ref, "refs/heads/", "", -1)
|
||||
}
|
||||
|
||||
// .___
|
||||
// | | ______ ________ __ ____
|
||||
// | |/ ___// ___/ | \_/ __ \
|
||||
// | |\___ \ \___ \| | /\ ___/
|
||||
// |___/____ >____ >____/ \___ >
|
||||
// \/ \/ \/
|
||||
|
||||
type HookIssueAction string
|
||||
|
||||
const (
|
||||
HOOK_ISSUE_OPENED HookIssueAction = "opened"
|
||||
HOOK_ISSUE_CLOSED HookIssueAction = "closed"
|
||||
HOOK_ISSUE_REOPENED HookIssueAction = "reopened"
|
||||
HOOK_ISSUE_EDITED HookIssueAction = "edited"
|
||||
HOOK_ISSUE_ASSIGNED HookIssueAction = "assigned"
|
||||
HOOK_ISSUE_UNASSIGNED HookIssueAction = "unassigned"
|
||||
HOOK_ISSUE_LABEL_UPDATED HookIssueAction = "label_updated"
|
||||
HOOK_ISSUE_LABEL_CLEARED HookIssueAction = "label_cleared"
|
||||
HOOK_ISSUE_MILESTONED HookIssueAction = "milestoned"
|
||||
HOOK_ISSUE_DEMILESTONED HookIssueAction = "demilestoned"
|
||||
HOOK_ISSUE_SYNCHRONIZED HookIssueAction = "synchronized"
|
||||
)
|
||||
|
||||
type ChangesFromPayload struct {
|
||||
From string `json:"from"`
|
||||
}
|
||||
|
||||
type ChangesPayload struct {
|
||||
Title *ChangesFromPayload `json:"title,omitempty"`
|
||||
Body *ChangesFromPayload `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// IssuesPayload represents a payload information of issues event.
|
||||
type IssuesPayload struct {
|
||||
Action HookIssueAction `json:"action"`
|
||||
Index int64 `json:"number"`
|
||||
Issue *Issue `json:"issue"`
|
||||
Changes *ChangesPayload `json:"changes,omitempty"`
|
||||
Repository *Repository `json:"repository"`
|
||||
Sender *User `json:"sender"`
|
||||
}
|
||||
|
||||
func (p *IssuesPayload) JSONPayload() ([]byte, error) {
|
||||
return json.MarshalIndent(p, "", " ")
|
||||
}
|
||||
|
||||
type HookIssueCommentAction string
|
||||
|
||||
const (
|
||||
HOOK_ISSUE_COMMENT_CREATED HookIssueCommentAction = "created"
|
||||
HOOK_ISSUE_COMMENT_EDITED HookIssueCommentAction = "edited"
|
||||
HOOK_ISSUE_COMMENT_DELETED HookIssueCommentAction = "deleted"
|
||||
)
|
||||
|
||||
// IssueCommentPayload represents a payload information of issue comment event.
|
||||
type IssueCommentPayload struct {
|
||||
Action HookIssueCommentAction `json:"action"`
|
||||
Issue *Issue `json:"issue"`
|
||||
Comment *Comment `json:"comment"`
|
||||
Changes *ChangesPayload `json:"changes,omitempty"`
|
||||
Repository *Repository `json:"repository"`
|
||||
Sender *User `json:"sender"`
|
||||
}
|
||||
|
||||
func (p *IssueCommentPayload) JSONPayload() ([]byte, error) {
|
||||
return json.MarshalIndent(p, "", " ")
|
||||
}
|
||||
|
||||
// __________ .__ .__ __________ __
|
||||
// \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
|
||||
// | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
|
||||
// | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | |
|
||||
// |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__|
|
||||
// \/ \/ |__| \/ \/
|
||||
|
||||
// PullRequestPayload represents a payload information of pull request event.
|
||||
type PullRequestPayload struct {
|
||||
Action HookIssueAction `json:"action"`
|
||||
Index int64 `json:"number"`
|
||||
PullRequest *PullRequest `json:"pull_request"`
|
||||
Changes *ChangesPayload `json:"changes,omitempty"`
|
||||
Repository *Repository `json:"repository"`
|
||||
Sender *User `json:"sender"`
|
||||
}
|
||||
|
||||
func (p *PullRequestPayload) JSONPayload() ([]byte, error) {
|
||||
return json.MarshalIndent(p, "", " ")
|
||||
}
|
||||
|
||||
// __________ .__
|
||||
// \______ \ ____ | | ____ _____ ______ ____
|
||||
// | _// __ \| | _/ __ \\__ \ / ___// __ \
|
||||
// | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
|
||||
// |____|_ /\___ >____/\___ >____ /____ >\___ >
|
||||
// \/ \/ \/ \/ \/ \/
|
||||
|
||||
type HookReleaseAction string
|
||||
|
||||
const (
|
||||
HOOK_RELEASE_PUBLISHED HookReleaseAction = "published"
|
||||
)
|
||||
|
||||
// ReleasePayload represents a payload information of release event.
|
||||
type ReleasePayload struct {
|
||||
Action HookReleaseAction `json:"action"`
|
||||
Release *Release `json:"release"`
|
||||
Repository *Repository `json:"repository"`
|
||||
Sender *User `json:"sender"`
|
||||
}
|
||||
|
||||
func (p *ReleasePayload) JSONPayload() ([]byte, error) {
|
||||
return json.MarshalIndent(p, "", " ")
|
||||
}
|
206
vendor/github.com/gogits/go-gogs-client/repo_hooks.go
generated
vendored
206
vendor/github.com/gogits/go-gogs-client/repo_hooks.go
generated
vendored
@ -1,206 +0,0 @@
|
||||
// Copyright 2014 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"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidReceiveHook = errors.New("Invalid JSON payload received over webhook")
|
||||
)
|
||||
|
||||
type Hook struct {
|
||||
ID int64 `json:"id"`
|
||||
Type string `json:"type"`
|
||||
URL string `json:"-"`
|
||||
Config map[string]string `json:"config"`
|
||||
Events []string `json:"events"`
|
||||
Active bool `json:"active"`
|
||||
Updated time.Time `json:"updated_at"`
|
||||
Created time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (c *Client) ListRepoHooks(user, repo string) ([]*Hook, error) {
|
||||
hooks := make([]*Hook, 0, 10)
|
||||
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), nil, nil, &hooks)
|
||||
}
|
||||
|
||||
type CreateHookOption struct {
|
||||
Type string `json:"type" binding:"Required"`
|
||||
Config map[string]string `json:"config" binding:"Required"`
|
||||
Events []string `json:"events"`
|
||||
Active bool `json:"active"`
|
||||
}
|
||||
|
||||
func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, error) {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
h := new(Hook)
|
||||
return h, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/hooks", user, repo),
|
||||
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), h)
|
||||
}
|
||||
|
||||
type EditHookOption struct {
|
||||
Config map[string]string `json:"config"`
|
||||
Events []string `json:"events"`
|
||||
Active *bool `json:"active"`
|
||||
}
|
||||
|
||||
func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) error {
|
||||
body, err := json.Marshal(&opt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.getResponse("PATCH", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id),
|
||||
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body))
|
||||
return err
|
||||
}
|
||||
|
||||
type Payloader interface {
|
||||
SetSecret(string)
|
||||
JSONPayload() ([]byte, error)
|
||||
}
|
||||
|
||||
type PayloadAuthor struct {
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
UserName string `json:"username"`
|
||||
}
|
||||
|
||||
type PayloadUser struct {
|
||||
UserName string `json:"login"`
|
||||
ID int64 `json:"id"`
|
||||
AvatarUrl string `json:"avatar_url"`
|
||||
}
|
||||
|
||||
type PayloadCommit struct {
|
||||
ID string `json:"id"`
|
||||
Message string `json:"message"`
|
||||
URL string `json:"url"`
|
||||
Author *PayloadAuthor `json:"author"`
|
||||
}
|
||||
|
||||
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"`
|
||||
Owner *PayloadAuthor `json:"owner"`
|
||||
Private bool `json:"private"`
|
||||
DefaultBranch string `json:"default_branch"`
|
||||
}
|
||||
|
||||
// _________ __
|
||||
// \_ ___ \_______ ____ _____ _/ |_ ____
|
||||
// / \ \/\_ __ \_/ __ \\__ \\ __\/ __ \
|
||||
// \ \____| | \/\ ___/ / __ \| | \ ___/
|
||||
// \______ /|__| \___ >____ /__| \___ >
|
||||
// \/ \/ \/ \/
|
||||
|
||||
type CreatePayload struct {
|
||||
Secret string `json:"secret"`
|
||||
Ref string `json:"ref"`
|
||||
RefType string `json:"ref_type"`
|
||||
Repo *PayloadRepo `json:"repository"`
|
||||
Sender *PayloadUser `json:"sender"`
|
||||
}
|
||||
|
||||
func (p *CreatePayload) SetSecret(secret string) {
|
||||
p.Secret = secret
|
||||
}
|
||||
|
||||
func (p *CreatePayload) JSONPayload() ([]byte, error) {
|
||||
data, err := json.MarshalIndent(p, "", " ")
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// ParseCreateHook parses create event hook content.
|
||||
func ParseCreateHook(raw []byte) (*CreatePayload, error) {
|
||||
hook := new(CreatePayload)
|
||||
if err := json.Unmarshal(raw, hook); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// it is possible the JSON was parsed, however,
|
||||
// was not from Gogs (maybe was from Bitbucket)
|
||||
// So we'll check to be sure certain key fields
|
||||
// were populated
|
||||
switch {
|
||||
case hook.Repo == nil:
|
||||
return nil, ErrInvalidReceiveHook
|
||||
case len(hook.Ref) == 0:
|
||||
return nil, ErrInvalidReceiveHook
|
||||
}
|
||||
return hook, nil
|
||||
}
|
||||
|
||||
// __________ .__
|
||||
// \______ \__ __ _____| |__
|
||||
// | ___/ | \/ ___/ | \
|
||||
// | | | | /\___ \| Y \
|
||||
// |____| |____//____ >___| /
|
||||
// \/ \/
|
||||
|
||||
// PushPayload represents a payload information of push event.
|
||||
type PushPayload struct {
|
||||
Secret string `json:"secret"`
|
||||
Ref string `json:"ref"`
|
||||
Before string `json:"before"`
|
||||
After string `json:"after"`
|
||||
CompareUrl string `json:"compare_url"`
|
||||
Commits []*PayloadCommit `json:"commits"`
|
||||
Repo *PayloadRepo `json:"repository"`
|
||||
Pusher *PayloadAuthor `json:"pusher"`
|
||||
Sender *PayloadUser `json:"sender"`
|
||||
}
|
||||
|
||||
func (p *PushPayload) SetSecret(secret string) {
|
||||
p.Secret = secret
|
||||
}
|
||||
|
||||
func (p *PushPayload) JSONPayload() ([]byte, error) {
|
||||
data, err := json.MarshalIndent(p, "", " ")
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// ParsePushHook parses push event hook content.
|
||||
func ParsePushHook(raw []byte) (*PushPayload, error) {
|
||||
hook := new(PushPayload)
|
||||
if err := json.Unmarshal(raw, hook); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch {
|
||||
case hook.Repo == nil:
|
||||
return nil, ErrInvalidReceiveHook
|
||||
case len(hook.Ref) == 0:
|
||||
return nil, ErrInvalidReceiveHook
|
||||
}
|
||||
return hook, nil
|
||||
}
|
||||
|
||||
// Branch returns branch name from a payload
|
||||
func (p *PushPayload) Branch() string {
|
||||
return strings.Replace(p.Ref, "refs/heads/", "", -1)
|
||||
}
|
@ -8,7 +8,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -42,8 +41,7 @@ func (c *Client) CreateDeployKey(user, repo string, opt CreateKeyOption) (*Deplo
|
||||
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)
|
||||
return key, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/keys", user, repo), jsonHeader, bytes.NewReader(body), key)
|
||||
}
|
||||
|
||||
func (c *Client) DeleteDeployKey(owner, repo string, keyID int64) error {
|
9
vendor/github.com/gogits/go-gogs-client/user.go
generated
vendored
9
vendor/github.com/gogits/go-gogs-client/user.go
generated
vendored
@ -11,7 +11,8 @@ import (
|
||||
// User represents a API user.
|
||||
type User struct {
|
||||
ID int64 `json:"id"`
|
||||
UserName string `json:"username"`
|
||||
UserName string `json:"username"` // LEGACY [Gogs 1.0]: remove field(s) for backward compatibility
|
||||
Login string `json:"login"`
|
||||
FullName string `json:"full_name"`
|
||||
Email string `json:"email"`
|
||||
AvatarUrl string `json:"avatar_url"`
|
||||
@ -22,3 +23,9 @@ func (c *Client) GetUserInfo(user string) (*User, error) {
|
||||
err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)
|
||||
return u, err
|
||||
}
|
||||
|
||||
func (c *Client) GetSelfInfo() (*User, error) {
|
||||
u := new(User)
|
||||
err := c.getParsedResponse("GET", "/user", nil, nil, u)
|
||||
return u, err
|
||||
}
|
||||
|
7
vendor/github.com/gogits/go-gogs-client/user_email.go
generated
vendored
7
vendor/github.com/gogits/go-gogs-client/user_email.go
generated
vendored
@ -7,7 +7,6 @@ package gogs
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Email struct {
|
||||
@ -31,8 +30,7 @@ func (c *Client) AddEmail(opt CreateEmailOption) ([]*Email, error) {
|
||||
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)
|
||||
return emails, c.getParsedResponse("POST", "/user/emails", jsonHeader, bytes.NewReader(body), emails)
|
||||
}
|
||||
|
||||
func (c *Client) DeleteEmail(opt CreateEmailOption) error {
|
||||
@ -40,7 +38,6 @@ func (c *Client) DeleteEmail(opt CreateEmailOption) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = c.getResponse("DELETE", "/user/emails",
|
||||
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body))
|
||||
_, err = c.getResponse("DELETE", "/user/emails", jsonHeader, bytes.NewReader(body))
|
||||
return err
|
||||
}
|
||||
|
2
vendor/github.com/gogits/go-gogs-client/user_follow.go
generated
vendored
2
vendor/github.com/gogits/go-gogs-client/user_follow.go
generated
vendored
@ -37,7 +37,7 @@ func (c *Client) IsUserFollowing(user, target string) bool {
|
||||
}
|
||||
|
||||
func (c *Client) Follow(target string) error {
|
||||
_, err := c.getResponse("PUT", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
||||
_, err := c.getResponse("PUT", fmt.Sprintf("/user/following/%s", target), jsonHeader, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -25,9 +24,9 @@ func (c *Client) ListPublicKeys(user string) ([]*PublicKey, error) {
|
||||
return keys, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/keys", user), nil, nil, &keys)
|
||||
}
|
||||
|
||||
func (c *Client) ListMyPublicKeys(user string) ([]*PublicKey, error) {
|
||||
func (c *Client) ListMyPublicKeys() ([]*PublicKey, error) {
|
||||
keys := make([]*PublicKey, 0, 10)
|
||||
return keys, c.getParsedResponse("GET", fmt.Sprintf("/user/keys", user), nil, nil, &keys)
|
||||
return keys, c.getParsedResponse("GET", "/user/keys", nil, nil, &keys)
|
||||
}
|
||||
|
||||
func (c *Client) GetPublicKey(keyID int64) (*PublicKey, error) {
|
||||
@ -41,8 +40,7 @@ func (c *Client) CreatePublicKey(opt CreateKeyOption) (*PublicKey, error) {
|
||||
return nil, err
|
||||
}
|
||||
key := new(PublicKey)
|
||||
return key, c.getParsedResponse("POST", "/user/keys",
|
||||
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), key)
|
||||
return key, c.getParsedResponse("POST", "/user/keys", jsonHeader, bytes.NewReader(body), key)
|
||||
}
|
||||
|
||||
func (c *Client) DeletePublicKey(keyID int64) error {
|
14
vendor/github.com/gogits/go-gogs-client/utils.go
generated
vendored
14
vendor/github.com/gogits/go-gogs-client/utils.go
generated
vendored
@ -4,6 +4,20 @@
|
||||
|
||||
package gogs
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var jsonHeader = http.Header{"content-type": []string{"application/json"}}
|
||||
|
||||
func Bool(v bool) *bool {
|
||||
return &v
|
||||
}
|
||||
|
||||
func String(v string) *string {
|
||||
return &v
|
||||
}
|
||||
|
||||
func Int64(v int64) *int64 {
|
||||
return &v
|
||||
}
|
||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -109,7 +109,7 @@ github.com/go-playground/validator/v10
|
||||
# github.com/go-sql-driver/mysql v1.6.0
|
||||
## explicit
|
||||
github.com/go-sql-driver/mysql
|
||||
# github.com/gogits/go-gogs-client v0.0.0-20160212212711-d584b1e0fb4d
|
||||
# github.com/gogits/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85
|
||||
## explicit
|
||||
github.com/gogits/go-gogs-client
|
||||
# github.com/gogo/protobuf v1.3.2
|
||||
|
Loading…
Reference in New Issue
Block a user