diff --git a/.drone.yml b/.drone.yml index 7dff3b5..335714f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -36,7 +36,7 @@ steps: - name: testing pull: always - image: golang:1.16 + image: golang:1.18 environment: GOPROXY: "https://goproxy.io" GO111MODULE: "on" @@ -48,7 +48,7 @@ steps: commands: - make clean - make vet - - make revive + - make ci-lint - make build - curl --noproxy "*" http://gitea:3000/api/v1/version # verify connection to instance - make test diff --git a/Makefile b/Makefile index 0b3cd15..4509f5f 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,8 @@ clean: .PHONY: fmt fmt: - find . -name "*.go" -type f ! -path "./vendor/*" ! -path "./benchmark/*" | xargs gofmt -s -w + find . -name "*.go" -type f | xargs gofmt -s -w; \ + $(GO) run mvdan.cc/gofumpt@latest -extra -w ./gitea .PHONY: vet vet: @@ -65,16 +66,25 @@ vet: cd gitea && $(GO) build code.gitea.io/gitea-vet cd gitea && $(GO) vet -vettool=gitea-vet $(PACKAGE) -.PHONY: lint -lint: - @echo 'make lint is depricated. Use "make revive" if you want to use the old lint tool, or "make golangci-lint" to run a complete code check.' - -.PHONY: revive -revive: - @hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ - $(GO) get -u github.com/mgechev/revive; \ - fi - revive -config .revive.toml -exclude=./vendor/... ./... || exit 1 +.PHONY: ci-lint +ci-lint: + cd gitea/; \ + $(GO) run github.com/mgechev/revive@latest -config ../.revive.toml .; \ + if [ $$? -eq 1 ]; then \ + echo "Doesn't pass revive"; \ + exit 1; \ + fi; \ + diff=$$($(GO) run mvdan.cc/gofumpt@latest -extra -l .); \ + if [ -n "$$diff" ]; then \ + echo "Not gofumpt-ed"; \ + exit 1; \ + fi; \ + $(GO) run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.44.2 run --timeout 5m; \ + if [ $$? -eq 1 ]; then \ + echo "Doesn't pass golangci-lint"; \ + exit 1; \ + fi; \ + cd -; \ .PHONY: test test: @@ -111,11 +121,3 @@ bench: .PHONY: build build: cd gitea && $(GO) build - -.PHONY: golangci-lint -golangci-lint: - @hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ - export BINARY="golangci-lint"; \ - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.22.2; \ - fi - golangci-lint run --timeout 5m diff --git a/gitea/attachment.go b/gitea/attachment.go index 24c57ba..f02c721 100644 --- a/gitea/attachment.go +++ b/gitea/attachment.go @@ -43,7 +43,7 @@ func (c *Client) ListReleaseAttachments(user, repo string, release int64, opt Li } // GetReleaseAttachment returns the requested attachment -func (c *Client) GetReleaseAttachment(user, repo string, release int64, id int64) (*Attachment, *Response, error) { +func (c *Client) GetReleaseAttachment(user, repo string, release, id int64) (*Attachment, *Response, error) { if err := escapeValidatePathSegments(&user, &repo); err != nil { return nil, nil, err } @@ -88,7 +88,7 @@ type EditAttachmentOptions struct { } // EditReleaseAttachment updates the given attachment with the given options -func (c *Client) EditReleaseAttachment(user, repo string, release int64, attachment int64, form EditAttachmentOptions) (*Attachment, *Response, error) { +func (c *Client) EditReleaseAttachment(user, repo string, release, attachment int64, form EditAttachmentOptions) (*Attachment, *Response, error) { if err := escapeValidatePathSegments(&user, &repo); err != nil { return nil, nil, err } @@ -102,7 +102,7 @@ func (c *Client) EditReleaseAttachment(user, repo string, release int64, attachm } // DeleteReleaseAttachment deletes the given attachment including the uploaded file -func (c *Client) DeleteReleaseAttachment(user, repo string, release int64, id int64) (*Response, error) { +func (c *Client) DeleteReleaseAttachment(user, repo string, release, id int64) (*Response, error) { if err := escapeValidatePathSegments(&user, &repo); err != nil { return nil, err } diff --git a/gitea/client.go b/gitea/client.go index c07e550..a821ddb 100644 --- a/gitea/client.go +++ b/gitea/client.go @@ -199,7 +199,7 @@ func (c *Client) getWebResponse(method, path string, body io.Reader) ([]byte, *R if debug { fmt.Printf("Response: %v\n\n", resp) } - return data, &Response{resp}, nil + return data, &Response{resp}, err } func (c *Client) doRequest(method, path string, header http.Header, body io.Reader) (*Response, error) { @@ -285,7 +285,6 @@ func statusCodeToErr(resp *Response) (body []byte, err error) { // If no error message, at least give status and data return data, fmt.Errorf("%s: %s", resp.Status, string(data)) - } func (c *Client) getResponse(method, path string, header http.Header, body io.Reader) ([]byte, *Response, error) { diff --git a/gitea/fork.go b/gitea/fork.go index 4974c07..0373c35 100644 --- a/gitea/fork.go +++ b/gitea/fork.go @@ -16,7 +16,7 @@ type ListForksOptions struct { } // ListForks list a repository's forks -func (c *Client) ListForks(user string, repo string, opt ListForksOptions) ([]*Repository, *Response, error) { +func (c *Client) ListForks(user, repo string, opt ListForksOptions) ([]*Repository, *Response, error) { if err := escapeValidatePathSegments(&user, &repo); err != nil { return nil, nil, err } diff --git a/gitea/go.mod b/gitea/go.mod index ecf3bc7..bc7f600 100644 --- a/gitea/go.mod +++ b/gitea/go.mod @@ -3,7 +3,6 @@ module code.gitea.io/sdk/gitea go 1.13 require ( - code.gitea.io/gitea-vet v0.2.1 // indirect github.com/hashicorp/go-version v1.4.0 github.com/stretchr/testify v1.7.0 ) diff --git a/gitea/go.sum b/gitea/go.sum index f014ba7..ebae1e4 100644 --- a/gitea/go.sum +++ b/gitea/go.sum @@ -1,5 +1,3 @@ -code.gitea.io/gitea-vet v0.2.1 h1:b30by7+3SkmiftK0RjuXqFvZg2q4p68uoPGuxhzBN0s= -code.gitea.io/gitea-vet v0.2.1/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE= 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/hashicorp/go-version v1.4.0 h1:aAQzgqIrRKRa7w75CKpbBxYsmUoPjzVm1W59ca1L0J4= @@ -9,24 +7,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200325010219-a49f79bcc224 h1:azwY/v0y0K4mFHVsg5+UrTgchqALYWpqVo6vL5OmkmI= -golang.org/x/tools v0.0.0-20200325010219-a49f79bcc224/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/gitea/issue_milestone.go b/gitea/issue_milestone.go index dfb5720..4e0d79a 100644 --- a/gitea/issue_milestone.go +++ b/gitea/issue_milestone.go @@ -72,7 +72,7 @@ func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, *Respon } // GetMilestoneByName get one milestone by repo and milestone name -func (c *Client) GetMilestoneByName(owner, repo string, name string) (*Milestone, *Response, error) { +func (c *Client) GetMilestoneByName(owner, repo, name string) (*Milestone, *Response, error) { if c.checkServerVersionGreaterThanOrEqual(version1_13_0) != nil { // backwards compatibility mode m, resp, err := c.resolveMilestoneByName(owner, repo, name) @@ -163,7 +163,7 @@ func (c *Client) EditMilestone(owner, repo string, id int64, opt EditMilestoneOp } // EditMilestoneByName modify milestone with options -func (c *Client) EditMilestoneByName(owner, repo string, name string, opt EditMilestoneOption) (*Milestone, *Response, error) { +func (c *Client) EditMilestoneByName(owner, repo, name string, opt EditMilestoneOption) (*Milestone, *Response, error) { if c.checkServerVersionGreaterThanOrEqual(version1_13_0) != nil { // backwards compatibility mode m, _, err := c.resolveMilestoneByName(owner, repo, name) @@ -197,7 +197,7 @@ func (c *Client) DeleteMilestone(owner, repo string, id int64) (*Response, error } // DeleteMilestoneByName delete one milestone by name -func (c *Client) DeleteMilestoneByName(owner, repo string, name string) (*Response, error) { +func (c *Client) DeleteMilestoneByName(owner, repo, name string) (*Response, error) { if c.checkServerVersionGreaterThanOrEqual(version1_13_0) != nil { // backwards compatibility mode m, _, err := c.resolveMilestoneByName(owner, repo, name) @@ -229,7 +229,7 @@ func (c *Client) resolveMilestoneByName(owner, repo, name string) (*Milestone, * return nil, nil, fmt.Errorf("milestone '%s' do not exist", name) } for _, m := range miles { - if strings.ToLower(strings.TrimSpace(m.Title)) == strings.ToLower(strings.TrimSpace(name)) { + if strings.EqualFold(strings.TrimSpace(m.Title), strings.TrimSpace(name)) { return m, resp, nil } } diff --git a/gitea/issue_milestone_test.go b/gitea/issue_milestone_test.go index 0de3747..e751689 100644 --- a/gitea/issue_milestone_test.go +++ b/gitea/issue_milestone_test.go @@ -18,7 +18,7 @@ func TestMilestones(t *testing.T) { repo, _ := createTestRepo(t, "TestMilestones", c) now := time.Now() - future := time.Unix(1896134400, 0) //2030-02-01 + future := time.Unix(1896134400, 0) // 2030-02-01 closed := "closed" sClosed := StateClosed @@ -59,7 +59,7 @@ func TestMilestones(t *testing.T) { m, _, err := c.resolveMilestoneByName(repo.Owner.UserName, repo.Name, "V3.0") assert.NoError(t, err) assert.EqualValues(t, ml[0].ID, m.ID) - m, _, err = c.resolveMilestoneByName(repo.Owner.UserName, repo.Name, "NoEvidenceOfExist") + _, _, err = c.resolveMilestoneByName(repo.Owner.UserName, repo.Name, "NoEvidenceOfExist") assert.Error(t, err) assert.EqualValues(t, "milestone 'NoEvidenceOfExist' do not exist", err.Error()) diff --git a/gitea/main_test.go b/gitea/main_test.go index 0e55e13..40c81e5 100644 --- a/gitea/main_test.go +++ b/gitea/main_test.go @@ -82,7 +82,7 @@ func downGitea() (string, error) { continue } - if err = os.Chmod(f.Name(), 700); err != nil { + if err = os.Chmod(f.Name(), 0o700); err != nil { return "", err } @@ -101,7 +101,10 @@ func runGitea() (*os.Process, error) { giteaDir := filepath.Dir(p) cfgDir := filepath.Join(giteaDir, "custom", "conf") - os.MkdirAll(cfgDir, os.ModePerm) + err = os.MkdirAll(cfgDir, os.ModePerm) + if err != nil { + log.Fatal(err) + } cfg, err := os.Create(filepath.Join(cfgDir, "app.ini")) if err != nil { log.Fatal(err) @@ -150,7 +153,9 @@ func TestMain(m *testing.M) { return } defer func() { - p.Kill() + if err := p.Kill(); err != nil { + log.Fatal(err) + } }() } log.Printf("testing with %v, %v, %v\n", getGiteaURL(), getGiteaUsername(), getGiteaPassword()) diff --git a/gitea/notifications.go b/gitea/notifications.go index 3b0fc0f..bb77bb8 100644 --- a/gitea/notifications.go +++ b/gitea/notifications.go @@ -8,12 +8,6 @@ import ( "fmt" "net/url" "time" - - "github.com/hashicorp/go-version" -) - -var ( - version1_12_3, _ = version.NewVersion("1.12.3") ) // NotificationThread expose Notification on API diff --git a/gitea/org_team.go b/gitea/org_team.go index 0285afd..e4de31e 100644 --- a/gitea/org_team.go +++ b/gitea/org_team.go @@ -125,7 +125,7 @@ type CreateTeamOption struct { } // Validate the CreateTeamOption struct -func (opt CreateTeamOption) Validate() error { +func (opt *CreateTeamOption) Validate() error { if opt.Permission == AccessModeOwner { opt.Permission = AccessModeAdmin } else if opt.Permission != AccessModeRead && opt.Permission != AccessModeWrite && opt.Permission != AccessModeAdmin { @@ -148,7 +148,7 @@ func (c *Client) CreateTeam(org string, opt CreateTeamOption) (*Team, *Response, if err := escapeValidatePathSegments(&org); err != nil { return nil, nil, err } - if err := opt.Validate(); err != nil { + if err := (&opt).Validate(); err != nil { return nil, nil, err } body, err := json.Marshal(&opt) @@ -171,7 +171,7 @@ type EditTeamOption struct { } // Validate the EditTeamOption struct -func (opt EditTeamOption) Validate() error { +func (opt *EditTeamOption) Validate() error { if opt.Permission == AccessModeOwner { opt.Permission = AccessModeAdmin } else if opt.Permission != AccessModeRead && opt.Permission != AccessModeWrite && opt.Permission != AccessModeAdmin { @@ -191,7 +191,7 @@ func (opt EditTeamOption) Validate() error { // EditTeam edits a team of an organization func (c *Client) EditTeam(id int64, opt EditTeamOption) (*Response, error) { - if err := opt.Validate(); err != nil { + if err := (&opt).Validate(); err != nil { return nil, err } body, err := json.Marshal(&opt) diff --git a/gitea/pull.go b/gitea/pull.go index 2f41465..e277847 100644 --- a/gitea/pull.go +++ b/gitea/pull.go @@ -12,8 +12,6 @@ import ( "net/url" "strings" "time" - - "github.com/hashicorp/go-version" ) // PRBranchInfo information about a branch @@ -219,8 +217,6 @@ type MergePullRequestOption struct { ForceMerge bool `json:"force_merge"` } -var version1_11_5, _ = version.NewVersion("1.11.5") - // Validate the MergePullRequestOption struct func (opt MergePullRequestOption) Validate(c *Client) error { if opt.Style == MergeStyleSquash { @@ -256,7 +252,6 @@ func (c *Client) IsPullRequestMerged(owner, repo string, index int64) (bool, *Re return false, nil, err } status, resp, err := c.getStatusCode("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d/merge", owner, repo, index), nil, nil) - if err != nil { return false, resp, err } diff --git a/gitea/pull_review_test.go b/gitea/pull_review_test.go index eda75e8..949ab9d 100644 --- a/gitea/pull_review_test.go +++ b/gitea/pull_review_test.go @@ -33,12 +33,12 @@ func TestPullReview(t *testing.T) { } c.SetSudo(submitter.UserName) - r2, _, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{ + _, _, err = c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{ State: ReviewStateApproved, Body: "lgtm it myself", }) assert.Error(t, err) - r2, _, err = c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{ + r2, _, err := c.CreatePullReview(repo.Owner.UserName, repo.Name, pull.Index, CreatePullReviewOptions{ State: ReviewStateComment, Body: "no seriously please have a look at it", }) diff --git a/gitea/pull_test.go b/gitea/pull_test.go index 657813a..f3b31b9 100644 --- a/gitea/pull_test.go +++ b/gitea/pull_test.go @@ -74,6 +74,7 @@ func TestPull(t *testing.T) { // test Update pull pr, _, err := c.GetPullRequest(user.UserName, repoName, pullUpdateFile.Index) assert.NoError(t, err) + assert.NotNil(t, pr) assert.False(t, pullUpdateFile.HasMerged) assert.True(t, pullUpdateFile.Mergeable) merged, _, err := c.MergePullRequest(user.UserName, repoName, pullUpdateFile.Index, MergePullRequestOption{ diff --git a/gitea/release.go b/gitea/release.go index 8235ada..3200f20 100644 --- a/gitea/release.go +++ b/gitea/release.go @@ -79,7 +79,7 @@ func (c *Client) GetRelease(owner, repo string, id int64) (*Release, *Response, } // GetReleaseByTag get a release of a repository by tag -func (c *Client) GetReleaseByTag(owner, repo string, tag string) (*Release, *Response, error) { +func (c *Client) GetReleaseByTag(owner, repo, tag string) (*Release, *Response, error) { if c.checkServerVersionGreaterThanOrEqual(version1_13_0) != nil { return c.fallbackGetReleaseByTag(owner, repo, tag) } @@ -168,7 +168,7 @@ func (c *Client) DeleteRelease(user, repo string, id int64) (*Response, error) { } // DeleteReleaseByTag deletes a release frm a repository by tag -func (c *Client) DeleteReleaseByTag(user, repo string, tag string) (*Response, error) { +func (c *Client) DeleteReleaseByTag(user, repo, tag string) (*Response, error) { if err := escapeValidatePathSegments(&user, &repo, &tag); err != nil { return nil, err } @@ -182,7 +182,7 @@ func (c *Client) DeleteReleaseByTag(user, repo string, tag string) (*Response, e } // fallbackGetReleaseByTag is fallback for old gitea installations ( < 1.13.0 ) -func (c *Client) fallbackGetReleaseByTag(owner, repo string, tag string) (*Release, *Response, error) { +func (c *Client) fallbackGetReleaseByTag(owner, repo, tag string) (*Release, *Response, error) { for i := 1; ; i++ { rl, resp, err := c.ListReleases(owner, repo, ListReleasesOptions{ListOptions: ListOptions{Page: i}}) if err != nil { diff --git a/gitea/repo.go b/gitea/repo.go index 7ccde53..8f0e346 100644 --- a/gitea/repo.go +++ b/gitea/repo.go @@ -287,7 +287,9 @@ func (c *Client) SearchRepos(opt SearchRepoOptions) ([]*Repository, *Response, e // private repos only not supported on gitea <= 1.11.x return nil, nil, err } - link.Query().Add("private", "false") + newQuery := link.Query() + newQuery.Add("private", "false") + link.RawQuery = newQuery.Encode() } } diff --git a/gitea/repo_collaborator.go b/gitea/repo_collaborator.go index c766250..ab730df 100644 --- a/gitea/repo_collaborator.go +++ b/gitea/repo_collaborator.go @@ -66,7 +66,7 @@ const ( ) // Validate the AddCollaboratorOption struct -func (opt AddCollaboratorOption) Validate() error { +func (opt *AddCollaboratorOption) Validate() error { if opt.Permission != nil { if *opt.Permission == AccessModeOwner { *opt.Permission = AccessModeAdmin @@ -88,7 +88,7 @@ func (c *Client) AddCollaborator(user, repo, collaborator string, opt AddCollabo if err := escapeValidatePathSegments(&user, &repo, &collaborator); err != nil { return nil, err } - if err := opt.Validate(); err != nil { + if err := (&opt).Validate(); err != nil { return nil, err } body, err := json.Marshal(&opt) diff --git a/gitea/repo_collaborator_test.go b/gitea/repo_collaborator_test.go index d059ba8..6860214 100644 --- a/gitea/repo_collaborator_test.go +++ b/gitea/repo_collaborator_test.go @@ -18,8 +18,12 @@ func TestRepoCollaborator(t *testing.T) { repo, _ := createTestRepo(t, "RepoCollaborators", c) createTestUser(t, "ping", c) createTestUser(t, "pong", c) - defer c.AdminDeleteUser("ping") - defer c.AdminDeleteUser("pong") + defer func() { + _, err := c.AdminDeleteUser("ping") + assert.NoError(t, err) + _, err = c.AdminDeleteUser("pong") + assert.NoError(t, err) + }() collaborators, _, err := c.ListCollaborators(repo.Owner.UserName, repo.Name, ListCollaboratorsOptions{}) assert.NoError(t, err) diff --git a/gitea/repo_commit.go b/gitea/repo_commit.go index 5714173..cf53ede 100644 --- a/gitea/repo_commit.go +++ b/gitea/repo_commit.go @@ -83,7 +83,7 @@ func (c *Client) GetSingleCommit(user, repo, commitID string) (*Commit, *Respons // ListCommitOptions list commit options type ListCommitOptions struct { ListOptions - //SHA or branch to start listing commits from (usually 'master') + // SHA or branch to start listing commits from (usually 'master') SHA string } diff --git a/gitea/repo_file_test.go b/gitea/repo_file_test.go index ed8403d..9e606d6 100644 --- a/gitea/repo_file_test.go +++ b/gitea/repo_file_test.go @@ -65,6 +65,7 @@ func TestFileCreateUpdateGet(t *testing.T) { licence, _, err := c.GetContents(repo.Owner.UserName, repo.Name, "", "LICENSE") assert.NoError(t, err) licenceRaw, _, err := c.GetFile(repo.Owner.UserName, repo.Name, "", "LICENSE") + assert.NoError(t, err) testContent := "Tk9USElORyBJUyBIRVJFIEFOWU1PUkUKSUYgWU9VIExJS0UgVE8gRklORCBTT01FVEhJTkcKV0FJVCBGT1IgVEhFIEZVVFVSRQo=" updatedFile, _, err = c.UpdateFile(repo.Owner.UserName, repo.Name, "LICENSE", UpdateFileOptions{ FileOptions: FileOptions{ diff --git a/gitea/repo_migrate.go b/gitea/repo_migrate.go index cd0fe44..3ab690e 100644 --- a/gitea/repo_migrate.go +++ b/gitea/repo_migrate.go @@ -16,7 +16,7 @@ type GitServiceType string const ( // GitServicePlain represents a plain git service GitServicePlain GitServiceType = "git" - //GitServiceGithub represents github.com + // GitServiceGithub represents github.com GitServiceGithub GitServiceType = "github" // GitServiceGitlab represents a gitlab service GitServiceGitlab GitServiceType = "gitlab" diff --git a/gitea/repo_tree.go b/gitea/repo_tree.go index 452394a..c9ffc55 100644 --- a/gitea/repo_tree.go +++ b/gitea/repo_tree.go @@ -35,7 +35,7 @@ func (c *Client) GetTrees(user, repo, ref string, recursive bool) (*GitTreeRespo return nil, nil, err } trees := new(GitTreeResponse) - var path = fmt.Sprintf("/repos/%s/%s/git/trees/%s", user, repo, ref) + path := fmt.Sprintf("/repos/%s/%s/git/trees/%s", user, repo, ref) if recursive { path += "?recursive=1" } diff --git a/gitea/repo_watch.go b/gitea/repo_watch.go index f499aff..c36ca64 100644 --- a/gitea/repo_watch.go +++ b/gitea/repo_watch.go @@ -33,7 +33,7 @@ func (c *Client) GetWatchedRepos(user string) ([]*Repository, *Response, error) // GetMyWatchedRepos list repositories watched by the authenticated user func (c *Client) GetMyWatchedRepos() ([]*Repository, *Response, error) { repos := make([]*Repository, 0, 10) - resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/subscriptions"), nil, nil, &repos) + resp, err := c.getParsedResponse("GET", "/user/subscriptions", nil, nil, &repos) return repos, resp, err } diff --git a/gitea/repo_watch_test.go b/gitea/repo_watch_test.go index 2c56281..8e74d7b 100644 --- a/gitea/repo_watch_test.go +++ b/gitea/repo_watch_test.go @@ -22,29 +22,29 @@ func TestRepoWatch(t *testing.T) { repo2, _ := createTestRepo(t, "TestRepoWatch_2", c) assert.NotEqual(t, repo1, repo2) - //GetWatchedRepos + // GetWatchedRepos wl, _, err := c.GetWatchedRepos("test01") assert.NoError(t, err) assert.NotNil(t, wl) maxcount := len(wl) - //GetMyWatchedRepos + // GetMyWatchedRepos wl, _, err = c.GetMyWatchedRepos() assert.NoError(t, err) assert.Len(t, wl, maxcount) - //CheckRepoWatch + // CheckRepoWatch isWatching, _, err := c.CheckRepoWatch(repo1.Owner.UserName, repo1.Name) assert.NoError(t, err) assert.True(t, isWatching) - //UnWatchRepo + // UnWatchRepo _, err = c.UnWatchRepo(repo1.Owner.UserName, repo1.Name) assert.NoError(t, err) isWatching, _, _ = c.CheckRepoWatch(repo1.Owner.UserName, repo1.Name) assert.False(t, isWatching) - //WatchRepo + // WatchRepo _, err = c.WatchRepo(repo1.Owner.UserName, repo1.Name) assert.NoError(t, err) isWatching, _, _ = c.CheckRepoWatch(repo1.Owner.UserName, repo1.Name) diff --git a/gitea/status_test.go b/gitea/status_test.go index 2bb3358..a1f78d5 100644 --- a/gitea/status_test.go +++ b/gitea/status_test.go @@ -17,7 +17,7 @@ func TestCommitStatus(t *testing.T) { user, _, err := c.GetMyUserInfo() assert.NoError(t, err) - var repoName = "CommitStatuses" + repoName := "CommitStatuses" origRepo, err := createTestRepo(t, repoName, c) if !assert.NoError(t, err) { return diff --git a/gitea/user.go b/gitea/user.go index c37627b..67208fb 100644 --- a/gitea/user.go +++ b/gitea/user.go @@ -77,7 +77,6 @@ func (c *Client) GetUserByID(id int64) (*User, *Response, error) { query := make(url.Values) query.Add("uid", strconv.FormatInt(id, 10)) users, resp, err := c.searchUsers(query.Encode()) - if err != nil { return nil, resp, err } diff --git a/gitea/user_app.go b/gitea/user_app.go index 88b01ed..eb3ef21 100644 --- a/gitea/user_app.go +++ b/gitea/user_app.go @@ -71,7 +71,7 @@ func (c *Client) DeleteAccessToken(value interface{}) (*Response, error) { return nil, fmt.Errorf("\"username\" not set: only BasicAuth allowed") } - var token = "" + token := "" switch reflect.ValueOf(value).Kind() { case reflect.Int64: diff --git a/gitea/version.go b/gitea/version.go index a7c62f8..83f6df9 100644 --- a/gitea/version.go +++ b/gitea/version.go @@ -52,7 +52,6 @@ func SetGiteaVersion(v string) ClientOption { return func(c *Client) (err error) { c.getVersionOnce.Do(func() { c.serverVersion, err = version.NewVersion(v) - return }) return } @@ -60,12 +59,14 @@ func SetGiteaVersion(v string) ClientOption { // predefined versions only have to be parsed by library once var ( - version1_11_0, _ = version.NewVersion("1.11.0") - version1_12_0, _ = version.NewVersion("1.12.0") - version1_13_0, _ = version.NewVersion("1.13.0") - version1_14_0, _ = version.NewVersion("1.14.0") - version1_15_0, _ = version.NewVersion("1.15.0") - version1_16_0, _ = version.NewVersion("1.16.0") + version1_11_0 = version.Must(version.NewVersion("1.11.0")) + version1_11_5 = version.Must(version.NewVersion("1.11.5")) + version1_12_0 = version.Must(version.NewVersion("1.12.0")) + version1_12_3 = version.Must(version.NewVersion("1.12.3")) + version1_13_0 = version.Must(version.NewVersion("1.13.0")) + version1_14_0 = version.Must(version.NewVersion("1.14.0")) + version1_15_0 = version.Must(version.NewVersion("1.15.0")) + version1_16_0 = version.Must(version.NewVersion("1.16.0")) ) // checkServerVersionGreaterThanOrEqual is the canonical way in the SDK to check for versions for API compatibility reasons