Repository: goreleaser/goreleaser
Pull request #1828 (2020-09-30 23:30:21)

chore(deps): bump code.gitea.io/sdk/gitea from v0.12.1 to v0.13.1
follow up of  #1806

close #1827

6543: @caarlos0 hope you dont have to revert this one ...

next round ;)
6543: ok need more investigation ...
codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1828?src=pr&el=h1) Report
> Merging [#1828](https://codecov.io/gh/goreleaser/goreleaser/pull/1828?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/c55267f49f5f036dc296d68a7d787c578a262563?el=desc) will **increase** coverage by `0.21%`.
> The diff coverage is `55.55%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/1828/graphs/tree.svg?width=650&height=150&src=pr&token=3bJvv6b7hN)](https://codecov.io/gh/goreleaser/goreleaser/pull/1828?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1828      +/-   ##
==========================================
+ Coverage   81.01%   81.23%   +0.21%     
==========================================
  Files          72       72              
  Lines        3692     3687       -5     
==========================================
+ Hits         2991     2995       +4     
+ Misses        580      570      -10     
- Partials      121      122       +1     
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/1828?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [internal/client/gitea.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1828/diff?src=pr&el=tree#diff-aW50ZXJuYWwvY2xpZW50L2dpdGVhLmdv) | `90.26% <55.55%> (+7.21%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1828?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1828?src=pr&el=footer). Last update [c55267f...5882140](https://codecov.io/gh/goreleaser/goreleaser/pull/1828?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

6543: @caarlos0 5882140c916dedb240a4de60bbe79a142f4be619 did it

Patch:
diff --git a/go.mod b/go.mod
index 568c4c38..4466cd72 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 c6d1d8b0..16051483 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 8551e73f..48808425 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
-}


Test patch:
diff --git a/internal/client/gitea_test.go b/internal/client/gitea_test.go
index f7a5d9c3..2bc1ec8f 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() {