From 1bb832a764bd318b9a676d7670cdcd62822aef47 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 2 Oct 2020 04:06:21 +0200 Subject: [PATCH] chore(deps): bump code.gitea.io/sdk/gitea from v0.12.1 to v0.13.1 (#1828) * chore(deps): bump code.gitea.io/sdk/gitea from v0.12.1 to v0.13.1 * only set Context if not nil --- go.mod | 2 +- go.sum | 4 +-- internal/client/gitea.go | 61 ++++++++++++----------------------- internal/client/gitea_test.go | 5 ++- 4 files changed, 27 insertions(+), 45 deletions(-) diff --git a/go.mod b/go.mod index 568c4c385..4466cd72c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/goreleaser/goreleaser go 1.15 require ( - code.gitea.io/sdk/gitea v0.12.1 + code.gitea.io/sdk/gitea v0.13.1 github.com/Masterminds/semver/v3 v3.1.0 github.com/apex/log v1.9.0 github.com/caarlos0/ctrlc v1.0.0 diff --git a/go.sum b/go.sum index c6d1d8b06..16051483e 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.9.0 h1:oXnZyBjHB6hC8TnSle0AWW6pGJ29EuSo5ww+SFmdNBg= cloud.google.com/go/storage v1.9.0/go.mod h1:m+/etGaqZbylxaNT876QGXqEHp4PR2Rq5GMqICWb9bU= -code.gitea.io/sdk/gitea v0.12.1 h1:bMgjEqPnNX/i6TpVwXwpjJtFOnUSuC9P6yy/jjy8sjY= -code.gitea.io/sdk/gitea v0.12.1/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY= +code.gitea.io/sdk/gitea v0.13.1 h1:Y7bpH2iO6Q0KhhMJfjP/LZ0AmiYITeRQlCD8b0oYqhk= +code.gitea.io/sdk/gitea v0.13.1/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY= contrib.go.opencensus.io/exporter/aws v0.0.0-20181029163544-2befc13012d0/go.mod h1:uu1P0UCM/6RbsMrgPa98ll8ZcHM858i/AD06a9aLRCA= contrib.go.opencensus.io/exporter/stackdriver v0.12.1/go.mod h1:iwB6wGarfphGGe/e5CWqyUk/cLzKnWsOKPVW3no6OTw= contrib.go.opencensus.io/integrations/ocsql v0.1.4/go.mod h1:8DsSdjz3F+APR+0z0WkU1aRorQCFfRxvqjUUPMbF3fE= diff --git a/internal/client/gitea.go b/internal/client/gitea.go index 8551e73fc..48808425e 100644 --- a/internal/client/gitea.go +++ b/internal/client/gitea.go @@ -39,7 +39,6 @@ func NewGitea(ctx *context.Context, token string) (Client, error) { if err != nil { return nil, err } - client := gitea.NewClient(instanceURL, token) transport := &http.Transport{ TLSClientConfig: &tls.Config{ // nolint: gosec @@ -47,33 +46,31 @@ func NewGitea(ctx *context.Context, token string) (Client, error) { }, } httpClient := &http.Client{Transport: transport} - client.SetHTTPClient(httpClient) + client, err := gitea.NewClient(instanceURL, + gitea.SetToken(token), + gitea.SetHTTPClient(httpClient), + ) + if err != nil { + return nil, err + } + if ctx != nil { + gitea.SetContext(ctx)(client) + } return &giteaClient{client: client}, nil } // CloseMilestone closes a given milestone. func (c *giteaClient) CloseMilestone(ctx *context.Context, repo Repo, title string) error { - milestone, err := c.getMilestoneByTitle(repo, title) - - if err != nil { - return err + closedState := gitea.StateClosed + opts := gitea.EditMilestoneOption{ + State: &closedState, + Title: title, } - if milestone == nil { + _, resp, err := c.client.EditMilestoneByName(repo.Owner, repo.Name, title, opts) + if resp != nil && resp.StatusCode == http.StatusNotFound { return ErrNoMilestoneFound{Title: title} } - - closedState := string(gitea.StateClosed) - - opts := gitea.EditMilestoneOption{ - Deadline: milestone.Deadline, - Description: &milestone.Description, - State: &closedState, - Title: milestone.Title, - } - - _, err = c.client.EditMilestone(repo.Owner, repo.Name, milestone.ID, opts) - return err } @@ -105,7 +102,7 @@ func (c *giteaClient) createRelease(ctx *context.Context, title, body string) (* IsDraft: releaseConfig.Draft, IsPrerelease: ctx.PreRelease, } - release, err := c.client.CreateRelease(owner, repoName, opts) + release, _, err := c.client.CreateRelease(owner, repoName, opts) if err != nil { log.WithFields(log.Fields{ "err": err.Error(), @@ -117,7 +114,7 @@ func (c *giteaClient) createRelease(ctx *context.Context, title, body string) (* } func (c *giteaClient) getExistingRelease(owner, repoName, tagName string) (*gitea.Release, error) { - releases, err := c.client.ListReleases(owner, repoName, gitea.ListReleasesOptions{}) + releases, _, err := c.client.ListReleases(owner, repoName, gitea.ListReleasesOptions{}) if err != nil { return nil, err } @@ -146,7 +143,7 @@ func (c *giteaClient) updateRelease(ctx *context.Context, title, body string, id IsPrerelease: &ctx.PreRelease, } - release, err := c.client.EditRelease(owner, repoName, id, opts) + release, _, err := c.client.EditRelease(owner, repoName, id, opts) if err != nil { log.WithFields(log.Fields{ "err": err.Error(), @@ -213,27 +210,9 @@ func (c *giteaClient) Upload( owner := releaseConfig.Gitea.Owner repoName := releaseConfig.Gitea.Name - _, err = c.client.CreateReleaseAttachment(owner, repoName, giteaReleaseID, file, artifact.Name) + _, _, err = c.client.CreateReleaseAttachment(owner, repoName, giteaReleaseID, file, artifact.Name) if err != nil { return RetriableError{err} } return nil } - -// getMilestoneByTitle returns a milestone by title. -func (c *giteaClient) getMilestoneByTitle(repo Repo, title string) (*gitea.Milestone, error) { - // The Gitea API/SDK does not provide lookup by title functionality currently. - milestones, err := c.client.ListRepoMilestones(repo.Owner, repo.Name, gitea.ListMilestoneOption{}) - - if err != nil { - return nil, err - } - - for _, milestone := range milestones { - if milestone.Title == title { - return milestone, nil - } - } - - return nil, nil -} diff --git a/internal/client/gitea_test.go b/internal/client/gitea_test.go index f7a5d9c3e..2bc1ec8fb 100644 --- a/internal/client/gitea_test.go +++ b/internal/client/gitea_test.go @@ -120,7 +120,10 @@ func (s *GiteaReleasesTestSuite) SetupTest() { } s.releaseID = 666 s.releaseURL = fmt.Sprintf("%v/%v", s.releasesURL, s.releaseID) - s.client = &giteaClient{client: gitea.NewClient(s.url, "")} + httpmock.RegisterResponder("GET", fmt.Sprintf("%s/api/v1/version", s.url), httpmock.NewStringResponder(200, "{\"version\":\"1.12.0\"}")) + newClient, err := gitea.NewClient(s.url) + assert.NoError(s.T(), err) + s.client = &giteaClient{client: newClient} } func (s *GiteaReleasesTestSuite) TearDownTest() {