Update dependency package code.gitea.io/sdk/gitea to latest version (#48)

This commit is contained in:
Lunny Xiao 2019-10-13 15:13:33 +00:00 committed by Gitea
parent 7c024bcd69
commit d1134e8008
39 changed files with 549 additions and 1096 deletions

2
go.mod
View File

@ -3,7 +3,7 @@ module code.gitea.io/tea
go 1.12 go 1.12
require ( require (
code.gitea.io/sdk v0.0.0-20190424055801-13a7bf625b83 code.gitea.io/sdk/gitea v0.0.0-20191013013401-e41e9ea72caa
github.com/go-gitea/yaml v0.0.0-20170812160011-eb3733d160e7 github.com/go-gitea/yaml v0.0.0-20170812160011-eb3733d160e7
github.com/mattn/go-runewidth v0.0.4 // indirect github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/olekukonko/tablewriter v0.0.1 github.com/olekukonko/tablewriter v0.0.1

4
go.sum
View File

@ -1,5 +1,5 @@
code.gitea.io/sdk v0.0.0-20190424055801-13a7bf625b83 h1:wrdvJESj8NgPL4tDGNHGAIDOe/rFE8+gIGDwsvC6MuE= code.gitea.io/sdk/gitea v0.0.0-20191013013401-e41e9ea72caa h1:KgpwNF1StxPXMfCD9M++jvCUPUqHPAbuvQn1q3sWtqw=
code.gitea.io/sdk v0.0.0-20190424055801-13a7bf625b83/go.mod h1:5bZt0dRznpn2JysytQnV0yCru3FwDv9O5G91jo+lDAk= code.gitea.io/sdk/gitea v0.0.0-20191013013401-e41e9ea72caa/go.mod h1:8IxkM1gyiwEjfO0m47bcmr3u3foR15+LoVub43hCHd0=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs= github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=

View File

@ -1,4 +1,5 @@
// Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved.
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -10,6 +11,12 @@ import (
"fmt" "fmt"
) )
// AdminListOrgs lists all orgs
func (c *Client) AdminListOrgs() ([]*Organization, error) {
orgs := make([]*Organization, 0, 10)
return orgs, c.getParsedResponse("GET", "/admin/orgs", nil, nil, &orgs)
}
// AdminCreateOrg create an organization // AdminCreateOrg create an organization
func (c *Client) AdminCreateOrg(user string, opt CreateOrgOption) (*Organization, error) { func (c *Client) AdminCreateOrg(user string, opt CreateOrgOption) (*Organization, error) {
body, err := json.Marshal(&opt) body, err := json.Marshal(&opt)

View File

@ -11,18 +11,20 @@ import (
"fmt" "fmt"
) )
// AdminListUsers lists all users
func (c *Client) AdminListUsers() ([]*User, error) {
users := make([]*User, 0, 10)
return users, c.getParsedResponse("GET", "/admin/users", nil, nil, &users)
}
// CreateUserOption create user options // CreateUserOption create user options
type CreateUserOption struct { type CreateUserOption struct {
SourceID int64 `json:"source_id"` SourceID int64 `json:"source_id"`
LoginName string `json:"login_name"` LoginName string `json:"login_name"`
// required: true Username string `json:"username"`
Username string `json:"username" binding:"Required;AlphaDashDot;MaxSize(40)"` FullName string `json:"full_name"`
FullName string `json:"full_name" binding:"MaxSize(100)"` Email string `json:"email"`
// required: true Password string `json:"password"`
// swagger:strfmt email
Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
// required: true
Password string `json:"password" binding:"Required;MaxSize(255)"`
MustChangePassword *bool `json:"must_change_password"` MustChangePassword *bool `json:"must_change_password"`
SendNotify bool `json:"send_notify"` SendNotify bool `json:"send_notify"`
} }
@ -39,16 +41,14 @@ func (c *Client) AdminCreateUser(opt CreateUserOption) (*User, error) {
// EditUserOption edit user options // EditUserOption edit user options
type EditUserOption struct { type EditUserOption struct {
SourceID int64 `json:"source_id"` SourceID int64 `json:"source_id"`
LoginName string `json:"login_name"` LoginName string `json:"login_name"`
FullName string `json:"full_name" binding:"MaxSize(100)"` FullName string `json:"full_name"`
// required: true Email string `json:"email"`
// swagger:strfmt email Password string `json:"password"`
Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
Password string `json:"password" binding:"MaxSize(255)"`
MustChangePassword *bool `json:"must_change_password"` MustChangePassword *bool `json:"must_change_password"`
Website string `json:"website" binding:"MaxSize(50)"` Website string `json:"website"`
Location string `json:"location" binding:"MaxSize(50)"` Location string `json:"location"`
Active *bool `json:"active"` Active *bool `json:"active"`
Admin *bool `json:"admin"` Admin *bool `json:"admin"`
AllowGitHook *bool `json:"allow_git_hook"` AllowGitHook *bool `json:"allow_git_hook"`
@ -74,7 +74,7 @@ func (c *Client) AdminDeleteUser(user string) error {
return err return err
} }
// AdminCreateUserPublicKey create one user with options // AdminCreateUserPublicKey adds a public key for the user
func (c *Client) AdminCreateUserPublicKey(user string, opt CreateKeyOption) (*PublicKey, error) { func (c *Client) AdminCreateUserPublicKey(user string, opt CreateKeyOption) (*PublicKey, error) {
body, err := json.Marshal(&opt) body, err := json.Marshal(&opt)
if err != nil { if err != nil {
@ -83,3 +83,9 @@ func (c *Client) AdminCreateUserPublicKey(user string, opt CreateKeyOption) (*Pu
key := new(PublicKey) key := new(PublicKey)
return key, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/keys", user), jsonHeader, bytes.NewReader(body), key) return key, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/keys", user), jsonHeader, bytes.NewReader(body), key)
} }
// AdminDeleteUserPublicKey deletes a user's public key
func (c *Client) AdminDeleteUserPublicKey(user string, keyID int) error {
_, err := c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s/keys/%d", user, keyID), nil, nil)
return err
}

View File

@ -14,16 +14,14 @@ import (
) )
// Attachment a generic attachment // Attachment a generic attachment
// swagger:model
type Attachment struct { type Attachment struct {
ID int64 `json:"id"` ID int64 `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Size int64 `json:"size"` Size int64 `json:"size"`
DownloadCount int64 `json:"download_count"` DownloadCount int64 `json:"download_count"`
// swagger:strfmt date-time Created time.Time `json:"created_at"`
Created time.Time `json:"created_at"` UUID string `json:"uuid"`
UUID string `json:"uuid"` DownloadURL string `json:"browser_download_url"`
DownloadURL string `json:"browser_download_url"`
} }
// ListReleaseAttachments list release's attachments // ListReleaseAttachments list release's attachments
@ -69,6 +67,11 @@ func (c *Client) CreateReleaseAttachment(user, repo string, release int64, file
return attachment, err return attachment, err
} }
// EditAttachmentOptions options for editing attachments
type EditAttachmentOptions struct {
Name string `json:"name"`
}
// EditReleaseAttachment updates the given attachment with the given options // EditReleaseAttachment updates the given attachment with the given options
func (c *Client) EditReleaseAttachment(user, repo string, release int64, attachment int64, form EditAttachmentOptions) (*Attachment, error) { func (c *Client) EditReleaseAttachment(user, repo string, release int64, attachment int64, form EditAttachmentOptions) (*Attachment, error) {
body, err := json.Marshal(&form) body, err := json.Marshal(&form)
@ -84,9 +87,3 @@ func (c *Client) DeleteReleaseAttachment(user, repo string, release int64, id in
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, id), nil, nil) _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, id), nil, nil)
return err return err
} }
// EditAttachmentOptions options for editing attachments
// swagger:model
type EditAttachmentOptions struct {
Name string `json:"name"`
}

View File

@ -14,6 +14,8 @@ import (
"strings" "strings"
) )
var jsonHeader = http.Header{"content-type": []string{"application/json"}}
// Version return the library version // Version return the library version
func Version() string { func Version() string {
return "0.12.3" return "0.12.3"

View File

@ -1,14 +0,0 @@
// Copyright 2019 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
// GitBlobResponse represents a git blob
type GitBlobResponse struct {
Content string `json:"content"`
Encoding string `json:"encoding"`
URL string `json:"url"`
SHA string `json:"sha"`
Size int64 `json:"size"`
}

View File

@ -17,11 +17,8 @@ type GitHook struct {
Content string `json:"content,omitempty"` Content string `json:"content,omitempty"`
} }
// GitHookList represents a list of Git hooks
type GitHookList []*GitHook
// ListRepoGitHooks list all the Git hooks of one repository // ListRepoGitHooks list all the Git hooks of one repository
func (c *Client) ListRepoGitHooks(user, repo string) (GitHookList, error) { func (c *Client) ListRepoGitHooks(user, repo string) ([]*GitHook, error) {
hooks := make([]*GitHook, 0, 10) hooks := make([]*GitHook, 0, 10)
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks/git", user, repo), nil, nil, &hooks) return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks/git", user, repo), nil, nil, &hooks)
} }

3
vendor/code.gitea.io/sdk/gitea/go.mod generated vendored Normal file
View File

@ -0,0 +1,3 @@
module code.gitea.io/sdk/gitea
go 1.12

0
vendor/code.gitea.io/sdk/gitea/go.sum generated vendored Normal file
View File

View File

@ -8,42 +8,30 @@ package gitea
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"strings"
"time" "time"
) )
var (
// ErrInvalidReceiveHook FIXME
ErrInvalidReceiveHook = errors.New("Invalid JSON payload received over webhook")
)
// Hook a hook is a web hook when one repository changed // Hook a hook is a web hook when one repository changed
type Hook struct { type Hook struct {
ID int64 `json:"id"` ID int64 `json:"id"`
Type string `json:"type"` Type string `json:"type"`
URL string `json:"-"` URL string `json:"-"`
Config map[string]string `json:"config"` Config map[string]string `json:"config"`
Events []string `json:"events"` Events []string `json:"events"`
Active bool `json:"active"` Active bool `json:"active"`
// swagger:strfmt date-time Updated time.Time `json:"updated_at"`
Updated time.Time `json:"updated_at"` Created time.Time `json:"created_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 // ListOrgHooks list all the hooks of one organization
func (c *Client) ListOrgHooks(org string) (HookList, error) { func (c *Client) ListOrgHooks(org string) ([]*Hook, error) {
hooks := make([]*Hook, 0, 10) hooks := make([]*Hook, 0, 10)
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/hooks", org), nil, nil, &hooks) return hooks, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/hooks", org), nil, nil, &hooks)
} }
// ListRepoHooks list all the hooks of one repository // ListRepoHooks list all the hooks of one repository
func (c *Client) ListRepoHooks(user, repo string) (HookList, error) { func (c *Client) ListRepoHooks(user, repo string) ([]*Hook, error) {
hooks := make([]*Hook, 0, 10) hooks := make([]*Hook, 0, 10)
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), nil, nil, &hooks) return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), nil, nil, &hooks)
} }
@ -62,14 +50,11 @@ func (c *Client) GetRepoHook(user, repo string, id int64) (*Hook, error) {
// CreateHookOption options when create a hook // CreateHookOption options when create a hook
type CreateHookOption struct { type CreateHookOption struct {
// required: true Type string `json:"type"`
// enum: gitea,gogs,slack,discord Config map[string]string `json:"config"`
Type string `json:"type" binding:"Required"` Events []string `json:"events"`
// required: true BranchFilter string `json:"branch_filter"`
Config map[string]string `json:"config" binding:"Required"` Active bool `json:"active"`
Events []string `json:"events"`
// default: false
Active bool `json:"active"`
} }
// CreateOrgHook create one hook for an organization, with options // CreateOrgHook create one hook for an organization, with options
@ -94,9 +79,10 @@ func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook,
// EditHookOption options when modify one hook // EditHookOption options when modify one hook
type EditHookOption struct { type EditHookOption struct {
Config map[string]string `json:"config"` Config map[string]string `json:"config"`
Events []string `json:"events"` Events []string `json:"events"`
Active *bool `json:"active"` BranchFilter string `json:"branch_filter"`
Active *bool `json:"active"`
} }
// EditOrgHook modify one hook of an organization, with hook id and options // EditOrgHook modify one hook of an organization, with hook id and options
@ -121,7 +107,7 @@ func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) e
// DeleteOrgHook delete one hook from an organization, with hook id // DeleteOrgHook delete one hook from an organization, with hook id
func (c *Client) DeleteOrgHook(org string, id int64) error { func (c *Client) DeleteOrgHook(org string, id int64) error {
_, err := c.getResponse("DELETE", fmt.Sprintf("/org/%s/hooks/%d", org, id), nil, nil) _, err := c.getResponse("DELETE", fmt.Sprintf("/orgs/%s/hooks/%d", org, id), nil, nil)
return err return err
} }
@ -130,414 +116,3 @@ 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) _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), nil, nil)
return err 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"`
Added []string `json:"added"`
Removed []string `json:"removed"`
Modified []string `json:"modified"`
}
// 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 = &DeletePayload{}
_ Payloader = &ForkPayload{}
_ Payloader = &PushPayload{}
_ Payloader = &IssuePayload{}
_ Payloader = &IssueCommentPayload{}
_ Payloader = &PullRequestPayload{}
_ Payloader = &RepositoryPayload{}
_ Payloader = &ReleasePayload{}
)
// _________ __
// \_ ___ \_______ ____ _____ _/ |_ ____
// / \ \/\_ __ \_/ __ \\__ \\ __\/ __ \
// \ \____| | \/\ ___/ / __ \| | \ ___/
// \______ /|__| \___ >____ /__| \___ >
// \/ \/ \/ \/
// 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 modifies the secret of the CreatePayload
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
}
// ________ .__ __
// \______ \ ____ | | _____/ |_ ____
// | | \_/ __ \| | _/ __ \ __\/ __ \
// | ` \ ___/| |_\ ___/| | \ ___/
// /_______ /\___ >____/\___ >__| \___ >
// \/ \/ \/ \/
// PusherType define the type to push
type PusherType string
// describe all the PusherTypes
const (
PusherTypeUser PusherType = "user"
)
// DeletePayload represents delete payload
type DeletePayload struct {
Secret string `json:"secret"`
Ref string `json:"ref"`
RefType string `json:"ref_type"`
PusherType PusherType `json:"pusher_type"`
Repo *Repository `json:"repository"`
Sender *User `json:"sender"`
}
// SetSecret modifies the secret of the DeletePayload
func (p *DeletePayload) SetSecret(secret string) {
p.Secret = secret
}
// JSONPayload implements Payload
func (p *DeletePayload) JSONPayload() ([]byte, error) {
return json.MarshalIndent(p, "", " ")
}
// ___________ __
// \_ _____/__________| | __
// | __)/ _ \_ __ \ |/ /
// | \( <_> ) | \/ <
// \___ / \____/|__| |__|_ \
// \/ \/
// ForkPayload represents fork payload
type ForkPayload struct {
Secret string `json:"secret"`
Forkee *Repository `json:"forkee"`
Repo *Repository `json:"repository"`
Sender *User `json:"sender"`
}
// SetSecret modifies the secret of the ForkPayload
func (p *ForkPayload) SetSecret(secret string) {
p.Secret = secret
}
// JSONPayload implements Payload
func (p *ForkPayload) JSONPayload() ([]byte, error) {
return json.MarshalIndent(p, "", " ")
}
// HookIssueCommentAction defines hook issue comment action
type HookIssueCommentAction string
// all issue comment actions
const (
HookIssueCommentCreated HookIssueCommentAction = "created"
HookIssueCommentEdited HookIssueCommentAction = "edited"
HookIssueCommentDeleted HookIssueCommentAction = "deleted"
)
// IssueCommentPayload represents a payload information of issue comment event.
type IssueCommentPayload struct {
Secret string `json:"secret"`
Action HookIssueCommentAction `json:"action"`
Issue *Issue `json:"issue"`
Comment *Comment `json:"comment"`
Changes *ChangesPayload `json:"changes,omitempty"`
Repository *Repository `json:"repository"`
Sender *User `json:"sender"`
}
// SetSecret modifies the secret of the IssueCommentPayload
func (p *IssueCommentPayload) SetSecret(secret string) {
p.Secret = secret
}
// JSONPayload implements Payload
func (p *IssueCommentPayload) JSONPayload() ([]byte, error) {
return json.MarshalIndent(p, "", " ")
}
// __________ .__
// \______ \ ____ | | ____ _____ ______ ____
// | _// __ \| | _/ __ \\__ \ / ___// __ \
// | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
// |____|_ /\___ >____/\___ >____ /____ >\___ >
// \/ \/ \/ \/ \/ \/
// HookReleaseAction defines hook release action type
type HookReleaseAction string
// all release actions
const (
HookReleasePublished HookReleaseAction = "published"
HookReleaseUpdated HookReleaseAction = "updated"
HookReleaseDeleted HookReleaseAction = "deleted"
)
// ReleasePayload represents a payload information of release event.
type ReleasePayload struct {
Secret string `json:"secret"`
Action HookReleaseAction `json:"action"`
Release *Release `json:"release"`
Repository *Repository `json:"repository"`
Sender *User `json:"sender"`
}
// SetSecret modifies the secret of the ReleasePayload
func (p *ReleasePayload) SetSecret(secret string) {
p.Secret = secret
}
// JSONPayload implements Payload
func (p *ReleasePayload) JSONPayload() ([]byte, error) {
return json.MarshalIndent(p, "", " ")
}
// __________ .__
// \______ \__ __ _____| |__
// | ___/ | \/ ___/ | \
// | | | | /\___ \| 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"`
HeadCommit *PayloadCommit `json:"head_commit"`
Repo *Repository `json:"repository"`
Pusher *User `json:"pusher"`
Sender *User `json:"sender"`
}
// SetSecret modifies the secret of the PushPayload
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 modifies the secret of the RepositoryPayload
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, "", " ")
}

View File

@ -1,4 +1,5 @@
// Copyright 2016 The Gogs Authors. All rights reserved. // Copyright 2016 The Gogs Authors. All rights reserved.
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -11,16 +12,6 @@ import (
"time" "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 // PullRequestMeta PR info if an issue is a PR
type PullRequestMeta struct { type PullRequestMeta struct {
HasMerged bool `json:"merged"` HasMerged bool `json:"merged"`
@ -28,33 +19,26 @@ type PullRequestMeta struct {
} }
// Issue represents an issue in a repository // Issue represents an issue in a repository
// swagger:model
type Issue struct { type Issue struct {
ID int64 `json:"id"` ID int64 `json:"id"`
URL string `json:"url"` URL string `json:"url"`
Index int64 `json:"number"` Index int64 `json:"number"`
Poster *User `json:"user"` Poster *User `json:"user"`
Title string `json:"title"` OriginalAuthor string `json:"original_author"`
Body string `json:"body"` OriginalAuthorID int64 `json:"original_author_id"`
Labels []*Label `json:"labels"` Title string `json:"title"`
Milestone *Milestone `json:"milestone"` Body string `json:"body"`
Assignee *User `json:"assignee"` Labels []*Label `json:"labels"`
Assignees []*User `json:"assignees"` Milestone *Milestone `json:"milestone"`
Assignee *User `json:"assignee"`
Assignees []*User `json:"assignees"`
// Whether the issue is open or closed // Whether the issue is open or closed
// State StateType `json:"state"`
// type: string Comments int `json:"comments"`
// enum: open,closed Created time.Time `json:"created_at"`
State StateType `json:"state"` Updated time.Time `json:"updated_at"`
Comments int `json:"comments"` Closed *time.Time `json:"closed_at"`
// swagger:strfmt date-time Deadline *time.Time `json:"due_date"`
Created time.Time `json:"created_at"`
// swagger:strfmt date-time
Updated time.Time `json:"updated_at"`
// swagger:strfmt date-time
Closed *time.Time `json:"closed_at"`
// swagger:strfmt date-time
Deadline *time.Time `json:"due_date"`
PullRequest *PullRequestMeta `json:"pull_request"` PullRequest *PullRequestMeta `json:"pull_request"`
} }
@ -90,14 +74,12 @@ func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, error) {
// CreateIssueOption options to create one issue // CreateIssueOption options to create one issue
type CreateIssueOption struct { type CreateIssueOption struct {
// required:true Title string `json:"title"`
Title string `json:"title" binding:"Required"`
Body string `json:"body"` Body string `json:"body"`
// username of assignee // username of assignee
Assignee string `json:"assignee"` Assignee string `json:"assignee"`
Assignees []string `json:"assignees"` Assignees []string `json:"assignees"`
// swagger:strfmt date-time Deadline *time.Time `json:"due_date"`
Deadline *time.Time `json:"due_date"`
// milestone id // milestone id
Milestone int64 `json:"milestone"` Milestone int64 `json:"milestone"`
// list of label ids // list of label ids
@ -118,14 +100,13 @@ func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue,
// EditIssueOption options for editing an issue // EditIssueOption options for editing an issue
type EditIssueOption struct { type EditIssueOption struct {
Title string `json:"title"` Title string `json:"title"`
Body *string `json:"body"` Body *string `json:"body"`
Assignee *string `json:"assignee"` Assignee *string `json:"assignee"`
Assignees []string `json:"assignees"` Assignees []string `json:"assignees"`
Milestone *int64 `json:"milestone"` Milestone *int64 `json:"milestone"`
State *string `json:"state"` State *string `json:"state"`
// swagger:strfmt date-time Deadline *time.Time `json:"due_date"`
Deadline *time.Time `json:"due_date"`
} }
// EditIssue modify an existing issue for a given repository // EditIssue modify an existing issue for a given repository
@ -154,23 +135,3 @@ func (c *Client) StopIssueStopWatch(owner, repo string, index int64) error {
jsonHeader, nil) jsonHeader, nil)
return err return err
} }
// EditDeadlineOption options for creating a deadline
type EditDeadlineOption struct {
// required:true
// swagger:strfmt date-time
Deadline *time.Time `json:"due_date"`
}
// IssueDeadline represents an issue deadline
// swagger:model
type IssueDeadline struct {
// swagger:strfmt date-time
Deadline *time.Time `json:"due_date"`
}
// EditPriorityOption options for updating priority
type EditPriorityOption struct {
// required:true
Priority int `json:"priority"`
}

View File

@ -13,16 +13,16 @@ import (
// Comment represents a comment on a commit or issue // Comment represents a comment on a commit or issue
type Comment struct { type Comment struct {
ID int64 `json:"id"` ID int64 `json:"id"`
HTMLURL string `json:"html_url"` HTMLURL string `json:"html_url"`
PRURL string `json:"pull_request_url"` PRURL string `json:"pull_request_url"`
IssueURL string `json:"issue_url"` IssueURL string `json:"issue_url"`
Poster *User `json:"user"` Poster *User `json:"user"`
Body string `json:"body"` OriginalAuthor string `json:"original_author"`
// swagger:strfmt date-time OriginalAuthorID int64 `json:"original_author_id"`
Created time.Time `json:"created_at"` Body string `json:"body"`
// swagger:strfmt date-time Created time.Time `json:"created_at"`
Updated time.Time `json:"updated_at"` Updated time.Time `json:"updated_at"`
} }
// ListIssueComments list comments on an issue. // ListIssueComments list comments on an issue.
@ -39,8 +39,7 @@ func (c *Client) ListRepoIssueComments(owner, repo string) ([]*Comment, error) {
// CreateIssueCommentOption options for creating a comment on an issue // CreateIssueCommentOption options for creating a comment on an issue
type CreateIssueCommentOption struct { type CreateIssueCommentOption struct {
// required:true Body string `json:"body"`
Body string `json:"body" binding:"Required"`
} }
// CreateIssueComment create comment on an issue. // CreateIssueComment create comment on an issue.
@ -55,22 +54,21 @@ func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateI
// EditIssueCommentOption options for editing a comment // EditIssueCommentOption options for editing a comment
type EditIssueCommentOption struct { type EditIssueCommentOption struct {
// required: true Body string `json:"body"`
Body string `json:"body" binding:"Required"`
} }
// EditIssueComment edits an issue comment. // EditIssueComment edits an issue comment.
func (c *Client) EditIssueComment(owner, repo string, index, commentID int64, opt EditIssueCommentOption) (*Comment, error) { func (c *Client) EditIssueComment(owner, repo string, commentID int64, opt EditIssueCommentOption) (*Comment, error) {
body, err := json.Marshal(&opt) body, err := json.Marshal(&opt)
if err != nil { if err != nil {
return nil, err return nil, err
} }
comment := new(Comment) 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) return comment, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/comments/%d", owner, repo, commentID), jsonHeader, bytes.NewReader(body), comment)
} }
// DeleteIssueComment deletes an issue comment. // DeleteIssueComment deletes an issue comment.
func (c *Client) DeleteIssueComment(owner, repo string, index, commentID int64) error { func (c *Client) DeleteIssueComment(owner, repo string, commentID int64) error {
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/comments/%d", owner, repo, index, commentID), nil, nil) _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/comments/%d", owner, repo, commentID), nil, nil)
return err return err
} }

View File

@ -11,13 +11,13 @@ import (
) )
// Label a label to an issue or a pr // Label a label to an issue or a pr
// swagger:model
type Label struct { type Label struct {
ID int64 `json:"id"` ID int64 `json:"id"`
Name string `json:"name"` Name string `json:"name"`
// example: 00aabb // example: 00aabb
Color string `json:"color"` Color string `json:"color"`
URL string `json:"url"` Description string `json:"description"`
URL string `json:"url"`
} }
// ListRepoLabels list labels of one repository // ListRepoLabels list labels of one repository
@ -35,11 +35,10 @@ func (c *Client) GetRepoLabel(owner, repo string, id int64) (*Label, error) {
// CreateLabelOption options for creating a label // CreateLabelOption options for creating a label
type CreateLabelOption struct { type CreateLabelOption struct {
// required:true Name string `json:"name"`
Name string `json:"name" binding:"Required"`
// required:true
// example: #00aabb // example: #00aabb
Color string `json:"color" binding:"Required;Size(7)"` Color string `json:"color"`
Description string `json:"description"`
} }
// CreateLabel create one label of repository // CreateLabel create one label of repository
@ -55,8 +54,9 @@ func (c *Client) CreateLabel(owner, repo string, opt CreateLabelOption) (*Label,
// EditLabelOption options for editing a label // EditLabelOption options for editing a label
type EditLabelOption struct { type EditLabelOption struct {
Name *string `json:"name"` Name *string `json:"name"`
Color *string `json:"color"` Color *string `json:"color"`
Description *string `json:"description"`
} }
// EditLabel modify one label with options // EditLabel modify one label with options
@ -76,18 +76,18 @@ func (c *Client) DeleteLabel(owner, repo string, id int64) error {
return err 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 // GetIssueLabels get labels of one issue via issue id
func (c *Client) GetIssueLabels(owner, repo string, index int64) ([]*Label, error) { func (c *Client) GetIssueLabels(owner, repo string, index int64) ([]*Label, error) {
labels := make([]*Label, 0, 5) labels := make([]*Label, 0, 5)
return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil, &labels) return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil, &labels)
} }
// IssueLabelsOption a collection of labels
type IssueLabelsOption struct {
// list of label IDs
Labels []int64 `json:"labels"`
}
// AddIssueLabels add one or more labels to one issue // AddIssueLabels add one or more labels to one issue
func (c *Client) AddIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) { func (c *Client) AddIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) {
body, err := json.Marshal(&opt) body, err := json.Marshal(&opt)

View File

@ -11,18 +11,28 @@ import (
"time" "time"
) )
// StateType issue state type
type StateType string
const (
// StateOpen pr is opend
StateOpen StateType = "open"
// StateClosed pr is closed
StateClosed StateType = "closed"
// StateAll is all
StateAll StateType = "all"
)
// Milestone milestone is a collection of issues on one repository // Milestone milestone is a collection of issues on one repository
type Milestone struct { type Milestone struct {
ID int64 `json:"id"` ID int64 `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Description string `json:"description"` Description string `json:"description"`
State StateType `json:"state"` State StateType `json:"state"`
OpenIssues int `json:"open_issues"` OpenIssues int `json:"open_issues"`
ClosedIssues int `json:"closed_issues"` ClosedIssues int `json:"closed_issues"`
// swagger:strfmt date-time Closed *time.Time `json:"closed_at"`
Closed *time.Time `json:"closed_at"` Deadline *time.Time `json:"due_on"`
// swagger:strfmt date-time
Deadline *time.Time `json:"due_on"`
} }
// ListRepoMilestones list all the milestones of one repository // ListRepoMilestones list all the milestones of one repository
@ -39,10 +49,9 @@ func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, error)
// CreateMilestoneOption options for creating a milestone // CreateMilestoneOption options for creating a milestone
type CreateMilestoneOption struct { type CreateMilestoneOption struct {
Title string `json:"title"` Title string `json:"title"`
Description string `json:"description"` Description string `json:"description"`
// swagger:strfmt date-time Deadline *time.Time `json:"due_on"`
Deadline *time.Time `json:"due_on"`
} }
// CreateMilestone create one milestone with options // CreateMilestone create one milestone with options

View File

@ -13,8 +13,7 @@ import (
// TrackedTime worked time for an issue / pr // TrackedTime worked time for an issue / pr
type TrackedTime struct { type TrackedTime struct {
ID int64 `json:"id"` ID int64 `json:"id"`
// swagger:strfmt date-time
Created time.Time `json:"created"` Created time.Time `json:"created"`
// Time in seconds // Time in seconds
Time int64 `json:"time"` Time int64 `json:"time"`
@ -22,32 +21,28 @@ type TrackedTime struct {
IssueID int64 `json:"issue_id"` IssueID int64 `json:"issue_id"`
} }
// TrackedTimes represent a list of tracked times
type TrackedTimes []*TrackedTime
// GetUserTrackedTimes list tracked times of a user // GetUserTrackedTimes list tracked times of a user
func (c *Client) GetUserTrackedTimes(owner, repo, user string) (TrackedTimes, error) { func (c *Client) GetUserTrackedTimes(owner, repo, user string) ([]*TrackedTime, error) {
times := make(TrackedTimes, 0, 10) times := make([]*TrackedTime, 0, 10)
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times/%s", owner, repo, user), nil, nil, &times) return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times/%s", owner, repo, user), nil, nil, &times)
} }
// GetRepoTrackedTimes list tracked times of a repository // GetRepoTrackedTimes list tracked times of a repository
func (c *Client) GetRepoTrackedTimes(owner, repo string) (TrackedTimes, error) { func (c *Client) GetRepoTrackedTimes(owner, repo string) ([]*TrackedTime, error) {
times := make(TrackedTimes, 0, 10) times := make([]*TrackedTime, 0, 10)
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times", owner, repo), nil, nil, &times) return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times", owner, repo), nil, nil, &times)
} }
// GetMyTrackedTimes list tracked times of the current user // GetMyTrackedTimes list tracked times of the current user
func (c *Client) GetMyTrackedTimes() (TrackedTimes, error) { func (c *Client) GetMyTrackedTimes() ([]*TrackedTime, error) {
times := make(TrackedTimes, 0, 10) times := make([]*TrackedTime, 0, 10)
return times, c.getParsedResponse("GET", "/user/times", nil, nil, &times) return times, c.getParsedResponse("GET", "/user/times", nil, nil, &times)
} }
// AddTimeOption options for adding time to an issue // AddTimeOption options for adding time to an issue
type AddTimeOption struct { type AddTimeOption struct {
// time in seconds // time in seconds
// required: true Time int64 `json:"time"`
Time int64 `json:"time" binding:"Required"`
} }
// AddTime adds time to issue with the given index // AddTime adds time to issue with the given index
@ -62,7 +57,7 @@ func (c *Client) AddTime(owner, repo string, index int64, opt AddTimeOption) (*T
} }
// ListTrackedTimes get tracked times of one issue via issue id // ListTrackedTimes get tracked times of one issue via issue id
func (c *Client) ListTrackedTimes(owner, repo string, index int64) (TrackedTimes, error) { func (c *Client) ListTrackedTimes(owner, repo string, index int64) ([]*TrackedTime, error) {
times := make(TrackedTimes, 0, 5) times := make([]*TrackedTime, 0, 5)
return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index), nil, nil, &times) return times, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index), nil, nil, &times)
} }

View File

@ -1,65 +0,0 @@
// 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"`
}

View File

@ -4,49 +4,10 @@
package gitea 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 // ServerVersion returns the version of the server
func (c *Client) ServerVersion() (string, error) { func (c *Client) ServerVersion() (string, error) {
v := ServerVersion{} var v = struct {
Version string `json:"version"`
}{}
return v.Version, c.getParsedResponse("GET", "/api/v1/version", nil, nil, &v) return v.Version, c.getParsedResponse("GET", "/api/v1/version", nil, nil, &v)
} }

View File

@ -1,4 +1,5 @@
// Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved.
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -12,14 +13,14 @@ import (
// Organization represents an organization // Organization represents an organization
type Organization struct { type Organization struct {
ID int64 `json:"id"` ID int64 `json:"id"`
UserName string `json:"username"` UserName string `json:"username"`
FullName string `json:"full_name"` FullName string `json:"full_name"`
AvatarURL string `json:"avatar_url"` AvatarURL string `json:"avatar_url"`
Description string `json:"description"` Description string `json:"description"`
Website string `json:"website"` Website string `json:"website"`
Location string `json:"location"` Location string `json:"location"`
Visibility VisibleType `json:"visibility"` Visibility string `json:"visibility"`
} }
// ListMyOrgs list all of current user's organizations // ListMyOrgs list all of current user's organizations
@ -42,13 +43,24 @@ func (c *Client) GetOrg(orgname string) (*Organization, error) {
// CreateOrgOption options for creating an organization // CreateOrgOption options for creating an organization
type CreateOrgOption struct { type CreateOrgOption struct {
// required: true UserName string `json:"username"`
UserName string `json:"username" binding:"Required"` FullName string `json:"full_name"`
FullName string `json:"full_name"` Description string `json:"description"`
Description string `json:"description"` Website string `json:"website"`
Website string `json:"website"` Location string `json:"location"`
Location string `json:"location"` // possible values are `public` (default), `limited` or `private`
Visibility VisibleType `json:"visibility"` // enum: public,limited,private
Visibility string `json:"visibility"`
}
// CreateOrg creates an organization
func (c *Client) CreateOrg(opt CreateOrgOption) (*Organization, error) {
body, err := json.Marshal(&opt)
if err != nil {
return nil, err
}
org := new(Organization)
return org, c.getParsedResponse("POST", "/orgs", jsonHeader, bytes.NewReader(body), org)
} }
// EditOrgOption options for editing an organization // EditOrgOption options for editing an organization
@ -57,6 +69,9 @@ type EditOrgOption struct {
Description string `json:"description"` Description string `json:"description"`
Website string `json:"website"` Website string `json:"website"`
Location string `json:"location"` Location string `json:"location"`
// possible values are `public`, `limited` or `private`
// enum: public,limited,private
Visibility string `json:"visibility"`
} }
// EditOrg modify one organization via options // EditOrg modify one organization via options
@ -68,3 +83,9 @@ func (c *Client) EditOrg(orgname string, opt EditOrgOption) error {
_, err = c.getResponse("PATCH", fmt.Sprintf("/orgs/%s", orgname), jsonHeader, bytes.NewReader(body)) _, err = c.getResponse("PATCH", fmt.Sprintf("/orgs/%s", orgname), jsonHeader, bytes.NewReader(body))
return err return err
} }
// DeleteOrg deletes an organization
func (c *Client) DeleteOrg(orgname string) error {
_, err := c.getResponse("DELETE", fmt.Sprintf("/orgs/%s", orgname), nil, nil)
return err
}

View File

@ -12,7 +12,7 @@ import (
// AddOrgMembershipOption add user to organization options // AddOrgMembershipOption add user to organization options
type AddOrgMembershipOption struct { type AddOrgMembershipOption struct {
Role string `json:"role" binding:"Required"` Role string `json:"role"`
} }
// AddOrgMembership add some one to an organization's member // AddOrgMembership add some one to an organization's member

View File

@ -1,10 +1,15 @@
// Copyright 2016 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved.
// Copyright 2018 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package gitea package gitea
import (
"bytes"
"encoding/json"
"fmt"
)
// Team represents a team in an organization // Team represents a team in an organization
type Team struct { type Team struct {
ID int64 `json:"id"` ID int64 `json:"id"`
@ -13,28 +18,112 @@ type Team struct {
Organization *Organization `json:"organization"` Organization *Organization `json:"organization"`
// enum: none,read,write,admin,owner // enum: none,read,write,admin,owner
Permission string `json:"permission"` Permission string `json:"permission"`
// enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki // example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.ext_wiki"]
Units []string `json:"units"` Units []string `json:"units"`
} }
// ListOrgTeams lists all teams of an organization
func (c *Client) ListOrgTeams(org string) ([]*Team, error) {
teams := make([]*Team, 0, 10)
return teams, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/teams", org), nil, nil, &teams)
}
// ListMyTeams lists all the teams of the current user
func (c *Client) ListMyTeams() ([]*Team, error) {
teams := make([]*Team, 0, 10)
return teams, c.getParsedResponse("GET", "/user/teams", nil, nil, &teams)
}
// GetTeam gets a team by ID
func (c *Client) GetTeam(id int64) (*Team, error) {
t := new(Team)
return t, c.getParsedResponse("GET", fmt.Sprintf("/teams/%d", id), nil, nil, t)
}
// CreateTeamOption options for creating a team // CreateTeamOption options for creating a team
type CreateTeamOption struct { type CreateTeamOption struct {
// required: true Name string `json:"name"`
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"` Description string `json:"description"`
Description string `json:"description" binding:"MaxSize(255)"`
// enum: read,write,admin // enum: read,write,admin
Permission string `json:"permission"` Permission string `json:"permission"`
// enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki // example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.ext_wiki"]
Units []string `json:"units"` Units []string `json:"units"`
} }
// CreateTeam creates a team for an organization
func (c *Client) CreateTeam(org string, opt CreateTeamOption) (*Team, error) {
body, err := json.Marshal(&opt)
if err != nil {
return nil, err
}
t := new(Team)
return t, c.getParsedResponse("POST", fmt.Sprintf("/orgs/%s/teams", org), jsonHeader, bytes.NewReader(body), t)
}
// EditTeamOption options for editing a team // EditTeamOption options for editing a team
type EditTeamOption struct { type EditTeamOption struct {
// required: true Name string `json:"name"`
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"` Description string `json:"description"`
Description string `json:"description" binding:"MaxSize(255)"`
// enum: read,write,admin // enum: read,write,admin
Permission string `json:"permission"` Permission string `json:"permission"`
// enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki // example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.ext_wiki"]
Units []string `json:"units"` Units []string `json:"units"`
} }
// EditTeam edits a team of an organization
func (c *Client) EditTeam(id int64, opt EditTeamOption) error {
body, err := json.Marshal(&opt)
if err != nil {
return err
}
_, err = c.getResponse("PATCH", fmt.Sprintf("/teams/%d", id), jsonHeader, bytes.NewReader(body))
return err
}
// DeleteTeam deletes a team of an organization
func (c *Client) DeleteTeam(id int64) error {
_, err := c.getResponse("DELETE", fmt.Sprintf("/teams/%d", id), nil, nil)
return err
}
// ListTeamMembers lists all members of a team
func (c *Client) ListTeamMembers(id int64) ([]*User, error) {
members := make([]*User, 0, 10)
return members, c.getParsedResponse("GET", fmt.Sprintf("/teams/%d/members", id), nil, nil, &members)
}
// GetTeamMember gets a member of a team
func (c *Client) GetTeamMember(id int64, user string) (*User, error) {
m := new(User)
return m, c.getParsedResponse("GET", fmt.Sprintf("/teams/%d/members/%s", id, user), nil, nil, m)
}
// AddTeamMember adds a member to a team
func (c *Client) AddTeamMember(id int64, user string) error {
_, err := c.getResponse("PUT", fmt.Sprintf("/teams/%d/members/%s", id, user), nil, nil)
return err
}
// RemoveTeamMember removes a member from a team
func (c *Client) RemoveTeamMember(id int64, user string) error {
_, err := c.getResponse("DELETE", fmt.Sprintf("/teams/%d/members/%s", id, user), nil, nil)
return err
}
// ListTeamRepositories lists all repositories of a team
func (c *Client) ListTeamRepositories(id int64) ([]*Repository, error) {
repos := make([]*Repository, 0, 10)
return repos, c.getParsedResponse("GET", fmt.Sprintf("/teams/%d/repos", id), nil, nil, &repos)
}
// AddTeamRepository adds a repository to a team
func (c *Client) AddTeamRepository(id int64, org, repo string) error {
_, err := c.getResponse("PUT", fmt.Sprintf("/teams/%d/repos/%s/%s", id, org, repo), nil, nil)
return err
}
// RemoveTeamRepository removes a repository from a team
func (c *Client) RemoveTeamRepository(id int64, org, repo string) error {
_, err := c.getResponse("DELETE", fmt.Sprintf("/teams/%d/repos/%s/%s", id, org, repo), nil, nil)
return err
}

View File

@ -18,28 +18,6 @@ const (
VisibleTypePrivate VisibleTypePrivate
) )
// VisibilityModes is a map of org Visibility types
var VisibilityModes = map[string]VisibleType{
"public": VisibleTypePublic,
"limited": VisibleTypeLimited,
"private": VisibleTypePrivate,
}
// IsPublic returns true if VisibleType is public
func (vt VisibleType) IsPublic() bool {
return vt == VisibleTypePublic
}
// IsLimited returns true if VisibleType is limited
func (vt VisibleType) IsLimited() bool {
return vt == VisibleTypeLimited
}
// IsPrivate returns true if VisibleType is private
func (vt VisibleType) IsPrivate() bool {
return vt == VisibleTypePrivate
}
// ExtractKeysFromMapString provides a slice of keys from map // ExtractKeysFromMapString provides a slice of keys from map
func ExtractKeysFromMapString(in map[string]VisibleType) (keys []string) { func ExtractKeysFromMapString(in map[string]VisibleType) (keys []string) {
for k := range in { for k := range in {

View File

@ -11,6 +11,15 @@ import (
"time" "time"
) )
// 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"`
}
// PullRequest represents a pull request // PullRequest represents a pull request
type PullRequest struct { type PullRequest struct {
ID int64 `json:"id"` ID int64 `json:"id"`
@ -30,9 +39,8 @@ type PullRequest struct {
DiffURL string `json:"diff_url"` DiffURL string `json:"diff_url"`
PatchURL string `json:"patch_url"` PatchURL string `json:"patch_url"`
Mergeable bool `json:"mergeable"` Mergeable bool `json:"mergeable"`
HasMerged bool `json:"merged"` HasMerged bool `json:"merged"`
// swagger:strfmt date-time
Merged *time.Time `json:"merged_at"` Merged *time.Time `json:"merged_at"`
MergedCommitID *string `json:"merge_commit_sha"` MergedCommitID *string `json:"merge_commit_sha"`
MergedBy *User `json:"merged_by"` MergedBy *User `json:"merged_by"`
@ -41,24 +49,10 @@ type PullRequest struct {
Head *PRBranchInfo `json:"head"` Head *PRBranchInfo `json:"head"`
MergeBase string `json:"merge_base"` MergeBase string `json:"merge_base"`
// swagger:strfmt date-time
Deadline *time.Time `json:"due_date"` Deadline *time.Time `json:"due_date"`
Created *time.Time `json:"created_at"`
// swagger:strfmt date-time Updated *time.Time `json:"updated_at"`
Created *time.Time `json:"created_at"` Closed *time.Time `json:"closed_at"`
// swagger:strfmt date-time
Updated *time.Time `json:"updated_at"`
// swagger:strfmt date-time
Closed *time.Time `json:"closed_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 // ListPullRequestsOptions options for listing pull requests
@ -85,16 +79,15 @@ func (c *Client) GetPullRequest(owner, repo string, index int64) (*PullRequest,
// CreatePullRequestOption options when creating a pull request // CreatePullRequestOption options when creating a pull request
type CreatePullRequestOption struct { type CreatePullRequestOption struct {
Head string `json:"head" binding:"Required"` Head string `json:"head"`
Base string `json:"base" binding:"Required"` Base string `json:"base"`
Title string `json:"title" binding:"Required"` Title string `json:"title"`
Body string `json:"body"` Body string `json:"body"`
Assignee string `json:"assignee"` Assignee string `json:"assignee"`
Assignees []string `json:"assignees"` Assignees []string `json:"assignees"`
Milestone int64 `json:"milestone"` Milestone int64 `json:"milestone"`
Labels []int64 `json:"labels"` Labels []int64 `json:"labels"`
// swagger:strfmt date-time Deadline *time.Time `json:"due_date"`
Deadline *time.Time `json:"due_date"`
} }
// CreatePullRequest create pull request with options // CreatePullRequest create pull request with options
@ -110,15 +103,14 @@ func (c *Client) CreatePullRequest(owner, repo string, opt CreatePullRequestOpti
// EditPullRequestOption options when modify pull request // EditPullRequestOption options when modify pull request
type EditPullRequestOption struct { type EditPullRequestOption struct {
Title string `json:"title"` Title string `json:"title"`
Body string `json:"body"` Body string `json:"body"`
Assignee string `json:"assignee"` Assignee string `json:"assignee"`
Assignees []string `json:"assignees"` Assignees []string `json:"assignees"`
Milestone int64 `json:"milestone"` Milestone int64 `json:"milestone"`
Labels []int64 `json:"labels"` Labels []int64 `json:"labels"`
State *string `json:"state"` State *string `json:"state"`
// swagger:strfmt date-time Deadline *time.Time `json:"due_date"`
Deadline *time.Time `json:"due_date"`
} }
// EditPullRequest modify pull request with PR id and options // EditPullRequest modify pull request with PR id and options
@ -128,7 +120,7 @@ func (c *Client) EditPullRequest(owner, repo string, index int64, opt EditPullRe
return nil, err return nil, err
} }
pr := new(PullRequest) pr := new(PullRequest)
return pr, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), return pr, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/pulls/%d", owner, repo, index),
jsonHeader, bytes.NewReader(body), pr) jsonHeader, bytes.NewReader(body), pr)
} }
@ -147,5 +139,4 @@ func (c *Client) IsPullRequestMerged(owner, repo string, index int64) (bool, err
} }
return statusCode == 204, nil return statusCode == 204, nil
} }

View File

@ -13,22 +13,20 @@ import (
// Release represents a repository release // Release represents a repository release
type Release struct { type Release struct {
ID int64 `json:"id"` ID int64 `json:"id"`
TagName string `json:"tag_name"` TagName string `json:"tag_name"`
Target string `json:"target_commitish"` Target string `json:"target_commitish"`
Title string `json:"name"` Title string `json:"name"`
Note string `json:"body"` Note string `json:"body"`
URL string `json:"url"` URL string `json:"url"`
TarURL string `json:"tarball_url"` TarURL string `json:"tarball_url"`
ZipURL string `json:"zipball_url"` ZipURL string `json:"zipball_url"`
IsDraft bool `json:"draft"` IsDraft bool `json:"draft"`
IsPrerelease bool `json:"prerelease"` IsPrerelease bool `json:"prerelease"`
// swagger:strfmt date-time CreatedAt time.Time `json:"created_at"`
CreatedAt time.Time `json:"created_at"` PublishedAt time.Time `json:"published_at"`
// swagger:strfmt date-time Publisher *User `json:"author"`
PublishedAt time.Time `json:"published_at"` Attachments []*Attachment `json:"assets"`
Publisher *User `json:"author"`
Attachments []*Attachment `json:"assets"`
} }
// ListReleases list releases of a repository // ListReleases list releases of a repository
@ -51,8 +49,7 @@ func (c *Client) GetRelease(user, repo string, id int64) (*Release, error) {
// CreateReleaseOption options when creating a release // CreateReleaseOption options when creating a release
type CreateReleaseOption struct { type CreateReleaseOption struct {
// required: true TagName string `json:"tag_name"`
TagName string `json:"tag_name" binding:"Required"`
Target string `json:"target_commitish"` Target string `json:"target_commitish"`
Title string `json:"name"` Title string `json:"name"`
Note string `json:"body"` Note string `json:"body"`

View File

@ -20,32 +20,40 @@ type Permission struct {
// Repository represents a repository // Repository represents a repository
type Repository struct { type Repository struct {
ID int64 `json:"id"` ID int64 `json:"id"`
Owner *User `json:"owner"` Owner *User `json:"owner"`
Name string `json:"name"` Name string `json:"name"`
FullName string `json:"full_name"` FullName string `json:"full_name"`
Description string `json:"description"` Description string `json:"description"`
Empty bool `json:"empty"` Empty bool `json:"empty"`
Private bool `json:"private"` Private bool `json:"private"`
Fork bool `json:"fork"` Fork bool `json:"fork"`
Parent *Repository `json:"parent"` Parent *Repository `json:"parent"`
Mirror bool `json:"mirror"` Mirror bool `json:"mirror"`
Size int `json:"size"` Size int `json:"size"`
HTMLURL string `json:"html_url"` HTMLURL string `json:"html_url"`
SSHURL string `json:"ssh_url"` SSHURL string `json:"ssh_url"`
CloneURL string `json:"clone_url"` CloneURL string `json:"clone_url"`
Website string `json:"website"` OriginalURL string `json:"original_url"`
Stars int `json:"stars_count"` Website string `json:"website"`
Forks int `json:"forks_count"` Stars int `json:"stars_count"`
Watchers int `json:"watchers_count"` Forks int `json:"forks_count"`
OpenIssues int `json:"open_issues_count"` Watchers int `json:"watchers_count"`
DefaultBranch string `json:"default_branch"` OpenIssues int `json:"open_issues_count"`
Archived bool `json:"archived"` DefaultBranch string `json:"default_branch"`
// swagger:strfmt date-time Archived bool `json:"archived"`
Created time.Time `json:"created_at"` Created time.Time `json:"created_at"`
// swagger:strfmt date-time Updated time.Time `json:"updated_at"`
Updated time.Time `json:"updated_at"` Permissions *Permission `json:"permissions,omitempty"`
Permissions *Permission `json:"permissions,omitempty"` HasIssues bool `json:"has_issues"`
HasWiki bool `json:"has_wiki"`
HasPullRequests bool `json:"has_pull_requests"`
IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"`
AllowMerge bool `json:"allow_merge_commits"`
AllowRebase bool `json:"allow_rebase"`
AllowRebaseMerge bool `json:"allow_rebase_explicit"`
AllowSquash bool `json:"allow_squash_merge"`
AvatarURL string `json:"avatar_url"`
} }
// ListMyRepos lists all repositories for the authenticated user that has access to. // ListMyRepos lists all repositories for the authenticated user that has access to.
@ -67,17 +75,16 @@ func (c *Client) ListOrgRepos(org string) ([]*Repository, error) {
} }
// CreateRepoOption options when creating repository // CreateRepoOption options when creating repository
// swagger:model
type CreateRepoOption struct { type CreateRepoOption struct {
// Name of the repository to create // Name of the repository to create
// //
// required: true Name string `json:"name"`
// unique: true
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
// Description of the repository to create // Description of the repository to create
Description string `json:"description" binding:"MaxSize(255)"` Description string `json:"description"`
// Whether the repository is private // Whether the repository is private
Private bool `json:"private"` Private bool `json:"private"`
// Issue Label set to use
IssueLabels string `json:"issue_labels"`
// Whether the repository should be auto-intialized? // Whether the repository should be auto-intialized?
AutoInit bool `json:"auto_init"` AutoInit bool `json:"auto_init"`
// Gitignores to use // Gitignores to use
@ -114,6 +121,50 @@ func (c *Client) GetRepo(owner, reponame string) (*Repository, error) {
return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame), nil, nil, repo) return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame), nil, nil, repo)
} }
// EditRepoOption options when editing a repository's properties
type EditRepoOption struct {
// name of the repository
Name *string `json:"name,omitempty"`
// a short description of the repository.
Description *string `json:"description,omitempty"`
// a URL with more information about the repository.
Website *string `json:"website,omitempty"`
// either `true` to make the repository private or `false` to make it public.
// Note: you will get a 422 error if the organization restricts changing repository visibility to organization
// owners and a non-owner tries to change the value of private.
Private *bool `json:"private,omitempty"`
// either `true` to enable issues for this repository or `false` to disable them.
HasIssues *bool `json:"has_issues,omitempty"`
// either `true` to enable the wiki for this repository or `false` to disable it.
HasWiki *bool `json:"has_wiki,omitempty"`
// sets the default branch for this repository.
DefaultBranch *string `json:"default_branch,omitempty"`
// either `true` to allow pull requests, or `false` to prevent pull request.
HasPullRequests *bool `json:"has_pull_requests,omitempty"`
// either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace. `has_pull_requests` must be `true`.
IgnoreWhitespaceConflicts *bool `json:"ignore_whitespace_conflicts,omitempty"`
// either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits. `has_pull_requests` must be `true`.
AllowMerge *bool `json:"allow_merge_commits,omitempty"`
// either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging. `has_pull_requests` must be `true`.
AllowRebase *bool `json:"allow_rebase,omitempty"`
// either `true` to allow rebase with explicit merge commits (--no-ff), or `false` to prevent rebase with explicit merge commits. `has_pull_requests` must be `true`.
AllowRebaseMerge *bool `json:"allow_rebase_explicit,omitempty"`
// either `true` to allow squash-merging pull requests, or `false` to prevent squash-merging. `has_pull_requests` must be `true`.
AllowSquash *bool `json:"allow_squash_merge,omitempty"`
// set to `true` to archive this repository.
Archived *bool `json:"archived,omitempty"`
}
// EditRepo edit the properties of a repository
func (c *Client) EditRepo(owner, reponame string, opt EditRepoOption) (*Repository, error) {
body, err := json.Marshal(&opt)
if err != nil {
return nil, err
}
repo := new(Repository)
return repo, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s", owner, reponame), jsonHeader, bytes.NewReader(body), repo)
}
// DeleteRepo deletes a repository of user or organization. // DeleteRepo deletes a repository of user or organization.
func (c *Client) DeleteRepo(owner, repo string) error { func (c *Client) DeleteRepo(owner, repo string) error {
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s", owner, repo), nil, nil) _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s", owner, repo), nil, nil)
@ -122,17 +173,14 @@ func (c *Client) DeleteRepo(owner, repo string) error {
// MigrateRepoOption options for migrating a repository from an external service // MigrateRepoOption options for migrating a repository from an external service
type MigrateRepoOption struct { type MigrateRepoOption struct {
// required: true CloneAddr string `json:"clone_addr"`
CloneAddr string `json:"clone_addr" binding:"Required"`
AuthUsername string `json:"auth_username"` AuthUsername string `json:"auth_username"`
AuthPassword string `json:"auth_password"` AuthPassword string `json:"auth_password"`
// required: true UID int `json:"uid"`
UID int `json:"uid" binding:"Required"` RepoName string `json:"repo_name"`
// required: true Mirror bool `json:"mirror"`
RepoName string `json:"repo_name" binding:"Required"` Private bool `json:"private"`
Mirror bool `json:"mirror"` Description string `json:"description"`
Private bool `json:"private"`
Description string `json:"description"`
} }
// MigrateRepo migrates a repository from other Git hosting sources for the // MigrateRepo migrates a repository from other Git hosting sources for the

View File

@ -6,8 +6,43 @@ package gitea
import ( import (
"fmt" "fmt"
"time"
) )
// PayloadUser represents the author or committer of a commit
type PayloadUser struct {
// Full name of the commit author
Name string `json:"name"`
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"`
Timestamp time.Time `json:"timestamp"`
Added []string `json:"added"`
Removed []string `json:"removed"`
Modified []string `json:"modified"`
}
// 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"`
}
// Branch represents a repository branch // Branch represents a repository branch
type Branch struct { type Branch struct {
Name string `json:"name"` Name string `json:"name"`

View File

@ -11,9 +11,8 @@ import (
// Identity for a person's identity like an author or committer // Identity for a person's identity like an author or committer
type Identity struct { type Identity struct {
Name string `json:"name" binding:"MaxSize(100)"` Name string `json:"name"`
// swagger:strfmt email Email string `json:"email"`
Email string `json:"email" binding:"MaxSize(254)"`
} }
// CommitMeta contains meta information of a commit in terms of API. // CommitMeta contains meta information of a commit in terms of API.
@ -50,5 +49,5 @@ type Commit struct {
// GetSingleCommit returns a single commit // GetSingleCommit returns a single commit
func (c *Client) GetSingleCommit(user, repo, commitID string) (*Commit, error) { func (c *Client) GetSingleCommit(user, repo, commitID string) (*Commit, error) {
commit := new(Commit) commit := new(Commit)
return commit, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s", user, repo, commitID), nil, nil, &commit) return commit, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/git/commits/%s", user, repo, commitID), nil, nil, &commit)
} }

View File

@ -14,77 +14,3 @@ import (
func (c *Client) GetFile(user, repo, ref, tree string) ([]byte, error) { 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) return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s/%s", user, repo, ref, tree), nil, nil)
} }
// FileOptions options for all file APIs
type FileOptions struct {
Message string `json:"message" binding:"Required"`
BranchName string `json:"branch"`
NewBranchName string `json:"new_branch"`
Author Identity `json:"author"`
Committer Identity `json:"committer"`
}
// CreateFileOptions options for creating files
type CreateFileOptions struct {
FileOptions
Content string `json:"content"`
}
// DeleteFileOptions options for deleting files (used for other File structs below)
type DeleteFileOptions struct {
FileOptions
SHA string `json:"sha" binding:"Required"`
}
// UpdateFileOptions options for updating files
type UpdateFileOptions struct {
DeleteFileOptions
Content string `json:"content"`
FromPath string `json:"from_path" binding:"MaxSize(500)"`
}
// FileLinksResponse contains the links for a repo's file
type FileLinksResponse struct {
Self string `json:"url"`
GitURL string `json:"git_url"`
HTMLURL string `json:"html_url"`
}
// FileContentResponse contains information about a repo's file stats and content
type FileContentResponse struct {
Name string `json:"name"`
Path string `json:"path"`
SHA string `json:"sha"`
Size int64 `json:"size"`
URL string `json:"url"`
HTMLURL string `json:"html_url"`
GitURL string `json:"git_url"`
DownloadURL string `json:"download_url"`
Type string `json:"type"`
Links *FileLinksResponse `json:"_links"`
}
// FileCommitResponse contains information generated from a Git commit for a repo's file.
type FileCommitResponse struct {
CommitMeta
HTMLURL string `json:"html_url"`
Author *CommitUser `json:"author"`
Committer *CommitUser `json:"committer"`
Parents []*CommitMeta `json:"parents"`
Message string `json:"message"`
Tree *CommitMeta `json:"tree"`
}
// FileResponse contains information about a repo's file
type FileResponse struct {
Content *FileContentResponse `json:"content"`
Commit *FileCommitResponse `json:"commit"`
Verification *PayloadCommitVerification `json:"verification"`
}
// FileDeleteResponse contains information about a repo's file that was deleted
type FileDeleteResponse struct {
Content interface{} `json:"content"` // to be set to nil
Commit *FileCommitResponse `json:"commit"`
Verification *PayloadCommitVerification `json:"verification"`
}

View File

@ -13,16 +13,15 @@ import (
// DeployKey a deploy key // DeployKey a deploy key
type DeployKey struct { type DeployKey struct {
ID int64 `json:"id"` ID int64 `json:"id"`
KeyID int64 `json:"key_id"` KeyID int64 `json:"key_id"`
Key string `json:"key"` Key string `json:"key"`
URL string `json:"url"` URL string `json:"url"`
Title string `json:"title"` Title string `json:"title"`
Fingerprint string `json:"fingerprint"` Fingerprint string `json:"fingerprint"`
// swagger:strfmt date-time Created time.Time `json:"created_at"`
Created time.Time `json:"created_at"` ReadOnly bool `json:"read_only"`
ReadOnly bool `json:"read_only"` Repository *Repository `json:"repository,omitempty"`
Repository *Repository `json:"repository,omitempty"`
} }
// ListDeployKeys list all the deploy keys of one repository // ListDeployKeys list all the deploy keys of one repository
@ -37,24 +36,6 @@ func (c *Client) GetDeployKey(user, repo string, keyID int64) (*DeployKey, error
return key, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys/%d", user, repo, keyID), nil, nil, &key) 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 // CreateDeployKey options when create one deploy key
func (c *Client) CreateDeployKey(user, repo string, opt CreateKeyOption) (*DeployKey, error) { func (c *Client) CreateDeployKey(user, repo string, opt CreateKeyOption) (*DeployKey, error) {
body, err := json.Marshal(&opt) body, err := json.Marshal(&opt)

View File

@ -10,13 +10,11 @@ import (
// Tag represents a repository tag // Tag represents a repository tag
type Tag struct { type Tag struct {
Name string `json:"name"` Name string `json:"name"`
Commit struct { ID string `json:"id"`
SHA string `json:"sha"` Commit *CommitMeta `json:"commit"`
URL string `json:"url"` ZipballURL string `json:"zipball_url"`
} `json:"commit"` TarballURL string `json:"tarball_url"`
ZipballURL string `json:"zipball_url"`
TarballURL string `json:"tarball_url"`
} }
// ListRepoTags list all the branches of one repository // ListRepoTags list all the branches of one repository

View File

@ -37,21 +37,8 @@ type Status struct {
URL string `json:"url"` URL string `json:"url"`
Context string `json:"context"` Context string `json:"context"`
Creator *User `json:"creator"` Creator *User `json:"creator"`
// swagger:strfmt date-time Created time.Time `json:"created_at"`
Created time.Time `json:"created_at"` Updated time.Time `json:"updated_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 // CreateStatusOption holds the information needed to create a new Status for a Commit
@ -62,11 +49,6 @@ type CreateStatusOption struct {
Context string `json:"context"` Context string `json:"context"`
} }
// ListStatusesOption holds pagination information
type ListStatusesOption struct {
Page int
}
// CreateStatus creates a new Status for a given Commit // CreateStatus creates a new Status for a given Commit
// //
// POST /repos/:owner/:repo/statuses/:sha // POST /repos/:owner/:repo/statuses/:sha
@ -80,6 +62,11 @@ func (c *Client) CreateStatus(owner, repo, sha string, opts CreateStatusOption)
jsonHeader, bytes.NewReader(body), status) jsonHeader, bytes.NewReader(body), status)
} }
// ListStatusesOption holds pagination information
type ListStatusesOption struct {
Page int
}
// ListStatuses returns all statuses for a given Commit // ListStatuses returns all statuses for a given Commit
// //
// GET /repos/:owner/:repo/commits/:ref/statuses // GET /repos/:owner/:repo/commits/:ref/statuses
@ -88,6 +75,17 @@ func (c *Client) ListStatuses(owner, repo, sha string, opts ListStatusesOption)
return statuses, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s/statuses?page=%d", owner, repo, sha, opts.Page), nil, nil, &statuses) return statuses, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s/statuses?page=%d", owner, repo, sha, opts.Page), nil, nil, &statuses)
} }
// 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"`
}
// GetCombinedStatus returns the CombinedStatus for a given Commit // GetCombinedStatus returns the CombinedStatus for a given Commit
// //
// GET /repos/:owner/:repo/commits/:ref/status // GET /repos/:owner/:repo/commits/:ref/status

View File

@ -5,12 +5,11 @@
package gitea package gitea
import ( import (
"encoding/json"
"fmt" "fmt"
"time"
) )
// User represents a user // User represents a user
// swagger:model
type User struct { type User struct {
// the user's id // the user's id
ID int64 `json:"id"` ID int64 `json:"id"`
@ -18,24 +17,15 @@ type User struct {
UserName string `json:"login"` UserName string `json:"login"`
// the user's full name // the user's full name
FullName string `json:"full_name"` FullName string `json:"full_name"`
// swagger:strfmt email Email string `json:"email"`
Email string `json:"email"`
// URL to the user's avatar // URL to the user's avatar
AvatarURL string `json:"avatar_url"` AvatarURL string `json:"avatar_url"`
// User locale // User locale
Language string `json:"language"` Language string `json:"language"`
// Is the user an administrator // Is the user an administrator
IsAdmin bool `json:"is_admin"` IsAdmin bool `json:"is_admin"`
} LastLogin time.Time `json:"last_login,omitempty"`
Created time.Time `json:"created,omitempty"`
// 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 // GetUserInfo get user info by user's name

View File

@ -19,19 +19,13 @@ func BasicAuthEncode(user, pass string) string {
} }
// AccessToken represents an API access token. // AccessToken represents an API access token.
// swagger:response AccessToken
type AccessToken struct { type AccessToken struct {
ID int64 `json:"id"` ID int64 `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Token string `json:"token"` Token string `json:"sha1"`
HashedToken string `json:"hashed_token"`
TokenLastEight string `json:"token_last_eight"` TokenLastEight string `json:"token_last_eight"`
} }
// AccessTokenList represents a list of API access token.
// swagger:response AccessTokenList
type AccessTokenList []*AccessToken
// ListAccessTokens lista all the access tokens of user // ListAccessTokens lista all the access tokens of user
func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) { func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) {
tokens := make([]*AccessToken, 0, 10) tokens := make([]*AccessToken, 0, 10)
@ -40,9 +34,8 @@ func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) {
} }
// CreateAccessTokenOption options when create access token // CreateAccessTokenOption options when create access token
// swagger:parameters userCreateToken
type CreateAccessTokenOption struct { type CreateAccessTokenOption struct {
Name string `json:"name" binding:"Required"` Name string `json:"name"`
} }
// CreateAccessToken create one access token with options // CreateAccessToken create one access token with options

View File

@ -11,7 +11,6 @@ import (
// Email an email address belonging to a user // Email an email address belonging to a user
type Email struct { type Email struct {
// swagger:strfmt email
Email string `json:"email"` Email string `json:"email"`
Verified bool `json:"verified"` Verified bool `json:"verified"`
Primary bool `json:"primary"` Primary bool `json:"primary"`

View File

@ -23,28 +23,16 @@ type GPGKey struct {
CanEncryptComms bool `json:"can_encrypt_comms"` CanEncryptComms bool `json:"can_encrypt_comms"`
CanEncryptStorage bool `json:"can_encrypt_storage"` CanEncryptStorage bool `json:"can_encrypt_storage"`
CanCertify bool `json:"can_certify"` CanCertify bool `json:"can_certify"`
// swagger:strfmt date-time Created time.Time `json:"created_at,omitempty"`
Created time.Time `json:"created_at,omitempty"` Expires time.Time `json:"expires_at,omitempty"`
// swagger:strfmt date-time
Expires time.Time `json:"expires_at,omitempty"`
} }
// GPGKeyEmail an email attached to a GPGKey // GPGKeyEmail an email attached to a GPGKey
// swagger:model GPGKeyEmail
type GPGKeyEmail struct { type GPGKeyEmail struct {
Email string `json:"email"` Email string `json:"email"`
Verified bool `json:"verified"` 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 // ListGPGKeys list all the GPG keys of the user
func (c *Client) ListGPGKeys(user string) ([]*GPGKey, error) { func (c *Client) ListGPGKeys(user string) ([]*GPGKey, error) {
keys := make([]*GPGKey, 0, 10) keys := make([]*GPGKey, 0, 10)
@ -63,6 +51,13 @@ func (c *Client) GetGPGKey(keyID int64) (*GPGKey, error) {
return key, c.getParsedResponse("GET", fmt.Sprintf("/user/gpg_keys/%d", keyID), nil, nil, &key) return key, c.getParsedResponse("GET", fmt.Sprintf("/user/gpg_keys/%d", keyID), nil, nil, &key)
} }
// CreateGPGKeyOption options create user GPG key
type CreateGPGKeyOption struct {
// An armored GPG key to add
//
ArmoredKey string `json:"armored_public_key"`
}
// CreateGPGKey create GPG key with options // CreateGPGKey create GPG key with options
func (c *Client) CreateGPGKey(opt CreateGPGKeyOption) (*GPGKey, error) { func (c *Client) CreateGPGKey(opt CreateGPGKeyOption) (*GPGKey, error) {
body, err := json.Marshal(&opt) body, err := json.Marshal(&opt)

View File

@ -13,16 +13,15 @@ import (
// PublicKey publickey is a user key to push code to repository // PublicKey publickey is a user key to push code to repository
type PublicKey struct { type PublicKey struct {
ID int64 `json:"id"` ID int64 `json:"id"`
Key string `json:"key"` Key string `json:"key"`
URL string `json:"url,omitempty"` URL string `json:"url,omitempty"`
Title string `json:"title,omitempty"` Title string `json:"title,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"` Fingerprint string `json:"fingerprint,omitempty"`
// swagger:strfmt date-time Created time.Time `json:"created_at,omitempty"`
Created time.Time `json:"created_at,omitempty"` Owner *User `json:"user,omitempty"`
Owner *User `json:"user,omitempty"` ReadOnly bool `json:"read_only,omitempty"`
ReadOnly bool `json:"read_only,omitempty"` KeyType string `json:"key_type,omitempty"`
KeyType string `json:"key_type,omitempty"`
} }
// ListPublicKeys list all the public keys of the user // ListPublicKeys list all the public keys of the user
@ -43,6 +42,16 @@ func (c *Client) GetPublicKey(keyID int64) (*PublicKey, error) {
return key, c.getParsedResponse("GET", fmt.Sprintf("/user/keys/%d", keyID), nil, nil, &key) return key, c.getParsedResponse("GET", fmt.Sprintf("/user/keys/%d", keyID), nil, nil, &key)
} }
// CreateKeyOption options when creating a key
type CreateKeyOption struct {
// Title of the key to add
Title string `json:"title"`
// An armored SSH key to add
Key string `json:"key"`
// Describe if the key has only read access or read/write
ReadOnly bool `json:"read_only"`
}
// CreatePublicKey create public key with options // CreatePublicKey create public key with options
func (c *Client) CreatePublicKey(opt CreateKeyOption) (*PublicKey, error) { func (c *Client) CreatePublicKey(opt CreateKeyOption) (*PublicKey, error) {
body, err := json.Marshal(&opt) body, err := json.Marshal(&opt)

View File

@ -1,26 +0,0 @@
// Copyright 2015 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package 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
}

2
vendor/modules.txt vendored
View File

@ -1,4 +1,4 @@
# code.gitea.io/sdk v0.0.0-20190424055801-13a7bf625b83 # code.gitea.io/sdk/gitea v0.0.0-20191013013401-e41e9ea72caa
code.gitea.io/sdk/gitea code.gitea.io/sdk/gitea
# github.com/go-gitea/yaml v0.0.0-20170812160011-eb3733d160e7 # github.com/go-gitea/yaml v0.0.0-20170812160011-eb3733d160e7
github.com/go-gitea/yaml github.com/go-gitea/yaml