issue create return web url (#257)
Update SDK Use OptionalBool helper Fix #254 Reviewed-on: https://gitea.com/gitea/tea/pulls/257 Reviewed-by: John Olheiser <john.olheiser@gmail.com> Reviewed-by: techknowlogick <techknowlogick@gitea.io> Co-Authored-By: 6543 <6543@obermui.de> Co-Committed-By: 6543 <6543@obermui.de>
This commit is contained in:
parent
e6fbba3f80
commit
476900ab41
|
@ -56,6 +56,6 @@ func runIssuesCreate(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
print.IssueDetails(issue)
|
print.IssueDetails(issue)
|
||||||
fmt.Println(issue.URL)
|
fmt.Println(issue.HTMLURL)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,19 +75,11 @@ func runReleaseEdit(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var isDraft, isPre *bool
|
var isDraft, isPre *bool
|
||||||
bTrue := true
|
|
||||||
bFalse := false
|
|
||||||
if ctx.IsSet("draft") {
|
if ctx.IsSet("draft") {
|
||||||
isDraft = &bFalse
|
isDraft = gitea.OptionalBool(strings.ToLower(ctx.String("draft"))[:1] == "t")
|
||||||
if strings.ToLower(ctx.String("draft"))[:1] == "t" {
|
|
||||||
isDraft = &bTrue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ctx.IsSet("prerelease") {
|
if ctx.IsSet("prerelease") {
|
||||||
isPre = &bFalse
|
isPre = gitea.OptionalBool(strings.ToLower(ctx.String("prerelease"))[:1] == "t")
|
||||||
if strings.ToLower(ctx.String("prerelease"))[:1] == "t" {
|
|
||||||
isPre = &bTrue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err = client.EditRelease(owner, repo, release.ID, gitea.EditReleaseOption{
|
_, _, err = client.EditRelease(owner, repo, release.ID, gitea.EditReleaseOption{
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
code.gitea.io/gitea-vet v0.2.1
|
code.gitea.io/gitea-vet v0.2.1
|
||||||
code.gitea.io/sdk/gitea v0.13.2-0.20201112213603-e323ee0bc434
|
code.gitea.io/sdk/gitea v0.13.1-0.20201129150736-6ea6e887f2fc
|
||||||
github.com/AlecAivazis/survey/v2 v2.2.2
|
github.com/AlecAivazis/survey/v2 v2.2.2
|
||||||
github.com/Microsoft/go-winio v0.4.15 // indirect
|
github.com/Microsoft/go-winio v0.4.15 // indirect
|
||||||
github.com/adrg/xdg v0.2.2
|
github.com/adrg/xdg v0.2.2
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -1,7 +1,7 @@
|
||||||
code.gitea.io/gitea-vet v0.2.1 h1:b30by7+3SkmiftK0RjuXqFvZg2q4p68uoPGuxhzBN0s=
|
code.gitea.io/gitea-vet v0.2.1 h1:b30by7+3SkmiftK0RjuXqFvZg2q4p68uoPGuxhzBN0s=
|
||||||
code.gitea.io/gitea-vet v0.2.1/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE=
|
code.gitea.io/gitea-vet v0.2.1/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE=
|
||||||
code.gitea.io/sdk/gitea v0.13.2-0.20201112213603-e323ee0bc434 h1:koxDF6qb81P1spPf48UJBCiuWlc3crd1+uUEOyFVolY=
|
code.gitea.io/sdk/gitea v0.13.1-0.20201129150736-6ea6e887f2fc h1:Jy4PoO7T7tST6iYe7nvUwD2zkqbqVB34hLZsrG0EmLo=
|
||||||
code.gitea.io/sdk/gitea v0.13.2-0.20201112213603-e323ee0bc434/go.mod h1:lee2y8LeV3kQb2iK+hHlMqoadL4bp27QOkOV/hawLKg=
|
code.gitea.io/sdk/gitea v0.13.1-0.20201129150736-6ea6e887f2fc/go.mod h1:89WiyOX1KEcvjP66sRHdu0RafojGo60bT9UqW17VbWs=
|
||||||
github.com/AlecAivazis/survey/v2 v2.2.2 h1:1I4qBrNsHQE+91tQCqVlfrKe9DEL65949d1oKZWVELY=
|
github.com/AlecAivazis/survey/v2 v2.2.2 h1:1I4qBrNsHQE+91tQCqVlfrKe9DEL65949d1oKZWVELY=
|
||||||
github.com/AlecAivazis/survey/v2 v2.2.2/go.mod h1:9FJRdMdDm8rnT+zHVbvQT2RTSTLq0Ttd6q3Vl2fahjk=
|
github.com/AlecAivazis/survey/v2 v2.2.2/go.mod h1:9FJRdMdDm8rnT+zHVbvQT2RTSTLq0Ttd6q3Vl2fahjk=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
|
|
|
@ -23,7 +23,7 @@ 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.13.0"
|
return "0.14.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client represents a Gitea API client.
|
// Client represents a Gitea API client.
|
||||||
|
@ -38,7 +38,7 @@ type Client struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
serverVersion *version.Version
|
serverVersion *version.Version
|
||||||
versionLock sync.RWMutex
|
getVersionOnce sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
// Response represents the gitea response
|
// Response represents the gitea response
|
||||||
|
@ -56,7 +56,7 @@ func NewClient(url string, options ...func(*Client)) (*Client, error) {
|
||||||
for _, opt := range options {
|
for _, opt := range options {
|
||||||
opt(client)
|
opt(client)
|
||||||
}
|
}
|
||||||
if err := client.checkServerVersionGreaterThanOrEqual(version1_10_0); err != nil {
|
if err := client.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return client, nil
|
return client, nil
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module code.gitea.io/sdk/gitea
|
module code.gitea.io/sdk/gitea
|
||||||
|
|
||||||
go 1.12
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/hashicorp/go-version v1.2.1
|
github.com/hashicorp/go-version v1.2.1
|
||||||
|
|
|
@ -2,6 +2,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E=
|
github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E=
|
||||||
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||||
|
github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI=
|
||||||
|
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
// Copyright 2020 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
|
||||||
|
|
||||||
|
// OptionalBool convert a bool to a bool reference
|
||||||
|
func OptionalBool(v bool) *bool {
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
||||||
|
// OptionalString convert a string to a string reference
|
||||||
|
func OptionalString(v string) *string {
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
||||||
|
// OptionalInt64 convert a int64 to a int64 reference
|
||||||
|
func OptionalInt64(v int64) *int64 {
|
||||||
|
return &v
|
||||||
|
}
|
|
@ -32,6 +32,7 @@ type RepositoryMeta struct {
|
||||||
type Issue struct {
|
type Issue struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
|
HTMLURL string `json:"html_url"`
|
||||||
Index int64 `json:"number"`
|
Index int64 `json:"number"`
|
||||||
Poster *User `json:"user"`
|
Poster *User `json:"user"`
|
||||||
OriginalAuthor string `json:"original_author"`
|
OriginalAuthor string `json:"original_author"`
|
||||||
|
@ -40,6 +41,8 @@ type Issue struct {
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
Labels []*Label `json:"labels"`
|
Labels []*Label `json:"labels"`
|
||||||
Milestone *Milestone `json:"milestone"`
|
Milestone *Milestone `json:"milestone"`
|
||||||
|
// deprecated
|
||||||
|
// TODO: rm on sdk 0.15.0
|
||||||
Assignee *User `json:"assignee"`
|
Assignee *User `json:"assignee"`
|
||||||
Assignees []*User `json:"assignees"`
|
Assignees []*User `json:"assignees"`
|
||||||
// Whether the issue is open or closed
|
// Whether the issue is open or closed
|
||||||
|
@ -128,6 +131,9 @@ func (c *Client) ListIssues(opt ListIssueOption) ([]*Issue, *Response, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for i := range issues {
|
||||||
|
c.issueBackwardsCompatibility(issues[i])
|
||||||
|
}
|
||||||
return issues, resp, err
|
return issues, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,6 +152,9 @@ func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Iss
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for i := range issues {
|
||||||
|
c.issueBackwardsCompatibility(issues[i])
|
||||||
|
}
|
||||||
return issues, resp, err
|
return issues, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +165,7 @@ func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, *Response, e
|
||||||
if e := c.checkServerVersionGreaterThanOrEqual(version1_12_0); e != nil && issue.Repository != nil {
|
if e := c.checkServerVersionGreaterThanOrEqual(version1_12_0); e != nil && issue.Repository != nil {
|
||||||
issue.Repository.Owner = strings.Split(issue.Repository.FullName, "/")[0]
|
issue.Repository.Owner = strings.Split(issue.Repository.FullName, "/")[0]
|
||||||
}
|
}
|
||||||
|
c.issueBackwardsCompatibility(issue)
|
||||||
return issue, resp, err
|
return issue, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,6 +204,7 @@ func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue,
|
||||||
issue := new(Issue)
|
issue := new(Issue)
|
||||||
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues", owner, repo),
|
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues", owner, repo),
|
||||||
jsonHeader, bytes.NewReader(body), issue)
|
jsonHeader, bytes.NewReader(body), issue)
|
||||||
|
c.issueBackwardsCompatibility(issue)
|
||||||
return issue, resp, err
|
return issue, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,5 +240,12 @@ func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption)
|
||||||
resp, err := c.getParsedResponse("PATCH",
|
resp, err := c.getParsedResponse("PATCH",
|
||||||
fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index),
|
fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index),
|
||||||
jsonHeader, bytes.NewReader(body), issue)
|
jsonHeader, bytes.NewReader(body), issue)
|
||||||
|
c.issueBackwardsCompatibility(issue)
|
||||||
return issue, resp, err
|
return issue, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) issueBackwardsCompatibility(issue *Issue) {
|
||||||
|
if c.checkServerVersionGreaterThanOrEqual(version1_12_0) != nil {
|
||||||
|
issue.HTMLURL = fmt.Sprintf("%s/%s/issues/%d", c.url, issue.Repository.FullName, issue.Index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -20,9 +20,6 @@ type Reaction struct {
|
||||||
|
|
||||||
// GetIssueReactions get a list reactions of an issue
|
// GetIssueReactions get a list reactions of an issue
|
||||||
func (c *Client) GetIssueReactions(owner, repo string, index int64) ([]*Reaction, *Response, error) {
|
func (c *Client) GetIssueReactions(owner, repo string, index int64) ([]*Reaction, *Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
reactions := make([]*Reaction, 0, 10)
|
reactions := make([]*Reaction, 0, 10)
|
||||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/reactions", owner, repo, index), nil, nil, &reactions)
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/reactions", owner, repo, index), nil, nil, &reactions)
|
||||||
return reactions, resp, err
|
return reactions, resp, err
|
||||||
|
@ -30,9 +27,6 @@ func (c *Client) GetIssueReactions(owner, repo string, index int64) ([]*Reaction
|
||||||
|
|
||||||
// GetIssueCommentReactions get a list of reactions from a comment of an issue
|
// GetIssueCommentReactions get a list of reactions from a comment of an issue
|
||||||
func (c *Client) GetIssueCommentReactions(owner, repo string, commentID int64) ([]*Reaction, *Response, error) {
|
func (c *Client) GetIssueCommentReactions(owner, repo string, commentID int64) ([]*Reaction, *Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
reactions := make([]*Reaction, 0, 10)
|
reactions := make([]*Reaction, 0, 10)
|
||||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments/%d/reactions", owner, repo, commentID), nil, nil, &reactions)
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments/%d/reactions", owner, repo, commentID), nil, nil, &reactions)
|
||||||
return reactions, resp, err
|
return reactions, resp, err
|
||||||
|
@ -45,9 +39,6 @@ type editReactionOption struct {
|
||||||
|
|
||||||
// PostIssueReaction add a reaction to an issue
|
// PostIssueReaction add a reaction to an issue
|
||||||
func (c *Client) PostIssueReaction(owner, repo string, index int64, reaction string) (*Reaction, *Response, error) {
|
func (c *Client) PostIssueReaction(owner, repo string, index int64, reaction string) (*Reaction, *Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
reactionResponse := new(Reaction)
|
reactionResponse := new(Reaction)
|
||||||
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -61,9 +52,6 @@ func (c *Client) PostIssueReaction(owner, repo string, index int64, reaction str
|
||||||
|
|
||||||
// DeleteIssueReaction remove a reaction from an issue
|
// DeleteIssueReaction remove a reaction from an issue
|
||||||
func (c *Client) DeleteIssueReaction(owner, repo string, index int64, reaction string) (*Response, error) {
|
func (c *Client) DeleteIssueReaction(owner, repo string, index int64, reaction string) (*Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -74,9 +62,6 @@ func (c *Client) DeleteIssueReaction(owner, repo string, index int64, reaction s
|
||||||
|
|
||||||
// PostIssueCommentReaction add a reaction to a comment of an issue
|
// PostIssueCommentReaction add a reaction to a comment of an issue
|
||||||
func (c *Client) PostIssueCommentReaction(owner, repo string, commentID int64, reaction string) (*Reaction, *Response, error) {
|
func (c *Client) PostIssueCommentReaction(owner, repo string, commentID int64, reaction string) (*Reaction, *Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
reactionResponse := new(Reaction)
|
reactionResponse := new(Reaction)
|
||||||
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -90,9 +75,6 @@ func (c *Client) PostIssueCommentReaction(owner, repo string, commentID int64, r
|
||||||
|
|
||||||
// DeleteIssueCommentReaction remove a reaction from a comment of an issue
|
// DeleteIssueCommentReaction remove a reaction from a comment of an issue
|
||||||
func (c *Client) DeleteIssueCommentReaction(owner, repo string, commentID int64, reaction string) (*Response, error) {
|
func (c *Client) DeleteIssueCommentReaction(owner, repo string, commentID int64, reaction string) (*Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -11,9 +11,6 @@ import (
|
||||||
|
|
||||||
// GetIssueSubscribers get list of users who subscribed on an issue
|
// GetIssueSubscribers get list of users who subscribed on an issue
|
||||||
func (c *Client) GetIssueSubscribers(owner, repo string, index int64) ([]*User, *Response, error) {
|
func (c *Client) GetIssueSubscribers(owner, repo string, index int64) ([]*User, *Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
subscribers := make([]*User, 0, 10)
|
subscribers := make([]*User, 0, 10)
|
||||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions", owner, repo, index), nil, nil, &subscribers)
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions", owner, repo, index), nil, nil, &subscribers)
|
||||||
return subscribers, resp, err
|
return subscribers, resp, err
|
||||||
|
@ -21,9 +18,6 @@ func (c *Client) GetIssueSubscribers(owner, repo string, index int64) ([]*User,
|
||||||
|
|
||||||
// AddIssueSubscription Subscribe user to issue
|
// AddIssueSubscription Subscribe user to issue
|
||||||
func (c *Client) AddIssueSubscription(owner, repo string, index int64, user string) (*Response, error) {
|
func (c *Client) AddIssueSubscription(owner, repo string, index int64, user string) (*Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
status, resp, err := c.getStatusCode("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions/%s", owner, repo, index, user), nil, nil)
|
status, resp, err := c.getStatusCode("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions/%s", owner, repo, index, user), nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return resp, err
|
return resp, err
|
||||||
|
@ -39,9 +33,6 @@ func (c *Client) AddIssueSubscription(owner, repo string, index int64, user stri
|
||||||
|
|
||||||
// DeleteIssueSubscription unsubscribe user from issue
|
// DeleteIssueSubscription unsubscribe user from issue
|
||||||
func (c *Client) DeleteIssueSubscription(owner, repo string, index int64, user string) (*Response, error) {
|
func (c *Client) DeleteIssueSubscription(owner, repo string, index int64, user string) (*Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
status, resp, err := c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions/%s", owner, repo, index, user), nil, nil)
|
status, resp, err := c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions/%s", owner, repo, index, user), nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return resp, err
|
return resp, err
|
||||||
|
|
|
@ -27,9 +27,6 @@ type TrackedTime struct {
|
||||||
|
|
||||||
// GetUserTrackedTimes list tracked times of a user
|
// GetUserTrackedTimes list tracked times of a user
|
||||||
func (c *Client) GetUserTrackedTimes(owner, repo, user string) ([]*TrackedTime, *Response, error) {
|
func (c *Client) GetUserTrackedTimes(owner, repo, user string) ([]*TrackedTime, *Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
times := make([]*TrackedTime, 0, 10)
|
times := make([]*TrackedTime, 0, 10)
|
||||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times/%s", owner, repo, user), nil, nil, ×)
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times/%s", owner, repo, user), nil, nil, ×)
|
||||||
return times, resp, err
|
return times, resp, err
|
||||||
|
@ -37,9 +34,6 @@ func (c *Client) GetUserTrackedTimes(owner, repo, user string) ([]*TrackedTime,
|
||||||
|
|
||||||
// GetRepoTrackedTimes list tracked times of a repository
|
// GetRepoTrackedTimes list tracked times of a repository
|
||||||
func (c *Client) GetRepoTrackedTimes(owner, repo string) ([]*TrackedTime, *Response, error) {
|
func (c *Client) GetRepoTrackedTimes(owner, repo string) ([]*TrackedTime, *Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
times := make([]*TrackedTime, 0, 10)
|
times := make([]*TrackedTime, 0, 10)
|
||||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times", owner, repo), nil, nil, ×)
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/times", owner, repo), nil, nil, ×)
|
||||||
return times, resp, err
|
return times, resp, err
|
||||||
|
@ -47,9 +41,6 @@ func (c *Client) GetRepoTrackedTimes(owner, repo string) ([]*TrackedTime, *Respo
|
||||||
|
|
||||||
// GetMyTrackedTimes list tracked times of the current user
|
// GetMyTrackedTimes list tracked times of the current user
|
||||||
func (c *Client) GetMyTrackedTimes() ([]*TrackedTime, *Response, error) {
|
func (c *Client) GetMyTrackedTimes() ([]*TrackedTime, *Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
times := make([]*TrackedTime, 0, 10)
|
times := make([]*TrackedTime, 0, 10)
|
||||||
resp, err := c.getParsedResponse("GET", "/user/times", nil, nil, ×)
|
resp, err := c.getParsedResponse("GET", "/user/times", nil, nil, ×)
|
||||||
return times, resp, err
|
return times, resp, err
|
||||||
|
@ -75,9 +66,6 @@ func (opt AddTimeOption) Validate() error {
|
||||||
|
|
||||||
// AddTime adds time to issue with the given index
|
// AddTime adds time to issue with the given index
|
||||||
func (c *Client) AddTime(owner, repo string, index int64, opt AddTimeOption) (*TrackedTime, *Response, error) {
|
func (c *Client) AddTime(owner, repo string, index int64, opt AddTimeOption) (*TrackedTime, *Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
if err := opt.Validate(); err != nil {
|
if err := opt.Validate(); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -99,9 +87,6 @@ type ListTrackedTimesOptions struct {
|
||||||
|
|
||||||
// ListTrackedTimes list tracked times of a single issue for a given repository
|
// ListTrackedTimes list tracked times of a single issue for a given repository
|
||||||
func (c *Client) ListTrackedTimes(owner, repo string, index int64, opt ListTrackedTimesOptions) ([]*TrackedTime, *Response, error) {
|
func (c *Client) ListTrackedTimes(owner, repo string, index int64, opt ListTrackedTimesOptions) ([]*TrackedTime, *Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
opt.setDefaults()
|
opt.setDefaults()
|
||||||
times := make([]*TrackedTime, 0, opt.PageSize)
|
times := make([]*TrackedTime, 0, opt.PageSize)
|
||||||
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/times?%s", owner, repo, index, opt.getURLQuery().Encode()), nil, nil, ×)
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/times?%s", owner, repo, index, opt.getURLQuery().Encode()), nil, nil, ×)
|
||||||
|
@ -110,18 +95,12 @@ func (c *Client) ListTrackedTimes(owner, repo string, index int64, opt ListTrack
|
||||||
|
|
||||||
// ResetIssueTime reset tracked time of a single issue for a given repository
|
// ResetIssueTime reset tracked time of a single issue for a given repository
|
||||||
func (c *Client) ResetIssueTime(owner, repo string, index int64) (*Response, error) {
|
func (c *Client) ResetIssueTime(owner, repo string, index int64) (*Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index), nil, nil)
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index), nil, nil)
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteTime delete a specific tracked time by id of a single issue for a given repository
|
// DeleteTime delete a specific tracked time by id of a single issue for a given repository
|
||||||
func (c *Client) DeleteTime(owner, repo string, index, timeID int64) (*Response, error) {
|
func (c *Client) DeleteTime(owner, repo string, index, timeID int64) (*Response, error) {
|
||||||
if err := c.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/times/%d", owner, repo, index, timeID), nil, nil)
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/times/%d", owner, repo, index, timeID), nil, nil)
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,15 +22,9 @@ func (c *Client) ServerVersion() (string, *Response, error) {
|
||||||
// CheckServerVersionConstraint validates that the login's server satisfies a
|
// CheckServerVersionConstraint validates that the login's server satisfies a
|
||||||
// given version constraint such as ">= 1.11.0+dev"
|
// given version constraint such as ">= 1.11.0+dev"
|
||||||
func (c *Client) CheckServerVersionConstraint(constraint string) error {
|
func (c *Client) CheckServerVersionConstraint(constraint string) error {
|
||||||
c.versionLock.RLock()
|
if err := c.loadServerVersion(); err != nil {
|
||||||
if c.serverVersion == nil {
|
|
||||||
c.versionLock.RUnlock()
|
|
||||||
if err := c.loadClientServerVersion(); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
c.versionLock.RUnlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
check, err := version.NewConstraint(constraint)
|
check, err := version.NewConstraint(constraint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -44,7 +38,6 @@ func (c *Client) CheckServerVersionConstraint(constraint string) error {
|
||||||
|
|
||||||
// predefined versions only have to be parsed by library once
|
// predefined versions only have to be parsed by library once
|
||||||
var (
|
var (
|
||||||
version1_10_0, _ = version.NewVersion("1.10.0")
|
|
||||||
version1_11_0, _ = version.NewVersion("1.11.0")
|
version1_11_0, _ = version.NewVersion("1.11.0")
|
||||||
version1_12_0, _ = version.NewVersion("1.12.0")
|
version1_12_0, _ = version.NewVersion("1.12.0")
|
||||||
version1_13_0, _ = version.NewVersion("1.13.0")
|
version1_13_0, _ = version.NewVersion("1.13.0")
|
||||||
|
@ -52,15 +45,9 @@ var (
|
||||||
|
|
||||||
// checkServerVersionGreaterThanOrEqual is internally used to speed up things and ignore issues with prerelease
|
// checkServerVersionGreaterThanOrEqual is internally used to speed up things and ignore issues with prerelease
|
||||||
func (c *Client) checkServerVersionGreaterThanOrEqual(v *version.Version) error {
|
func (c *Client) checkServerVersionGreaterThanOrEqual(v *version.Version) error {
|
||||||
c.versionLock.RLock()
|
if err := c.loadServerVersion(); err != nil {
|
||||||
if c.serverVersion == nil {
|
|
||||||
c.versionLock.RUnlock()
|
|
||||||
if err := c.loadClientServerVersion(); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
c.versionLock.RUnlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
if !c.serverVersion.GreaterThanOrEqual(v) {
|
if !c.serverVersion.GreaterThanOrEqual(v) {
|
||||||
return fmt.Errorf("gitea server at %s is older than %s", c.url, v.Original())
|
return fmt.Errorf("gitea server at %s is older than %s", c.url, v.Original())
|
||||||
|
@ -68,17 +55,17 @@ func (c *Client) checkServerVersionGreaterThanOrEqual(v *version.Version) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadClientServerVersion init the serverVersion variable
|
// loadServerVersion init the serverVersion variable
|
||||||
func (c *Client) loadClientServerVersion() error {
|
func (c *Client) loadServerVersion() (err error) {
|
||||||
c.versionLock.Lock()
|
c.getVersionOnce.Do(func() {
|
||||||
defer c.versionLock.Unlock()
|
raw, _, err2 := c.ServerVersion()
|
||||||
|
if err2 != nil {
|
||||||
raw, _, err := c.ServerVersion()
|
err = err2
|
||||||
if err != nil {
|
return
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
if c.serverVersion, err = version.NewVersion(raw); err != nil {
|
if c.serverVersion, err = version.NewVersion(raw); err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
return nil
|
})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# code.gitea.io/gitea-vet v0.2.1
|
# code.gitea.io/gitea-vet v0.2.1
|
||||||
code.gitea.io/gitea-vet
|
code.gitea.io/gitea-vet
|
||||||
code.gitea.io/gitea-vet/checks
|
code.gitea.io/gitea-vet/checks
|
||||||
# code.gitea.io/sdk/gitea v0.13.2-0.20201112213603-e323ee0bc434
|
# code.gitea.io/sdk/gitea v0.13.1-0.20201129150736-6ea6e887f2fc
|
||||||
code.gitea.io/sdk/gitea
|
code.gitea.io/sdk/gitea
|
||||||
# github.com/AlecAivazis/survey/v2 v2.2.2
|
# github.com/AlecAivazis/survey/v2 v2.2.2
|
||||||
github.com/AlecAivazis/survey/v2
|
github.com/AlecAivazis/survey/v2
|
||||||
|
|
Loading…
Reference in New Issue