Enforce golangci-lint + gofumpt (#587)

- Enforce [gofumpt](https://github.com/mvdan/gofumpt) to enforce a more idiomatic go style.
- Enforce golangci-lint a bunch of linters! Which were able to detect a few issues in the current codebase and have been fixed by this PR.
- Updated the Makefile to use `go install ....` instead of the old deprecated way of `go get`

Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/587
Reviewed-by: John Olheiser <john.olheiser@gmail.com>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Gusted <williamzijl7@hotmail.com>
Co-committed-by: Gusted <williamzijl7@hotmail.com>
This commit is contained in:
Gusted 2022-04-28 23:33:21 +08:00 committed by Lunny Xiao
parent ce9d46682d
commit 8fab37e740
29 changed files with 83 additions and 101 deletions

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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) {

View File

@ -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
}

View File

@ -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
)

View File

@ -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=

View File

@ -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
}
}

View File

@ -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())

View File

@ -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())

View File

@ -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

View File

@ -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)

View File

@ -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
}

View File

@ -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",
})

View File

@ -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{

View File

@ -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 {

View File

@ -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()
}
}

View File

@ -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)

View File

@ -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)

View File

@ -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
}

View File

@ -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{

View File

@ -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"

View File

@ -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"
}

View File

@ -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
}

View File

@ -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)

View File

@ -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

View File

@ -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
}

View File

@ -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:

View File

@ -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