1
0
mirror of https://gitea.com/jolheiser/sip synced 2024-11-22 19:51:58 +01:00

Update Gitea SDK (#23)

Update Gitea SDK

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Co-authored-by: jolheiser <john.olheiser@gmail.com>
Reviewed-on: https://gitea.com/jolheiser/sip/pulls/23
This commit is contained in:
John Olheiser 2020-09-15 18:02:45 +00:00
parent 40e256e8b9
commit 8db0c08253
13 changed files with 22 additions and 18 deletions

@ -67,7 +67,7 @@ func getToken(name string) string {
func getClient(ctx *cli.Context, requireToken bool) (*gitea.Client, error) { func getClient(ctx *cli.Context, requireToken bool) (*gitea.Client, error) {
if ctx.IsSet("token") { if ctx.IsSet("token") {
return gitea.NewClient(ctx.String("url"), getToken(ctx.String("token"))), nil return gitea.NewClient(ctx.String("url"), gitea.SetToken(getToken(ctx.String("token"))))
} }
var token string var token string
@ -93,7 +93,7 @@ func getClient(ctx *cli.Context, requireToken bool) (*gitea.Client, error) {
token = tokenMap[answer].Token token = tokenMap[answer].Token
} }
return gitea.NewClient(ctx.String("url"), token), nil return gitea.NewClient(ctx.String("url"), gitea.SetToken(token))
} }
func defRemote(remote, def string) string { func defRemote(remote, def string) string {

@ -67,7 +67,7 @@ func doIssueCreate(ctx *cli.Context) error {
} }
} }
issue, err := client.CreateIssue(ctx.String("owner"), ctx.String("repo"), gitea.CreateIssueOption{Title: title, Body: body}) issue, _, err := client.CreateIssue(ctx.String("owner"), ctx.String("repo"), gitea.CreateIssueOption{Title: title, Body: body})
if err != nil { if err != nil {
return err return err
} }

@ -57,7 +57,7 @@ func doPullCheckout(ctx *cli.Context) error {
} }
} }
} else { } else {
iss, err := client.GetIssue(upstreamRepo[1], upstreamRepo[2], prNum.Index) iss, _, err := client.GetIssue(upstreamRepo[1], upstreamRepo[2], prNum.Index)
if err != nil { if err != nil {
return err return err
} }

@ -29,7 +29,7 @@ func doPullCreate(ctx *cli.Context) error {
return err return err
} }
upstreams, err := client.ListRepoBranches(getUpstreamRepo()[1], getUpstreamRepo()[2], gitea.ListRepoBranchesOptions{}) upstreams, _, err := client.ListRepoBranches(getUpstreamRepo()[1], getUpstreamRepo()[2], gitea.ListRepoBranchesOptions{})
if err != nil { if err != nil {
return err return err
} }
@ -42,7 +42,7 @@ func doPullCreate(ctx *cli.Context) error {
bases[idx] = upstream.Name bases[idx] = upstream.Name
} }
origins, err := client.ListRepoBranches(getOriginRepo()[1], getOriginRepo()[2], gitea.ListRepoBranchesOptions{}) origins, _, err := client.ListRepoBranches(getOriginRepo()[1], getOriginRepo()[2], gitea.ListRepoBranchesOptions{})
if err != nil { if err != nil {
return err return err
} }
@ -114,7 +114,7 @@ func doPullCreate(ctx *cli.Context) error {
} }
} }
pull, err := client.CreatePullRequest(ctx.String("owner"), ctx.String("repo"), gitea.CreatePullRequestOption{Title: title, Body: body, Base: base, Head: head}) pull, _, err := client.CreatePullRequest(ctx.String("owner"), ctx.String("repo"), gitea.CreatePullRequestOption{Title: title, Body: body, Base: base, Head: head})
if err != nil { if err != nil {
if fmt.Sprint(err) == "409 Conflict" { // Hard-coded in the SDK if fmt.Sprint(err) == "409 Conflict" { // Hard-coded in the SDK
return existingPR(client, getUpstreamRepo()[1], getUpstreamRepo()[2], head, err) return existingPR(client, getUpstreamRepo()[1], getUpstreamRepo()[2], head, err)
@ -130,7 +130,7 @@ func doPullCreate(ctx *cli.Context) error {
} }
func existingPR(client *gitea.Client, owner, repo, head string, pullErr error) error { func existingPR(client *gitea.Client, owner, repo, head string, pullErr error) error {
pulls, err := client.ListRepoPullRequests(owner, repo, gitea.ListPullRequestsOptions{State: "open"}) pulls, _, err := client.ListRepoPullRequests(owner, repo, gitea.ListPullRequestsOptions{State: "open"})
if err != nil { if err != nil {
return err return err
} }

@ -68,7 +68,7 @@ func doReleaseCreate(ctx *cli.Context) error {
return err return err
} }
release, err := client.CreateRelease(ctx.String("owner"), ctx.String("repo"), gitea.CreateReleaseOption{ release, _, err := client.CreateRelease(ctx.String("owner"), ctx.String("repo"), gitea.CreateReleaseOption{
TagName: answers.Tag, TagName: answers.Tag,
Target: answers.Target, Target: answers.Target,
Title: answers.Title, Title: answers.Title,

@ -68,7 +68,7 @@ func doRepoCreate(ctx *cli.Context) error {
opts.Readme = auto.Readme opts.Readme = auto.Readme
} }
repo, err := client.CreateRepo(opts) repo, _, err := client.CreateRepo(opts)
if err != nil { if err != nil {
return err return err
} }

@ -75,13 +75,15 @@ func doTokenAdd(ctx *cli.Context) error {
return err return err
} }
client := gitea.NewClient(answers.URL, "") client, err := gitea.NewClient(answers.URL, gitea.SetBasicAuth(giteaAnswers.Username, giteaAnswers.Password))
client.SetBasicAuth(giteaAnswers.Username, giteaAnswers.Password) if err != nil {
return err
}
if giteaAnswers.OTP != "" { if giteaAnswers.OTP != "" {
client.SetOTP(giteaAnswers.OTP) client.SetOTP(giteaAnswers.OTP)
} }
t, err := client.CreateAccessToken(gitea.CreateAccessTokenOption{Name: giteaAnswers.Token}) t, _, err := client.CreateAccessToken(gitea.CreateAccessTokenOption{Name: giteaAnswers.Token})
if err != nil { if err != nil {
return err return err
} }

2
go.mod

@ -3,7 +3,7 @@ module gitea.com/jolheiser/sip
go 1.13 go 1.13
require ( require (
code.gitea.io/sdk/gitea v0.12.2 code.gitea.io/sdk/gitea v0.13.0
github.com/AlecAivazis/survey/v2 v2.1.1 github.com/AlecAivazis/survey/v2 v2.1.1
github.com/BurntSushi/toml v0.3.1 github.com/BurntSushi/toml v0.3.1
github.com/alecthomas/chroma v0.8.0 // indirect github.com/alecthomas/chroma v0.8.0 // indirect

2
go.sum

@ -1,5 +1,7 @@
code.gitea.io/sdk/gitea v0.12.2 h1:NQI8b/CT9AEQjsxbVIZ6gsPUXv38moT5y1ocN7n1YcQ= code.gitea.io/sdk/gitea v0.12.2 h1:NQI8b/CT9AEQjsxbVIZ6gsPUXv38moT5y1ocN7n1YcQ=
code.gitea.io/sdk/gitea v0.12.2/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY= code.gitea.io/sdk/gitea v0.12.2/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY=
code.gitea.io/sdk/gitea v0.13.0 h1:iHognp8ZMhMFLooUUNZFpm8IHaC9qoHJDvAE5vTm5aw=
code.gitea.io/sdk/gitea v0.13.0/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY=
github.com/AlecAivazis/survey/v2 v2.1.1 h1:LEMbHE0pLj75faaVEKClEX1TM4AJmmnOh9eimREzLWI= github.com/AlecAivazis/survey/v2 v2.1.1 h1:LEMbHE0pLj75faaVEKClEX1TM4AJmmnOh9eimREzLWI=
github.com/AlecAivazis/survey/v2 v2.1.1/go.mod h1:9FJRdMdDm8rnT+zHVbvQT2RTSTLq0Ttd6q3Vl2fahjk= github.com/AlecAivazis/survey/v2 v2.1.1/go.mod h1:9FJRdMdDm8rnT+zHVbvQT2RTSTLq0Ttd6q3Vl2fahjk=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=

@ -14,7 +14,7 @@ func GetIssues(client *gitea.Client, owner, repo string, opts gitea.ListIssueOpt
p := 1 p := 1
for { for {
opts.Page = p opts.Page = p
list, err := client.ListRepoIssues(owner, repo, opts) list, _, err := client.ListRepoIssues(owner, repo, opts)
if err != nil { if err != nil {
return issues, err return issues, err
} }

@ -10,7 +10,7 @@ func GetPulls(client *gitea.Client, owner, repo string, opts gitea.ListPullReque
p := 1 p := 1
for { for {
opts.Page = p opts.Page = p
list, err := client.ListRepoPullRequests(owner, repo, opts) list, _, err := client.ListRepoPullRequests(owner, repo, opts)
if err != nil { if err != nil {
return pulls, err return pulls, err
} }

@ -8,7 +8,7 @@ func GetReleases(client *gitea.Client, owner, repo string, opts gitea.ListReleas
p := 1 p := 1
for { for {
opts.Page = p opts.Page = p
list, err := client.ListReleases(owner, repo, opts) list, _, err := client.ListReleases(owner, repo, opts)
if err != nil { if err != nil {
return releases, err return releases, err
} }

@ -7,7 +7,7 @@ func GetForks(client *gitea.Client, owner, repo string) ([]*gitea.Repository, er
forks := make([]*gitea.Repository, 0) forks := make([]*gitea.Repository, 0)
p := 1 p := 1
for { for {
list, err := client.ListForks(owner, repo, gitea.ListForksOptions{ list, _, err := client.ListForks(owner, repo, gitea.ListForksOptions{
ListOptions: gitea.ListOptions{ ListOptions: gitea.ListOptions{
Page: p, Page: p,
PageSize: 100, PageSize: 100,