mirror of
https://github.com/thegeeklab/wp-gitea-release.git
synced 2024-11-25 09:20:39 +00:00
Add missing dependencies
Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
parent
ca3dee7248
commit
88dc55b2e7
20
vendor/code.gitea.io/sdk/LICENSE
generated
vendored
Normal file
20
vendor/code.gitea.io/sdk/LICENSE
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
Copyright (c) 2016 The Gitea Authors
|
||||||
|
Copyright (c) 2014 The Gogs Authors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
22
vendor/code.gitea.io/sdk/gitea/admin_org.go
generated
vendored
Normal file
22
vendor/code.gitea.io/sdk/gitea/admin_org.go
generated
vendored
Normal file
@ -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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AdminCreateOrg create an organization
|
||||||
|
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)
|
||||||
|
}
|
22
vendor/code.gitea.io/sdk/gitea/admin_repo.go
generated
vendored
Normal file
22
vendor/code.gitea.io/sdk/gitea/admin_repo.go
generated
vendored
Normal file
@ -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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AdminCreateRepo create a repo
|
||||||
|
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),
|
||||||
|
jsonHeader, bytes.NewReader(body), repo)
|
||||||
|
}
|
80
vendor/code.gitea.io/sdk/gitea/admin_user.go
generated
vendored
Normal file
80
vendor/code.gitea.io/sdk/gitea/admin_user.go
generated
vendored
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CreateUserOption create user options
|
||||||
|
type CreateUserOption struct {
|
||||||
|
SourceID int64 `json:"source_id"`
|
||||||
|
LoginName string `json:"login_name"`
|
||||||
|
// required: true
|
||||||
|
Username string `json:"username" binding:"Required;AlphaDashDot;MaxSize(35)"`
|
||||||
|
FullName string `json:"full_name" binding:"MaxSize(100)"`
|
||||||
|
// required: true
|
||||||
|
// swagger:strfmt email
|
||||||
|
Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
|
||||||
|
// required: true
|
||||||
|
Password string `json:"password" binding:"Required;MaxSize(255)"`
|
||||||
|
SendNotify bool `json:"send_notify"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminCreateUser create a user
|
||||||
|
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", jsonHeader, bytes.NewReader(body), user)
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditUserOption edit user options
|
||||||
|
type EditUserOption struct {
|
||||||
|
SourceID int64 `json:"source_id"`
|
||||||
|
LoginName string `json:"login_name"`
|
||||||
|
FullName string `json:"full_name" binding:"MaxSize(100)"`
|
||||||
|
// required: true
|
||||||
|
// swagger:strfmt email
|
||||||
|
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"`
|
||||||
|
MaxRepoCreation *int `json:"max_repo_creation"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminEditUser modify user informations
|
||||||
|
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), jsonHeader, bytes.NewReader(body))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminDeleteUser delete one user according name
|
||||||
|
func (c *Client) AdminDeleteUser(user string) error {
|
||||||
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s", user), nil, nil)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminCreateUserPublicKey create one user with options
|
||||||
|
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), jsonHeader, bytes.NewReader(body), key)
|
||||||
|
}
|
92
vendor/code.gitea.io/sdk/gitea/attachment.go
generated
vendored
Normal file
92
vendor/code.gitea.io/sdk/gitea/attachment.go
generated
vendored
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
// Copyright 2017 The Gitea 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 gitea // import "code.gitea.io/sdk/gitea"
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Attachment a generic attachment
|
||||||
|
// swagger:model
|
||||||
|
type Attachment struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
DownloadCount int64 `json:"download_count"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
UUID string `json:"uuid"`
|
||||||
|
DownloadURL string `json:"browser_download_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListReleaseAttachments list release's attachments
|
||||||
|
func (c *Client) ListReleaseAttachments(user, repo string, release int64) ([]*Attachment, error) {
|
||||||
|
attachments := make([]*Attachment, 0, 10)
|
||||||
|
err := c.getParsedResponse("GET",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/releases/%d/assets", user, repo, release),
|
||||||
|
nil, nil, &attachments)
|
||||||
|
return attachments, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListReleaseAttachments list release's attachments
|
||||||
|
func (c *Client) GetReleaseAttachment(user, repo string, release int64, id int64) (*Attachment, error) {
|
||||||
|
a := new(Attachment)
|
||||||
|
err := c.getParsedResponse("GET",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, id),
|
||||||
|
nil, nil, &a)
|
||||||
|
return a, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateReleaseAttachment creates an attachment for the given release
|
||||||
|
func (c *Client) CreateReleaseAttachment(user, repo string, release int64, file io.Reader, filename string) (*Attachment, error) {
|
||||||
|
// Write file to body
|
||||||
|
body := new(bytes.Buffer)
|
||||||
|
writer := multipart.NewWriter(body)
|
||||||
|
part, err := writer.CreateFormFile("attachment", filename)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = io.Copy(part, file); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err = writer.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send request
|
||||||
|
attachment := new(Attachment)
|
||||||
|
err = c.getParsedResponse("POST",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/releases/%d/assets", user, repo, release),
|
||||||
|
http.Header{"Content-Type": {writer.FormDataContentType()}}, body, &attachment)
|
||||||
|
return attachment, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditReleaseAttachment updates the given attachment with the given options
|
||||||
|
func (c *Client) EditReleaseAttachment(user, repo string, release int64, attachment int64, form EditAttachmentOptions) (*Attachment, error) {
|
||||||
|
body, err := json.Marshal(&form)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
attach := new(Attachment)
|
||||||
|
return attach, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, attachment), jsonHeader, bytes.NewReader(body), attach)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteReleaseAttachment deletes the given attachment including the uploaded file
|
||||||
|
func (c *Client) DeleteReleaseAttachment(user, repo string, release int64, id int64) error {
|
||||||
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, id), nil, nil)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditAttachmentOptions options for editing attachments
|
||||||
|
// swagger:model
|
||||||
|
type EditAttachmentOptions struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
5
vendor/code.gitea.io/sdk/gitea/doc.go
generated
vendored
Normal file
5
vendor/code.gitea.io/sdk/gitea/doc.go
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// Copyright 2016 The Gitea 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 gitea // import "code.gitea.io/sdk/gitea"
|
39
vendor/code.gitea.io/sdk/gitea/fork.go
generated
vendored
Normal file
39
vendor/code.gitea.io/sdk/gitea/fork.go
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// Copyright 2016 The Gitea 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ListForks list a repository's forks
|
||||||
|
func (c *Client) ListForks(user, repo string) ([]*Repository, error) {
|
||||||
|
forks := make([]*Repository, 10)
|
||||||
|
err := c.getParsedResponse("GET",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/forks", user, repo),
|
||||||
|
nil, nil, &forks)
|
||||||
|
return forks, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateForkOption options for creating a fork
|
||||||
|
type CreateForkOption struct {
|
||||||
|
// organization name, if forking into an organization
|
||||||
|
Organization *string `json:"organization"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFork create a fork of a repository
|
||||||
|
func (c *Client) CreateFork(user, repo string, form CreateForkOption) (*Repository, error) {
|
||||||
|
body, err := json.Marshal(form)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fork := new(Repository)
|
||||||
|
err = c.getParsedResponse("POST",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/forks", user, repo),
|
||||||
|
jsonHeader, bytes.NewReader(body), &fork)
|
||||||
|
return fork, err
|
||||||
|
}
|
104
vendor/code.gitea.io/sdk/gitea/gitea.go
generated
vendored
Normal file
104
vendor/code.gitea.io/sdk/gitea/gitea.go
generated
vendored
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Version return the library version
|
||||||
|
func Version() string {
|
||||||
|
return "0.12.3"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client represents a Gogs API client.
|
||||||
|
type Client struct {
|
||||||
|
url string
|
||||||
|
accessToken string
|
||||||
|
client *http.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient initializes and returns a API client.
|
||||||
|
func NewClient(url, token string) *Client {
|
||||||
|
return &Client{
|
||||||
|
url: strings.TrimSuffix(url, "/"),
|
||||||
|
accessToken: token,
|
||||||
|
client: &http.Client{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetHTTPClient replaces default http.Client with user given one.
|
||||||
|
func (c *Client) SetHTTPClient(client *http.Client) {
|
||||||
|
c.client = client
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
req.Header.Set("Authorization", "token "+c.accessToken)
|
||||||
|
for k, v := range header {
|
||||||
|
req.Header[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
data, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch resp.StatusCode {
|
||||||
|
case 403:
|
||||||
|
return nil, errors.New("403 Forbidden")
|
||||||
|
case 404:
|
||||||
|
return nil, errors.New("404 Not Found")
|
||||||
|
case 422:
|
||||||
|
return nil, fmt.Errorf("422 Unprocessable Entity: %s", string(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode/100 != 2 {
|
||||||
|
errMap := make(map[string]interface{})
|
||||||
|
if err = json.Unmarshal(data, &errMap); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return nil, errors.New(errMap["message"].(string))
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) getParsedResponse(method, path string, header http.Header, body io.Reader, obj interface{}) error {
|
||||||
|
data, err := c.getResponse(method, path, header, body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return json.Unmarshal(data, obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) getStatusCode(method, path string, header http.Header, body io.Reader) (int, error) {
|
||||||
|
resp, err := c.doRequest(method, path, header, body)
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
return resp.StatusCode, nil
|
||||||
|
}
|
407
vendor/code.gitea.io/sdk/gitea/hook.go
generated
vendored
Normal file
407
vendor/code.gitea.io/sdk/gitea/hook.go
generated
vendored
Normal file
@ -0,0 +1,407 @@
|
|||||||
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||||
|
// Copyright 2017 The Gitea 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ErrInvalidReceiveHook FIXME
|
||||||
|
ErrInvalidReceiveHook = errors.New("Invalid JSON payload received over webhook")
|
||||||
|
)
|
||||||
|
|
||||||
|
// Hook a hook is a web hook when one repository changed
|
||||||
|
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"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Updated time.Time `json:"updated_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// HookList represents a list of API hook.
|
||||||
|
type HookList []*Hook
|
||||||
|
|
||||||
|
// ListOrgHooks list all the hooks of one organization
|
||||||
|
func (c *Client) ListOrgHooks(org string) (HookList, error) {
|
||||||
|
hooks := make([]*Hook, 0, 10)
|
||||||
|
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/hooks", org), nil, nil, &hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepoHooks list all the hooks of one repository
|
||||||
|
func (c *Client) ListRepoHooks(user, repo string) (HookList, error) {
|
||||||
|
hooks := make([]*Hook, 0, 10)
|
||||||
|
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), nil, nil, &hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetOrgHook get a hook of an organization
|
||||||
|
func (c *Client) GetOrgHook(org string, id int64) (*Hook, error) {
|
||||||
|
h := new(Hook)
|
||||||
|
return h, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/hooks/%d", org, id), nil, nil, h)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRepoHook get a hook of a repository
|
||||||
|
func (c *Client) GetRepoHook(user, repo string, id int64) (*Hook, error) {
|
||||||
|
h := new(Hook)
|
||||||
|
return h, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), nil, nil, h)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateHookOption options when create a hook
|
||||||
|
type CreateHookOption struct {
|
||||||
|
// required: true
|
||||||
|
// enum: gitea,gogs,slack,discord
|
||||||
|
Type string `json:"type" binding:"Required"`
|
||||||
|
// required: true
|
||||||
|
Config map[string]string `json:"config" binding:"Required"`
|
||||||
|
Events []string `json:"events"`
|
||||||
|
// default: false
|
||||||
|
Active bool `json:"active"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateOrgHook create one hook for an organization, with options
|
||||||
|
func (c *Client) CreateOrgHook(org 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("/orgs/%s/hooks", org), jsonHeader, bytes.NewReader(body), h)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateRepoHook create one hook for a repository, with options
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditHookOption options when modify one hook
|
||||||
|
type EditHookOption struct {
|
||||||
|
Config map[string]string `json:"config"`
|
||||||
|
Events []string `json:"events"`
|
||||||
|
Active *bool `json:"active"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditOrgHook modify one hook of an organization, with hook id and options
|
||||||
|
func (c *Client) EditOrgHook(org string, id int64, opt EditHookOption) error {
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = c.getResponse("PATCH", fmt.Sprintf("/orgs/%s/hooks/%d", org, id), jsonHeader, bytes.NewReader(body))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditRepoHook modify one hook of a repository, with hook id and options
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOrgHook delete one hook from an organization, with hook id
|
||||||
|
func (c *Client) DeleteOrgHook(org string, id int64) error {
|
||||||
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/org/%s/hooks/%d", org, id), nil, nil)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteRepoHook delete one hook from a repository, with hook id
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// Payloader payload is some part of one hook
|
||||||
|
type Payloader interface {
|
||||||
|
SetSecret(string)
|
||||||
|
JSONPayload() ([]byte, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PayloadUser represents the author or committer of a commit
|
||||||
|
type PayloadUser struct {
|
||||||
|
// Full name of the commit author
|
||||||
|
Name string `json:"name"`
|
||||||
|
// swagger:strfmt email
|
||||||
|
Email string `json:"email"`
|
||||||
|
UserName string `json:"username"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: consider using same format as API when commits API are added.
|
||||||
|
// applies to PayloadCommit and PayloadCommitVerification
|
||||||
|
|
||||||
|
// PayloadCommit represents a commit
|
||||||
|
type PayloadCommit struct {
|
||||||
|
// sha1 hash of the commit
|
||||||
|
ID string `json:"id"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Author *PayloadUser `json:"author"`
|
||||||
|
Committer *PayloadUser `json:"committer"`
|
||||||
|
Verification *PayloadCommitVerification `json:"verification"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Timestamp time.Time `json:"timestamp"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PayloadCommitVerification represents the GPG verification of a commit
|
||||||
|
type PayloadCommitVerification struct {
|
||||||
|
Verified bool `json:"verified"`
|
||||||
|
Reason string `json:"reason"`
|
||||||
|
Signature string `json:"signature"`
|
||||||
|
Payload string `json:"payload"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ Payloader = &CreatePayload{}
|
||||||
|
_ Payloader = &PushPayload{}
|
||||||
|
_ Payloader = &IssuePayload{}
|
||||||
|
_ Payloader = &PullRequestPayload{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// _________ __
|
||||||
|
// \_ ___ \_______ ____ _____ _/ |_ ____
|
||||||
|
// / \ \/\_ __ \_/ __ \\__ \\ __\/ __ \
|
||||||
|
// \ \____| | \/\ ___/ / __ \| | \ ___/
|
||||||
|
// \______ /|__| \___ >____ /__| \___ >
|
||||||
|
// \/ \/ \/ \/
|
||||||
|
|
||||||
|
// CreatePayload FIXME
|
||||||
|
type CreatePayload struct {
|
||||||
|
Secret string `json:"secret"`
|
||||||
|
Sha string `json:"sha"`
|
||||||
|
Ref string `json:"ref"`
|
||||||
|
RefType string `json:"ref_type"`
|
||||||
|
Repo *Repository `json:"repository"`
|
||||||
|
Sender *User `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSecret FIXME
|
||||||
|
func (p *CreatePayload) SetSecret(secret string) {
|
||||||
|
p.Secret = secret
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSONPayload return payload information
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// __________ .__
|
||||||
|
// \______ \__ __ _____| |__
|
||||||
|
// | ___/ | \/ ___/ | \
|
||||||
|
// | | | | /\___ \| 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 *Repository `json:"repository"`
|
||||||
|
Pusher *User `json:"pusher"`
|
||||||
|
Sender *User `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSecret FIXME
|
||||||
|
func (p *PushPayload) SetSecret(secret string) {
|
||||||
|
p.Secret = secret
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSONPayload FIXME
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// .___
|
||||||
|
// | | ______ ________ __ ____
|
||||||
|
// | |/ ___// ___/ | \_/ __ \
|
||||||
|
// | |\___ \ \___ \| | /\ ___/
|
||||||
|
// |___/____ >____ >____/ \___ >
|
||||||
|
// \/ \/ \/
|
||||||
|
|
||||||
|
// HookIssueAction FIXME
|
||||||
|
type HookIssueAction string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// HookIssueOpened opened
|
||||||
|
HookIssueOpened HookIssueAction = "opened"
|
||||||
|
// HookIssueClosed closed
|
||||||
|
HookIssueClosed HookIssueAction = "closed"
|
||||||
|
// HookIssueReOpened reopened
|
||||||
|
HookIssueReOpened HookIssueAction = "reopened"
|
||||||
|
// HookIssueEdited edited
|
||||||
|
HookIssueEdited HookIssueAction = "edited"
|
||||||
|
// HookIssueAssigned assigned
|
||||||
|
HookIssueAssigned HookIssueAction = "assigned"
|
||||||
|
// HookIssueUnassigned unassigned
|
||||||
|
HookIssueUnassigned HookIssueAction = "unassigned"
|
||||||
|
// HookIssueLabelUpdated label_updated
|
||||||
|
HookIssueLabelUpdated HookIssueAction = "label_updated"
|
||||||
|
// HookIssueLabelCleared label_cleared
|
||||||
|
HookIssueLabelCleared HookIssueAction = "label_cleared"
|
||||||
|
// HookIssueSynchronized synchronized
|
||||||
|
HookIssueSynchronized HookIssueAction = "synchronized"
|
||||||
|
// HookIssueMilestoned is an issue action for when a milestone is set on an issue.
|
||||||
|
HookIssueMilestoned HookIssueAction = "milestoned"
|
||||||
|
// HookIssueDemilestoned is an issue action for when a milestone is cleared on an issue.
|
||||||
|
HookIssueDemilestoned HookIssueAction = "demilestoned"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IssuePayload represents the payload information that is sent along with an issue event.
|
||||||
|
type IssuePayload struct {
|
||||||
|
Secret string `json:"secret"`
|
||||||
|
Action HookIssueAction `json:"action"`
|
||||||
|
Index int64 `json:"number"`
|
||||||
|
Changes *ChangesPayload `json:"changes,omitempty"`
|
||||||
|
Issue *Issue `json:"issue"`
|
||||||
|
Repository *Repository `json:"repository"`
|
||||||
|
Sender *User `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSecret modifies the secret of the IssuePayload.
|
||||||
|
func (p *IssuePayload) SetSecret(secret string) {
|
||||||
|
p.Secret = secret
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSONPayload encodes the IssuePayload to JSON, with an indentation of two spaces.
|
||||||
|
func (p *IssuePayload) JSONPayload() ([]byte, error) {
|
||||||
|
return json.MarshalIndent(p, "", " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChangesFromPayload FIXME
|
||||||
|
type ChangesFromPayload struct {
|
||||||
|
From string `json:"from"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChangesPayload FIXME
|
||||||
|
type ChangesPayload struct {
|
||||||
|
Title *ChangesFromPayload `json:"title,omitempty"`
|
||||||
|
Body *ChangesFromPayload `json:"body,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// __________ .__ .__ __________ __
|
||||||
|
// \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
|
||||||
|
// | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
|
||||||
|
// | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | |
|
||||||
|
// |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__|
|
||||||
|
// \/ \/ |__| \/ \/
|
||||||
|
|
||||||
|
// PullRequestPayload represents a payload information of pull request event.
|
||||||
|
type PullRequestPayload struct {
|
||||||
|
Secret string `json:"secret"`
|
||||||
|
Action HookIssueAction `json:"action"`
|
||||||
|
Index int64 `json:"number"`
|
||||||
|
Changes *ChangesPayload `json:"changes,omitempty"`
|
||||||
|
PullRequest *PullRequest `json:"pull_request"`
|
||||||
|
Repository *Repository `json:"repository"`
|
||||||
|
Sender *User `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSecret modifies the secret of the PullRequestPayload.
|
||||||
|
func (p *PullRequestPayload) SetSecret(secret string) {
|
||||||
|
p.Secret = secret
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSONPayload FIXME
|
||||||
|
func (p *PullRequestPayload) JSONPayload() ([]byte, error) {
|
||||||
|
return json.MarshalIndent(p, "", " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
//__________ .__ __
|
||||||
|
//\______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
|
||||||
|
// | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
|
||||||
|
// | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
|
||||||
|
// |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
|
||||||
|
// \/ \/|__| \/ \/
|
||||||
|
|
||||||
|
// HookRepoAction an action that happens to a repo
|
||||||
|
type HookRepoAction string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// HookRepoCreated created
|
||||||
|
HookRepoCreated HookRepoAction = "created"
|
||||||
|
// HookRepoDeleted deleted
|
||||||
|
HookRepoDeleted HookRepoAction = "deleted"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RepositoryPayload payload for repository webhooks
|
||||||
|
type RepositoryPayload struct {
|
||||||
|
Secret string `json:"secret"`
|
||||||
|
Action HookRepoAction `json:"action"`
|
||||||
|
Repository *Repository `json:"repository"`
|
||||||
|
Organization *User `json:"organization"`
|
||||||
|
Sender *User `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSecret set the payload's secret
|
||||||
|
func (p *RepositoryPayload) SetSecret(secret string) {
|
||||||
|
p.Secret = secret
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSONPayload JSON representation of the payload
|
||||||
|
func (p *RepositoryPayload) JSONPayload() ([]byte, error) {
|
||||||
|
return json.MarshalIndent(p, "", " ")
|
||||||
|
}
|
129
vendor/code.gitea.io/sdk/gitea/issue.go
generated
vendored
Normal file
129
vendor/code.gitea.io/sdk/gitea/issue.go
generated
vendored
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// StateType issue state type
|
||||||
|
type StateType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// StateOpen pr is opend
|
||||||
|
StateOpen StateType = "open"
|
||||||
|
// StateClosed pr is closed
|
||||||
|
StateClosed StateType = "closed"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PullRequestMeta PR info if an issue is a PR
|
||||||
|
type PullRequestMeta struct {
|
||||||
|
HasMerged bool `json:"merged"`
|
||||||
|
Merged *time.Time `json:"merged_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Issue represents an issue in a repository
|
||||||
|
// swagger:model
|
||||||
|
type Issue struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
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"`
|
||||||
|
// Whether the issue is open or closed
|
||||||
|
//
|
||||||
|
// type: string
|
||||||
|
// enum: open,closed
|
||||||
|
State StateType `json:"state"`
|
||||||
|
Comments int `json:"comments"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Updated time.Time `json:"updated_at"`
|
||||||
|
|
||||||
|
PullRequest *PullRequestMeta `json:"pull_request"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListIssueOption list issue options
|
||||||
|
type ListIssueOption struct {
|
||||||
|
Page int
|
||||||
|
State string
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListIssues returns all issues assigned the authenticated user
|
||||||
|
func (c *Client) ListIssues(opt ListIssueOption) ([]*Issue, error) {
|
||||||
|
issues := make([]*Issue, 0, 10)
|
||||||
|
return issues, c.getParsedResponse("GET", fmt.Sprintf("/issues?page=%d", opt.Page), nil, nil, &issues)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListUserIssues returns all issues assigned to the authenticated user
|
||||||
|
func (c *Client) ListUserIssues(opt ListIssueOption) ([]*Issue, error) {
|
||||||
|
issues := make([]*Issue, 0, 10)
|
||||||
|
return issues, c.getParsedResponse("GET", fmt.Sprintf("/user/issues?page=%d", opt.Page), nil, nil, &issues)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepoIssues returns all issues for a given repository
|
||||||
|
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", owner, repo, opt.Page), nil, nil, &issues)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetIssue returns a single issue for a given repository
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateIssueOption options to create one issue
|
||||||
|
type CreateIssueOption struct {
|
||||||
|
// required:true
|
||||||
|
Title string `json:"title" binding:"Required"`
|
||||||
|
Body string `json:"body"`
|
||||||
|
// username of assignee
|
||||||
|
Assignee string `json:"assignee"`
|
||||||
|
// milestone id
|
||||||
|
Milestone int64 `json:"milestone"`
|
||||||
|
// list of label ids
|
||||||
|
Labels []int64 `json:"labels"`
|
||||||
|
Closed bool `json:"closed"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateIssue create a new issue for a given repository
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditIssueOption options for editing an issue
|
||||||
|
type EditIssueOption struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Body *string `json:"body"`
|
||||||
|
Assignee *string `json:"assignee"`
|
||||||
|
Milestone *int64 `json:"milestone"`
|
||||||
|
State *string `json:"state"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditIssue modify an existing issue for a given repository
|
||||||
|
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)
|
||||||
|
}
|
76
vendor/code.gitea.io/sdk/gitea/issue_comment.go
generated
vendored
Normal file
76
vendor/code.gitea.io/sdk/gitea/issue_comment.go
generated
vendored
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Comment represents a comment on a commit or issue
|
||||||
|
type Comment struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
HTMLURL string `json:"html_url"`
|
||||||
|
PRURL string `json:"pull_request_url"`
|
||||||
|
IssueURL string `json:"issue_url"`
|
||||||
|
Poster *User `json:"user"`
|
||||||
|
Body string `json:"body"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
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 options for creating a comment on an issue
|
||||||
|
type CreateIssueCommentOption struct {
|
||||||
|
// required:true
|
||||||
|
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 options for editing a comment
|
||||||
|
type EditIssueCommentOption struct {
|
||||||
|
// required: true
|
||||||
|
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
|
||||||
|
}
|
122
vendor/code.gitea.io/sdk/gitea/issue_label.go
generated
vendored
Normal file
122
vendor/code.gitea.io/sdk/gitea/issue_label.go
generated
vendored
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Label a label to an issue or a pr
|
||||||
|
// swagger:model
|
||||||
|
type Label struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
// example: 00aabb
|
||||||
|
Color string `json:"color"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepoLabels list labels of one repository
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRepoLabel get one label of repository by repo it
|
||||||
|
// TODO: maybe we need get a label by name
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateLabelOption options for creating a label
|
||||||
|
type CreateLabelOption struct {
|
||||||
|
// required:true
|
||||||
|
Name string `json:"name" binding:"Required"`
|
||||||
|
// required:true
|
||||||
|
// example: #00aabb
|
||||||
|
Color string `json:"color" binding:"Required;Size(7)"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateLabel create one label of repository
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditLabelOption options for editing a label
|
||||||
|
type EditLabelOption struct {
|
||||||
|
Name *string `json:"name"`
|
||||||
|
Color *string `json:"color"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditLabel modify one label with options
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteLabel delete one label of repository by id
|
||||||
|
// TODO: maybe we need delete by name
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssueLabelsOption a collection of labels
|
||||||
|
type IssueLabelsOption struct {
|
||||||
|
// list of label IDs
|
||||||
|
Labels []int64 `json:"labels"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetIssueLabels get labels of one issue via issue id
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddIssueLabels add one or more labels to one issue
|
||||||
|
func (c *Client) AddIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) {
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var labels []*Label
|
||||||
|
return labels, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReplaceIssueLabels replace old labels of issue with new 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
|
||||||
|
}
|
||||||
|
var labels []*Label
|
||||||
|
return labels, c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteIssueLabel delete one label of one issue by issue id and label id
|
||||||
|
// TODO: maybe we need delete by label name and issue id
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearIssueLabels delete all the labels of one issue.
|
||||||
|
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
|
||||||
|
}
|
80
vendor/code.gitea.io/sdk/gitea/issue_milestone.go
generated
vendored
Normal file
80
vendor/code.gitea.io/sdk/gitea/issue_milestone.go
generated
vendored
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Milestone milestone is a collection of issues on one repository
|
||||||
|
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"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Closed *time.Time `json:"closed_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Deadline *time.Time `json:"due_on"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepoMilestones list all the milestones of one repository
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMilestone get one milestone by repo name and milestone id
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateMilestoneOption options for creating a milestone
|
||||||
|
type CreateMilestoneOption struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Deadline *time.Time `json:"due_on"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateMilestone create one milestone with options
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditMilestoneOption options for editing a milestone
|
||||||
|
type EditMilestoneOption struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Description *string `json:"description"`
|
||||||
|
State *string `json:"state"`
|
||||||
|
Deadline *time.Time `json:"due_on"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditMilestone modify milestone with options
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteMilestone delete one milestone by milestone id
|
||||||
|
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
|
||||||
|
}
|
68
vendor/code.gitea.io/sdk/gitea/issue_tracked_time.go
generated
vendored
Normal file
68
vendor/code.gitea.io/sdk/gitea/issue_tracked_time.go
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
// Copyright 2017 The Gitea 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TrackedTime worked time for an issue / pr
|
||||||
|
type TrackedTime struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created time.Time `json:"created"`
|
||||||
|
// Time in seconds
|
||||||
|
Time int64 `json:"time"`
|
||||||
|
UserID int64 `json:"user_id"`
|
||||||
|
IssueID int64 `json:"issue_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TrackedTimes represent a list of tracked times
|
||||||
|
type TrackedTimes []*TrackedTime
|
||||||
|
|
||||||
|
// GetUserTrackedTimes list tracked times of a user
|
||||||
|
func (c *Client) GetUserTrackedTimes(owner, repo, user string) (TrackedTimes, error) {
|
||||||
|
times := make(TrackedTimes, 0, 10)
|
||||||
|
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times/%s", owner, repo, user), nil, nil, ×)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRepoTrackedTimes list tracked times of a repository
|
||||||
|
func (c *Client) GetRepoTrackedTimes(owner, repo string) (TrackedTimes, error) {
|
||||||
|
times := make(TrackedTimes, 0, 10)
|
||||||
|
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times", owner, repo), nil, nil, ×)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMyTrackedTimes list tracked times of the current user
|
||||||
|
func (c *Client) GetMyTrackedTimes() (TrackedTimes, error) {
|
||||||
|
times := make(TrackedTimes, 0, 10)
|
||||||
|
return times, c.getParsedResponse("GET", "/user/times", nil, nil, ×)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddTimeOption options for adding time to an issue
|
||||||
|
type AddTimeOption struct {
|
||||||
|
// time in seconds
|
||||||
|
// required: true
|
||||||
|
Time int64 `json:"time" binding:"Required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddTime adds time to issue with the given index
|
||||||
|
func (c *Client) AddTime(owner, repo string, index int64, opt AddTimeOption) (*TrackedTime, error) {
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
t := new(TrackedTime)
|
||||||
|
return t, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index),
|
||||||
|
jsonHeader, bytes.NewReader(body), t)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListTrackedTimes get tracked times of one issue via issue id
|
||||||
|
func (c *Client) ListTrackedTimes(owner, repo string, index int64) (TrackedTimes, error) {
|
||||||
|
times := make(TrackedTimes, 0, 5)
|
||||||
|
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index), nil, nil, ×)
|
||||||
|
}
|
65
vendor/code.gitea.io/sdk/gitea/lfs_lock.go
generated
vendored
Normal file
65
vendor/code.gitea.io/sdk/gitea/lfs_lock.go
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
// Copyright 2017 The Gitea 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LFSLock represent a lock
|
||||||
|
// for use with the locks API.
|
||||||
|
type LFSLock struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
LockedAt time.Time `json:"locked_at"`
|
||||||
|
Owner *LFSLockOwner `json:"owner"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LFSLockOwner represent a lock owner
|
||||||
|
// for use with the locks API.
|
||||||
|
type LFSLockOwner struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LFSLockRequest contains the path of the lock to create
|
||||||
|
// https://github.com/git-lfs/git-lfs/blob/master/docs/api/locking.md#create-lock
|
||||||
|
type LFSLockRequest struct {
|
||||||
|
Path string `json:"path"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LFSLockResponse represent a lock created
|
||||||
|
// https://github.com/git-lfs/git-lfs/blob/master/docs/api/locking.md#create-lock
|
||||||
|
type LFSLockResponse struct {
|
||||||
|
Lock *LFSLock `json:"lock"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LFSLockList represent a list of lock requested
|
||||||
|
// https://github.com/git-lfs/git-lfs/blob/master/docs/api/locking.md#list-locks
|
||||||
|
type LFSLockList struct {
|
||||||
|
Locks []*LFSLock `json:"locks"`
|
||||||
|
Next string `json:"next_cursor,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LFSLockListVerify represent a list of lock verification requested
|
||||||
|
// https://github.com/git-lfs/git-lfs/blob/master/docs/api/locking.md#list-locks-for-verification
|
||||||
|
type LFSLockListVerify struct {
|
||||||
|
Ours []*LFSLock `json:"ours"`
|
||||||
|
Theirs []*LFSLock `json:"theirs"`
|
||||||
|
Next string `json:"next_cursor,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LFSLockError contains information on the error that occurs
|
||||||
|
type LFSLockError struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
Lock *LFSLock `json:"lock,omitempty"`
|
||||||
|
Documentation string `json:"documentation_url,omitempty"`
|
||||||
|
RequestID string `json:"request_id,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LFSLockDeleteRequest contains params of a delete request
|
||||||
|
// https://github.com/git-lfs/git-lfs/blob/master/docs/api/locking.md#delete-lock
|
||||||
|
type LFSLockDeleteRequest struct {
|
||||||
|
Force bool `json:"force"`
|
||||||
|
}
|
52
vendor/code.gitea.io/sdk/gitea/miscellaneous.go
generated
vendored
Normal file
52
vendor/code.gitea.io/sdk/gitea/miscellaneous.go
generated
vendored
Normal file
@ -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 gitea
|
||||||
|
|
||||||
|
// SearchResults results of a successful search
|
||||||
|
type SearchResults struct {
|
||||||
|
OK bool `json:"ok"`
|
||||||
|
Data []*Repository `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SearchError error of a failed search
|
||||||
|
type SearchError struct {
|
||||||
|
OK bool `json:"ok"`
|
||||||
|
Error string `json:"error"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarkdownOption markdown options
|
||||||
|
type MarkdownOption struct {
|
||||||
|
// Text markdown to render
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
|
Text string
|
||||||
|
// Mode to render
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
|
Mode string
|
||||||
|
// Context to render
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
|
Context string
|
||||||
|
// Is it a wiki page ?
|
||||||
|
//
|
||||||
|
// in: body
|
||||||
|
Wiki bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarkdownRender is a rendered markdown document
|
||||||
|
// swagger:response MarkdownRender
|
||||||
|
type MarkdownRender string
|
||||||
|
|
||||||
|
// ServerVersion wraps the version of the server
|
||||||
|
type ServerVersion struct {
|
||||||
|
Version string `json:"version"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServerVersion returns the version of the server
|
||||||
|
func (c *Client) ServerVersion() (string, error) {
|
||||||
|
v := ServerVersion{}
|
||||||
|
return v.Version, c.getParsedResponse("GET", "/api/v1/version", nil, nil, &v)
|
||||||
|
}
|
68
vendor/code.gitea.io/sdk/gitea/org.go
generated
vendored
Normal file
68
vendor/code.gitea.io/sdk/gitea/org.go
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Organization represents an organization
|
||||||
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListMyOrgs list all of current user's organizations
|
||||||
|
func (c *Client) ListMyOrgs() ([]*Organization, error) {
|
||||||
|
orgs := make([]*Organization, 0, 5)
|
||||||
|
return orgs, c.getParsedResponse("GET", "/user/orgs", nil, nil, &orgs)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListUserOrgs list all of some user's organizations
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetOrg get one organization by name
|
||||||
|
func (c *Client) GetOrg(orgname string) (*Organization, error) {
|
||||||
|
org := new(Organization)
|
||||||
|
return org, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s", orgname), nil, nil, org)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateOrgOption options for creating an organization
|
||||||
|
type CreateOrgOption struct {
|
||||||
|
// required: true
|
||||||
|
UserName string `json:"username" binding:"Required"`
|
||||||
|
FullName string `json:"full_name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Website string `json:"website"`
|
||||||
|
Location string `json:"location"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditOrgOption options for editing an organization
|
||||||
|
type EditOrgOption struct {
|
||||||
|
FullName string `json:"full_name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Website string `json:"website"`
|
||||||
|
Location string `json:"location"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditOrg modify one organization via options
|
||||||
|
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), jsonHeader, bytes.NewReader(body))
|
||||||
|
return err
|
||||||
|
}
|
26
vendor/code.gitea.io/sdk/gitea/org_member.go
generated
vendored
Normal file
26
vendor/code.gitea.io/sdk/gitea/org_member.go
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AddOrgMembershipOption add user to organization options
|
||||||
|
type AddOrgMembershipOption struct {
|
||||||
|
Role string `json:"role" binding:"Required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddOrgMembership add some one to an organization's member
|
||||||
|
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
|
||||||
|
}
|
32
vendor/code.gitea.io/sdk/gitea/org_team.go
generated
vendored
Normal file
32
vendor/code.gitea.io/sdk/gitea/org_team.go
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
// Team represents a team in an organization
|
||||||
|
type Team struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
// enum: none,read,write,admin,owner
|
||||||
|
Permission string `json:"permission"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTeamOption options for creating a team
|
||||||
|
type CreateTeamOption struct {
|
||||||
|
// required: true
|
||||||
|
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
|
||||||
|
Description string `json:"description" binding:"MaxSize(255)"`
|
||||||
|
// enum: read,write,admin
|
||||||
|
Permission string `json:"permission"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditTeamOption options for editing a team
|
||||||
|
type EditTeamOption struct {
|
||||||
|
// required: true
|
||||||
|
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
|
||||||
|
Description string `json:"description" binding:"MaxSize(255)"`
|
||||||
|
// enum: read,write,admin
|
||||||
|
Permission string `json:"permission"`
|
||||||
|
}
|
139
vendor/code.gitea.io/sdk/gitea/pull.go
generated
vendored
Normal file
139
vendor/code.gitea.io/sdk/gitea/pull.go
generated
vendored
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PullRequest represents a pull request
|
||||||
|
type PullRequest struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
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"`
|
||||||
|
|
||||||
|
HTMLURL string `json:"html_url"`
|
||||||
|
DiffURL string `json:"diff_url"`
|
||||||
|
PatchURL string `json:"patch_url"`
|
||||||
|
|
||||||
|
Mergeable bool `json:"mergeable"`
|
||||||
|
HasMerged bool `json:"merged"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Merged *time.Time `json:"merged_at"`
|
||||||
|
MergedCommitID *string `json:"merge_commit_sha"`
|
||||||
|
MergedBy *User `json:"merged_by"`
|
||||||
|
|
||||||
|
Base *PRBranchInfo `json:"base"`
|
||||||
|
Head *PRBranchInfo `json:"head"`
|
||||||
|
MergeBase string `json:"merge_base"`
|
||||||
|
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created *time.Time `json:"created_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Updated *time.Time `json:"updated_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRBranchInfo information about a branch
|
||||||
|
type PRBranchInfo struct {
|
||||||
|
Name string `json:"label"`
|
||||||
|
Ref string `json:"ref"`
|
||||||
|
Sha string `json:"sha"`
|
||||||
|
RepoID int64 `json:"repo_id"`
|
||||||
|
Repository *Repository `json:"repo"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListPullRequestsOptions options for listing pull requests
|
||||||
|
type ListPullRequestsOptions struct {
|
||||||
|
Page int `json:"page"`
|
||||||
|
State string `json:"state"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepoPullRequests list PRs of one repository
|
||||||
|
func (c *Client) ListRepoPullRequests(owner, repo string, opt ListPullRequestsOptions) ([]*PullRequest, error) {
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
prs := make([]*PullRequest, 0, 10)
|
||||||
|
return prs, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/pulls", owner, repo), jsonHeader, bytes.NewReader(body), &prs)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPullRequest get information of one PR
|
||||||
|
func (c *Client) GetPullRequest(owner, repo string, index int64) (*PullRequest, error) {
|
||||||
|
pr := new(PullRequest)
|
||||||
|
return pr, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d", owner, repo, index), nil, nil, pr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatePullRequestOption options when creating a pull request
|
||||||
|
type CreatePullRequestOption struct {
|
||||||
|
Head string `json:"head" binding:"Required"`
|
||||||
|
Base string `json:"base" binding:"Required"`
|
||||||
|
Title string `json:"title" binding:"Required"`
|
||||||
|
Body string `json:"body"`
|
||||||
|
Assignee string `json:"assignee"`
|
||||||
|
Milestone int64 `json:"milestone"`
|
||||||
|
Labels []int64 `json:"labels"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatePullRequest create pull request with options
|
||||||
|
func (c *Client) CreatePullRequest(owner, repo string, opt CreatePullRequestOption) (*PullRequest, error) {
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
pr := new(PullRequest)
|
||||||
|
return pr, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/pulls", owner, repo),
|
||||||
|
jsonHeader, bytes.NewReader(body), pr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditPullRequestOption options when modify pull request
|
||||||
|
type EditPullRequestOption struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Body string `json:"body"`
|
||||||
|
Assignee string `json:"assignee"`
|
||||||
|
Milestone int64 `json:"milestone"`
|
||||||
|
Labels []int64 `json:"labels"`
|
||||||
|
State *string `json:"state"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditPullRequest modify pull request with PR id and options
|
||||||
|
func (c *Client) EditPullRequest(owner, repo string, index int64, opt EditPullRequestOption) (*PullRequest, error) {
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
pr := new(PullRequest)
|
||||||
|
return pr, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index),
|
||||||
|
jsonHeader, bytes.NewReader(body), pr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MergePullRequest merge a PR to repository by PR id
|
||||||
|
func (c *Client) MergePullRequest(owner, repo string, index int64) error {
|
||||||
|
_, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/pulls/%d/merge", owner, repo, index), nil, nil)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsPullRequestMerged test if one PR is merged to one repository
|
||||||
|
func (c *Client) IsPullRequestMerged(owner, repo string, index int64) (bool, error) {
|
||||||
|
statusCode, err := c.getStatusCode("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d/merge", owner, repo, index), nil, nil)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return statusCode == 204, nil
|
||||||
|
|
||||||
|
}
|
105
vendor/code.gitea.io/sdk/gitea/release.go
generated
vendored
Normal file
105
vendor/code.gitea.io/sdk/gitea/release.go
generated
vendored
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
// Copyright 2016 The Gitea 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Release represents a repository release
|
||||||
|
type Release struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
TagName string `json:"tag_name"`
|
||||||
|
Target string `json:"target_commitish"`
|
||||||
|
Title string `json:"name"`
|
||||||
|
Note string `json:"body"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
TarURL string `json:"tarball_url"`
|
||||||
|
ZipURL string `json:"zipball_url"`
|
||||||
|
IsDraft bool `json:"draft"`
|
||||||
|
IsPrerelease bool `json:"prerelease"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
PublishedAt time.Time `json:"published_at"`
|
||||||
|
Publisher *User `json:"author"`
|
||||||
|
Attachments []*Attachment `json:"assets"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListReleases list releases of a repository
|
||||||
|
func (c *Client) ListReleases(user, repo string) ([]*Release, error) {
|
||||||
|
releases := make([]*Release, 0, 10)
|
||||||
|
err := c.getParsedResponse("GET",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/releases", user, repo),
|
||||||
|
nil, nil, &releases)
|
||||||
|
return releases, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRelease get a release of a repository
|
||||||
|
func (c *Client) GetRelease(user, repo string, id int64) (*Release, error) {
|
||||||
|
r := new(Release)
|
||||||
|
err := c.getParsedResponse("GET",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/releases/%d", user, repo, id),
|
||||||
|
nil, nil, &r)
|
||||||
|
return r, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateReleaseOption options when creating a release
|
||||||
|
type CreateReleaseOption struct {
|
||||||
|
// required: true
|
||||||
|
TagName string `json:"tag_name" binding:"Required"`
|
||||||
|
Target string `json:"target_commitish"`
|
||||||
|
Title string `json:"name"`
|
||||||
|
Note string `json:"body"`
|
||||||
|
IsDraft bool `json:"draft"`
|
||||||
|
IsPrerelease bool `json:"prerelease"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateRelease create a release
|
||||||
|
func (c *Client) CreateRelease(user, repo string, form CreateReleaseOption) (*Release, error) {
|
||||||
|
body, err := json.Marshal(form)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
r := new(Release)
|
||||||
|
err = c.getParsedResponse("POST",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/releases", user, repo),
|
||||||
|
jsonHeader, bytes.NewReader(body), r)
|
||||||
|
return r, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditReleaseOption options when editing a release
|
||||||
|
type EditReleaseOption struct {
|
||||||
|
TagName string `json:"tag_name"`
|
||||||
|
Target string `json:"target_commitish"`
|
||||||
|
Title string `json:"name"`
|
||||||
|
Note string `json:"body"`
|
||||||
|
IsDraft *bool `json:"draft"`
|
||||||
|
IsPrerelease *bool `json:"prerelease"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditRelease edit a release
|
||||||
|
func (c *Client) EditRelease(user, repo string, id int64, form EditReleaseOption) (*Release, error) {
|
||||||
|
body, err := json.Marshal(form)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
r := new(Release)
|
||||||
|
err = c.getParsedResponse("PATCH",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/releases/%d", user, repo, id),
|
||||||
|
jsonHeader, bytes.NewReader(body), r)
|
||||||
|
return r, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteRelease delete a release from a repository
|
||||||
|
func (c *Client) DeleteRelease(user, repo string, id int64) error {
|
||||||
|
_, err := c.getResponse("DELETE",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/releases/%d", user, repo, id),
|
||||||
|
nil, nil)
|
||||||
|
return err
|
||||||
|
}
|
155
vendor/code.gitea.io/sdk/gitea/repo.go
generated
vendored
Normal file
155
vendor/code.gitea.io/sdk/gitea/repo.go
generated
vendored
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Permission represents a set of permissions
|
||||||
|
type Permission struct {
|
||||||
|
Admin bool `json:"admin"`
|
||||||
|
Push bool `json:"push"`
|
||||||
|
Pull bool `json:"pull"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Repository represents a repository
|
||||||
|
type Repository struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Owner *User `json:"owner"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
FullName string `json:"full_name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Empty bool `json:"empty"`
|
||||||
|
Private bool `json:"private"`
|
||||||
|
Fork bool `json:"fork"`
|
||||||
|
Parent *Repository `json:"parent"`
|
||||||
|
Mirror bool `json:"mirror"`
|
||||||
|
Size int `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"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Updated time.Time `json:"updated_at"`
|
||||||
|
Permissions *Permission `json:"permissions,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListMyRepos lists all repositories for the authenticated user that has access to.
|
||||||
|
func (c *Client) ListMyRepos() ([]*Repository, error) {
|
||||||
|
repos := make([]*Repository, 0, 10)
|
||||||
|
return repos, c.getParsedResponse("GET", "/user/repos", nil, nil, &repos)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListUserRepos list all repositories of one user by user's name
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListOrgRepos list all repositories of one organization by organization's name
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateRepoOption options when creating repository
|
||||||
|
// swagger:model
|
||||||
|
type CreateRepoOption struct {
|
||||||
|
// Name of the repository to create
|
||||||
|
//
|
||||||
|
// required: true
|
||||||
|
// unique: true
|
||||||
|
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
|
||||||
|
// Description of the repository to create
|
||||||
|
Description string `json:"description" binding:"MaxSize(255)"`
|
||||||
|
// Whether the repository is private
|
||||||
|
Private bool `json:"private"`
|
||||||
|
// Whether the repository should be auto-intialized?
|
||||||
|
AutoInit bool `json:"auto_init"`
|
||||||
|
// Gitignores to use
|
||||||
|
Gitignores string `json:"gitignores"`
|
||||||
|
// License to use
|
||||||
|
License string `json:"license"`
|
||||||
|
// Readme of the repository to create
|
||||||
|
Readme string `json:"readme"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateRepo creates a repository for authenticated user.
|
||||||
|
func (c *Client) CreateRepo(opt CreateRepoOption) (*Repository, error) {
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
repo := new(Repository)
|
||||||
|
return repo, c.getParsedResponse("POST", "/user/repos", jsonHeader, bytes.NewReader(body), repo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateOrgRepo creates an organization repository for authenticated user.
|
||||||
|
func (c *Client) CreateOrgRepo(org 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("/org/%s/repos", org), jsonHeader, 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// MigrateRepoOption options for migrating a repository from an external service
|
||||||
|
type MigrateRepoOption struct {
|
||||||
|
// required: true
|
||||||
|
CloneAddr string `json:"clone_addr" binding:"Required"`
|
||||||
|
AuthUsername string `json:"auth_username"`
|
||||||
|
AuthPassword string `json:"auth_password"`
|
||||||
|
// required: true
|
||||||
|
UID int `json:"uid" binding:"Required"`
|
||||||
|
// required: true
|
||||||
|
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", jsonHeader, bytes.NewReader(body), repo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MirrorSync adds a mirrored repository to the mirror sync queue.
|
||||||
|
func (c *Client) MirrorSync(owner, repo string) error {
|
||||||
|
_, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/mirror-sync", owner, repo), nil, nil)
|
||||||
|
return err
|
||||||
|
}
|
27
vendor/code.gitea.io/sdk/gitea/repo_branch.go
generated
vendored
Normal file
27
vendor/code.gitea.io/sdk/gitea/repo_branch.go
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Branch represents a repository branch
|
||||||
|
type Branch struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Commit *PayloadCommit `json:"commit"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepoBranches list all the branches of one repository
|
||||||
|
func (c *Client) ListRepoBranches(user, repo string) ([]*Branch, error) {
|
||||||
|
branches := make([]*Branch, 0, 10)
|
||||||
|
return branches, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches", user, repo), nil, nil, &branches)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRepoBranch get one branch's information of one repository
|
||||||
|
func (c *Client) GetRepoBranch(user, repo, branch string) (*Branch, error) {
|
||||||
|
b := new(Branch)
|
||||||
|
return b, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches/%s", user, repo, branch), nil, nil, &b)
|
||||||
|
}
|
57
vendor/code.gitea.io/sdk/gitea/repo_collaborator.go
generated
vendored
Normal file
57
vendor/code.gitea.io/sdk/gitea/repo_collaborator.go
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ListCollaborators list a repository's collaborators
|
||||||
|
func (c *Client) ListCollaborators(user, repo string) ([]*User, error) {
|
||||||
|
collaborators := make([]*User, 0, 10)
|
||||||
|
err := c.getParsedResponse("GET",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/collaborators", user, repo),
|
||||||
|
nil, nil, &collaborators)
|
||||||
|
return collaborators, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsCollaborator check if a user is a collaborator of a repository
|
||||||
|
func (c *Client) IsCollaborator(user, repo, collaborator string) (bool, error) {
|
||||||
|
status, err := c.getStatusCode("GET",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator),
|
||||||
|
nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if status == 204 {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddCollaboratorOption options when adding a user as a collaborator of a repository
|
||||||
|
type AddCollaboratorOption struct {
|
||||||
|
Permission *string `json:"permission"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddCollaborator add some user as a collaborator of a repository
|
||||||
|
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), nil, bytes.NewReader(body))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteCollaborator remove a collaborator from a repository
|
||||||
|
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
|
||||||
|
}
|
15
vendor/code.gitea.io/sdk/gitea/repo_file.go
generated
vendored
Normal file
15
vendor/code.gitea.io/sdk/gitea/repo_file.go
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetFile downloads a file of repository, ref can be branch/tag/commit.
|
||||||
|
// e.g.: ref -> master, tree -> macaron.go(no leading slash)
|
||||||
|
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)
|
||||||
|
}
|
69
vendor/code.gitea.io/sdk/gitea/repo_key.go
generated
vendored
Normal file
69
vendor/code.gitea.io/sdk/gitea/repo_key.go
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DeployKey a deploy key
|
||||||
|
type DeployKey struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Key string `json:"key"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
ReadOnly bool `json:"read_only"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListDeployKeys list all the deploy keys of one repository
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDeployKey get one deploy key with key id
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateKeyOption options when creating a key
|
||||||
|
type CreateKeyOption struct {
|
||||||
|
// Title of the key to add
|
||||||
|
//
|
||||||
|
// required: true
|
||||||
|
// unique: true
|
||||||
|
Title string `json:"title" binding:"Required"`
|
||||||
|
// An armored SSH key to add
|
||||||
|
//
|
||||||
|
// required: true
|
||||||
|
// unique: true
|
||||||
|
Key string `json:"key" binding:"Required"`
|
||||||
|
// Describe if the key has only read access or read/write
|
||||||
|
//
|
||||||
|
// required: false
|
||||||
|
ReadOnly bool `json:"read_only"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateDeployKey options when create one deploy key
|
||||||
|
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), jsonHeader, bytes.NewReader(body), key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteDeployKey delete deploy key with key id
|
||||||
|
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
|
||||||
|
}
|
41
vendor/code.gitea.io/sdk/gitea/repo_watch.go
generated
vendored
Normal file
41
vendor/code.gitea.io/sdk/gitea/repo_watch.go
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright 2017 The Gitea 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WatchInfo represents an API watch status of one repository
|
||||||
|
type WatchInfo struct {
|
||||||
|
Subscribed bool `json:"subscribed"`
|
||||||
|
Ignored bool `json:"ignored"`
|
||||||
|
Reason interface{} `json:"reason"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
RepositoryURL string `json:"repository_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetWatchedRepos list all the watched repos of user
|
||||||
|
func (c *Client) GetWatchedRepos(user, pass string) ([]*Repository, error) {
|
||||||
|
repos := make([]*Repository, 0, 10)
|
||||||
|
return repos, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/subscriptions", user),
|
||||||
|
http.Header{"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, nil, &repos)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WatchRepo start to watch a repository
|
||||||
|
func (c *Client) WatchRepo(user, pass, repoUser, repoName string) (*WatchInfo, error) {
|
||||||
|
i := new(WatchInfo)
|
||||||
|
return i, c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/subscription", repoUser, repoName),
|
||||||
|
http.Header{"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, nil, i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnWatchRepo start to watch a repository
|
||||||
|
func (c *Client) UnWatchRepo(user, pass, repoUser, repoName string) (int, error) {
|
||||||
|
return c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/subscription", repoUser, repoName),
|
||||||
|
http.Header{"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, nil)
|
||||||
|
}
|
97
vendor/code.gitea.io/sdk/gitea/status.go
generated
vendored
Normal file
97
vendor/code.gitea.io/sdk/gitea/status.go
generated
vendored
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
// Copyright 2017 The Gitea 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// StatusState holds the state of a Status
|
||||||
|
// It can be "pending", "success", "error", "failure", and "warning"
|
||||||
|
type StatusState string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// StatusPending is for when the Status is Pending
|
||||||
|
StatusPending StatusState = "pending"
|
||||||
|
// StatusSuccess is for when the Status is Success
|
||||||
|
StatusSuccess StatusState = "success"
|
||||||
|
// StatusError is for when the Status is Error
|
||||||
|
StatusError StatusState = "error"
|
||||||
|
// StatusFailure is for when the Status is Failure
|
||||||
|
StatusFailure StatusState = "failure"
|
||||||
|
// StatusWarning is for when the Status is Warning
|
||||||
|
StatusWarning StatusState = "warning"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Status holds a single Status of a single Commit
|
||||||
|
type Status struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
State StatusState `json:"status"`
|
||||||
|
TargetURL string `json:"target_url"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Context string `json:"context"`
|
||||||
|
Creator *User `json:"creator"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Updated time.Time `json:"updated_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CombinedStatus holds the combined state of several statuses for a single commit
|
||||||
|
type CombinedStatus struct {
|
||||||
|
State StatusState `json:"state"`
|
||||||
|
SHA string `json:"sha"`
|
||||||
|
TotalCount int `json:"total_count"`
|
||||||
|
Statuses []*Status `json:"statuses"`
|
||||||
|
Repository *Repository `json:"repository"`
|
||||||
|
CommitURL string `json:"commit_url"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateStatusOption holds the information needed to create a new Status for a Commit
|
||||||
|
type CreateStatusOption struct {
|
||||||
|
State StatusState `json:"state"`
|
||||||
|
TargetURL string `json:"target_url"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Context string `json:"context"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListStatusesOption holds pagination information
|
||||||
|
type ListStatusesOption struct {
|
||||||
|
Page int
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateStatus creates a new Status for a given Commit
|
||||||
|
//
|
||||||
|
// POST /repos/:owner/:repo/statuses/:sha
|
||||||
|
func (c *Client) CreateStatus(owner, repo, sha string, opts CreateStatusOption) (*Status, error) {
|
||||||
|
body, err := json.Marshal(&opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
status := &Status{}
|
||||||
|
return status, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/statuses/%s", owner, repo, sha),
|
||||||
|
jsonHeader, bytes.NewReader(body), status)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListStatuses returns all statuses for a given Commit
|
||||||
|
//
|
||||||
|
// GET /repos/:owner/:repo/commits/:ref/statuses
|
||||||
|
func (c *Client) ListStatuses(owner, repo, sha string, opts ListStatusesOption) ([]*Status, error) {
|
||||||
|
statuses := make([]*Status, 0, 10)
|
||||||
|
return statuses, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s/statuses?page=%d", owner, repo, sha, opts.Page), nil, nil, &statuses)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCombinedStatus returns the CombinedStatus for a given Commit
|
||||||
|
//
|
||||||
|
// GET /repos/:owner/:repo/commits/:ref/status
|
||||||
|
func (c *Client) GetCombinedStatus(owner, repo, sha string) (*CombinedStatus, error) {
|
||||||
|
status := &CombinedStatus{}
|
||||||
|
return status, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s/status", owner, repo, sha), nil, nil, status)
|
||||||
|
}
|
42
vendor/code.gitea.io/sdk/gitea/user.go
generated
vendored
Normal file
42
vendor/code.gitea.io/sdk/gitea/user.go
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// User represents a user
|
||||||
|
// swagger:model
|
||||||
|
type User struct {
|
||||||
|
// the user's id
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
// the user's username
|
||||||
|
UserName string `json:"login"`
|
||||||
|
// the user's full name
|
||||||
|
FullName string `json:"full_name"`
|
||||||
|
// swagger:strfmt email
|
||||||
|
Email string `json:"email"`
|
||||||
|
// URL to the user's avatar
|
||||||
|
AvatarURL string `json:"avatar_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
|
||||||
|
func (u User) MarshalJSON() ([]byte, error) {
|
||||||
|
// Re-declaring User to avoid recursion
|
||||||
|
type shadow User
|
||||||
|
return json.Marshal(struct {
|
||||||
|
shadow
|
||||||
|
CompatUserName string `json:"username"`
|
||||||
|
}{shadow(u), u.UserName})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetUserInfo get user info by user's name
|
||||||
|
func (c *Client) GetUserInfo(user string) (*User, error) {
|
||||||
|
u := new(User)
|
||||||
|
err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)
|
||||||
|
return u, err
|
||||||
|
}
|
56
vendor/code.gitea.io/sdk/gitea/user_app.go
generated
vendored
Normal file
56
vendor/code.gitea.io/sdk/gitea/user_app.go
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BasicAuthEncode generate base64 of basic auth head
|
||||||
|
func BasicAuthEncode(user, pass string) string {
|
||||||
|
return base64.StdEncoding.EncodeToString([]byte(user + ":" + pass))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccessToken represents a API access token.
|
||||||
|
// swagger:response AccessToken
|
||||||
|
type AccessToken struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Sha1 string `json:"sha1"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccessTokenList represents a list of API access token.
|
||||||
|
// swagger:response AccessTokenList
|
||||||
|
type AccessTokenList []*AccessToken
|
||||||
|
|
||||||
|
// ListAccessTokens lista all the access tokens of user
|
||||||
|
func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) {
|
||||||
|
tokens := make([]*AccessToken, 0, 10)
|
||||||
|
return tokens, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/tokens", user),
|
||||||
|
http.Header{"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, nil, &tokens)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateAccessTokenOption options when create access token
|
||||||
|
// swagger:parameters userCreateToken
|
||||||
|
type CreateAccessTokenOption struct {
|
||||||
|
Name string `json:"name" binding:"Required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateAccessToken create one access token with options
|
||||||
|
func (c *Client) CreateAccessToken(user, pass string, opt CreateAccessTokenOption) (*AccessToken, error) {
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
t := new(AccessToken)
|
||||||
|
return t, c.getParsedResponse("POST", fmt.Sprintf("/users/%s/tokens", user),
|
||||||
|
http.Header{
|
||||||
|
"content-type": []string{"application/json"},
|
||||||
|
"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}},
|
||||||
|
bytes.NewReader(body), t)
|
||||||
|
}
|
56
vendor/code.gitea.io/sdk/gitea/user_email.go
generated
vendored
Normal file
56
vendor/code.gitea.io/sdk/gitea/user_email.go
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Email an email address belonging to a user
|
||||||
|
type Email struct {
|
||||||
|
// swagger:strfmt email
|
||||||
|
Email string `json:"email"`
|
||||||
|
Verified bool `json:"verified"`
|
||||||
|
Primary bool `json:"primary"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListEmails all the email addresses of user
|
||||||
|
func (c *Client) ListEmails() ([]*Email, error) {
|
||||||
|
emails := make([]*Email, 0, 3)
|
||||||
|
return emails, c.getParsedResponse("GET", "/user/emails", nil, nil, &emails)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateEmailOption options when creating email addresses
|
||||||
|
type CreateEmailOption struct {
|
||||||
|
// email addresses to add
|
||||||
|
Emails []string `json:"emails"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddEmail add one email to current user with options
|
||||||
|
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", jsonHeader, bytes.NewReader(body), emails)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteEmailOption options when deleting email addresses
|
||||||
|
type DeleteEmailOption struct {
|
||||||
|
// email addresses to delete
|
||||||
|
Emails []string `json:"emails"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteEmail delete one email of current users'
|
||||||
|
func (c *Client) DeleteEmail(opt DeleteEmailOption) error {
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = c.getResponse("DELETE", "/user/emails", jsonHeader, bytes.NewReader(body))
|
||||||
|
return err
|
||||||
|
}
|
55
vendor/code.gitea.io/sdk/gitea/user_follow.go
generated
vendored
Normal file
55
vendor/code.gitea.io/sdk/gitea/user_follow.go
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// ListMyFollowers list all the followers of current user
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListFollowers list all the followers of one user
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListMyFollowing list all the users current user followed
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListFollowing list all the users the user followed
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsFollowing if current user followed the target
|
||||||
|
func (c *Client) IsFollowing(target string) bool {
|
||||||
|
_, err := c.getResponse("GET", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsUserFollowing if the user followed the target
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// Follow set current user follow the target
|
||||||
|
func (c *Client) Follow(target string) error {
|
||||||
|
_, err := c.getResponse("PUT", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unfollow set current user unfollow the target
|
||||||
|
func (c *Client) Unfollow(target string) error {
|
||||||
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
||||||
|
return err
|
||||||
|
}
|
80
vendor/code.gitea.io/sdk/gitea/user_gpgkey.go
generated
vendored
Normal file
80
vendor/code.gitea.io/sdk/gitea/user_gpgkey.go
generated
vendored
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// Copyright 2017 Gitea 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GPGKey a user GPG key to sign commit and tag in repository
|
||||||
|
type GPGKey struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
PrimaryKeyID string `json:"primary_key_id"`
|
||||||
|
KeyID string `json:"key_id"`
|
||||||
|
PublicKey string `json:"public_key"`
|
||||||
|
Emails []*GPGKeyEmail `json:"emails"`
|
||||||
|
SubsKey []*GPGKey `json:"subkeys"`
|
||||||
|
CanSign bool `json:"can_sign"`
|
||||||
|
CanEncryptComms bool `json:"can_encrypt_comms"`
|
||||||
|
CanEncryptStorage bool `json:"can_encrypt_storage"`
|
||||||
|
CanCertify bool `json:"can_certify"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created time.Time `json:"created_at,omitempty"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Expires time.Time `json:"expires_at,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GPGKeyEmail an email attached to a GPGKey
|
||||||
|
// swagger:model GPGKeyEmail
|
||||||
|
type GPGKeyEmail struct {
|
||||||
|
Email string `json:"email"`
|
||||||
|
Verified bool `json:"verified"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateGPGKeyOption options create user GPG key
|
||||||
|
type CreateGPGKeyOption struct {
|
||||||
|
// An armored GPG key to add
|
||||||
|
//
|
||||||
|
// required: true
|
||||||
|
// unique: true
|
||||||
|
ArmoredKey string `json:"armored_public_key" binding:"Required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListGPGKeys list all the GPG keys of the user
|
||||||
|
func (c *Client) ListGPGKeys(user string) ([]*GPGKey, error) {
|
||||||
|
keys := make([]*GPGKey, 0, 10)
|
||||||
|
return keys, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/gpg_keys", user), nil, nil, &keys)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListMyGPGKeys list all the GPG keys of current user
|
||||||
|
func (c *Client) ListMyGPGKeys() ([]*GPGKey, error) {
|
||||||
|
keys := make([]*GPGKey, 0, 10)
|
||||||
|
return keys, c.getParsedResponse("GET", "/user/gpg_keys", nil, nil, &keys)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGPGKey get current user's GPG key by key id
|
||||||
|
func (c *Client) GetGPGKey(keyID int64) (*GPGKey, error) {
|
||||||
|
key := new(GPGKey)
|
||||||
|
return key, c.getParsedResponse("GET", fmt.Sprintf("/user/gpg_keys/%d", keyID), nil, nil, &key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateGPGKey create GPG key with options
|
||||||
|
func (c *Client) CreateGPGKey(opt CreateGPGKeyOption) (*GPGKey, error) {
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
key := new(GPGKey)
|
||||||
|
return key, c.getParsedResponse("POST", "/user/gpg_keys", jsonHeader, bytes.NewReader(body), key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteGPGKey delete GPG key with key id
|
||||||
|
func (c *Client) DeleteGPGKey(keyID int64) error {
|
||||||
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/user/gpg_keys/%d", keyID), nil, nil)
|
||||||
|
return err
|
||||||
|
}
|
57
vendor/code.gitea.io/sdk/gitea/user_key.go
generated
vendored
Normal file
57
vendor/code.gitea.io/sdk/gitea/user_key.go
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PublicKey publickey is a user key to push code to repository
|
||||||
|
type PublicKey struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Key string `json:"key"`
|
||||||
|
URL string `json:"url,omitempty"`
|
||||||
|
Title string `json:"title,omitempty"`
|
||||||
|
Fingerprint string `json:"fingerprint,omitempty"`
|
||||||
|
// swagger:strfmt date-time
|
||||||
|
Created time.Time `json:"created_at,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListPublicKeys list all the public keys of the user
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListMyPublicKeys list all the public keys of current user
|
||||||
|
func (c *Client) ListMyPublicKeys() ([]*PublicKey, error) {
|
||||||
|
keys := make([]*PublicKey, 0, 10)
|
||||||
|
return keys, c.getParsedResponse("GET", "/user/keys", nil, nil, &keys)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPublicKey get current user's public key by key id
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatePublicKey create public key with options
|
||||||
|
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", jsonHeader, bytes.NewReader(body), key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletePublicKey delete public key with key id
|
||||||
|
func (c *Client) DeletePublicKey(keyID int64) error {
|
||||||
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/user/keys/%d", keyID), nil, nil)
|
||||||
|
return err
|
||||||
|
}
|
14
vendor/code.gitea.io/sdk/gitea/user_search.go
generated
vendored
Normal file
14
vendor/code.gitea.io/sdk/gitea/user_search.go
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package gitea
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type searchUsersResponse struct {
|
||||||
|
Users []*User `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SearchUsers finds users by query
|
||||||
|
func (c *Client) SearchUsers(query string, limit int) ([]*User, error) {
|
||||||
|
resp := new(searchUsersResponse)
|
||||||
|
err := c.getParsedResponse("GET", fmt.Sprintf("/users/search?q=%s&limit=%d", query, limit), nil, nil, &resp)
|
||||||
|
return resp.Users, err
|
||||||
|
}
|
26
vendor/code.gitea.io/sdk/gitea/utils.go
generated
vendored
Normal file
26
vendor/code.gitea.io/sdk/gitea/utils.go
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// 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 gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
var jsonHeader = http.Header{"content-type": []string{"application/json"}}
|
||||||
|
|
||||||
|
// Bool return address of bool value
|
||||||
|
func Bool(v bool) *bool {
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
||||||
|
// String return address of string value
|
||||||
|
func String(v string) *string {
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64 return address of int64 value
|
||||||
|
func Int64(v int64) *int64 {
|
||||||
|
return &v
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user