Skip to content

Commit 4feeb65

Browse files
committed
Merge branch 'master' into fix-go-gitea#6946-pass-in-pr-into-hooks
2 parents 757c395 + 2f39fc7 commit 4feeb65

File tree

206 files changed

+2809
-1626
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+2809
-1626
lines changed

.drone.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ pipeline:
77
image: docker:git
88
commands:
99
- git fetch --tags --force
10+
when:
11+
event:
12+
exclude: [ pull_request ]
1013

1114
download_translations:
1215
image: jonasfranz/crowdin
@@ -71,12 +74,10 @@ pipeline:
7174
commands:
7275
- make clean
7376
- make generate
74-
- make vet
75-
- make lint
76-
- make fmt-check
77+
- make golangci-lint
78+
- make revive
7779
- make swagger-check
7880
- make swagger-validate
79-
- make misspell-check
8081
- make test-vendor
8182
- make build
8283
when:

.golangci.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
linters:
2+
enable:
3+
- gosimple
4+
- deadcode
5+
- typecheck
6+
- govet
7+
- errcheck
8+
- staticcheck
9+
- unused
10+
- structcheck
11+
- varcheck
12+
- golint
13+
- dupl
14+
#- gocyclo # The cyclomatic complexety of a lot of functions is too high, we should refactor those another time.
15+
- gofmt
16+
- misspell
17+
- gocritic
18+
enable-all: false
19+
disable-all: true
20+
fast: false
21+
22+
linters-settings:
23+
gocritic:
24+
disabled-checks:
25+
- ifElseChain
26+
- singleCaseSwitch # Every time this occured in the code, there was no other way.
27+
28+
issues:
29+
exclude-rules:
30+
# Exclude some linters from running on tests files.
31+
- path: _test\.go
32+
linters:
33+
- gocyclo
34+
- errcheck
35+
- dupl
36+
- gosec
37+
- unparam
38+
- staticcheck
39+
- path: models/migrations/v
40+
linters:
41+
- gocyclo
42+
- errcheck
43+
- dupl
44+
- gosec
45+
- linters:
46+
- dupl
47+
text: "webhook"
48+
- linters:
49+
- gocritic
50+
text: "`ID' should not be capitalized"
51+
- path: modules/templates/helper.go
52+
linters:
53+
- gocritic
54+
- linters:
55+
- unused
56+
- deadcode
57+
text: "swagger"
58+
- path: contrib/pr/checkout.go
59+
linters:
60+
- errcheck
61+
- path: models/issue.go
62+
linters:
63+
- errcheck
64+
- path: models/migrations/
65+
linters:
66+
- errcheck
67+
- path: modules/log/
68+
linters:
69+
- errcheck
70+
- path: routers/routes/routes.go
71+
linters:
72+
- dupl
73+
- path: routers/repo/view.go
74+
linters:
75+
- dupl
76+
- path: models/migrations/
77+
linters:
78+
- unused
79+
- linters:
80+
- staticcheck
81+
text: "argument x is overwritten before first use"
82+
- path: modules/httplib/httplib.go
83+
linters:
84+
- staticcheck
85+
# Enabling this would require refactoring the methods and how they are called.
86+
- path: models/issue_comment_list.go
87+
linters:
88+
- dupl
89+
# "Destroy" is misspelled in github.com/go-macaron/session/session.go:213 so it's not our responsability to fix it
90+
- path: modules/session/virtual.go
91+
linters:
92+
- misspell
93+
text: '`Destory` is a misspelling of `Destroy`'
94+
- path: modules/session/memory.go
95+
linters:
96+
- misspell
97+
text: '`Destory` is a misspelling of `Destroy`'

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ errcheck:
135135

136136
.PHONY: lint
137137
lint:
138+
@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.'
139+
140+
.PHONY: revive
141+
revive:
138142
@hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
139143
$(GO) get -u github.com/mgechev/revive; \
140144
fi
@@ -461,3 +465,11 @@ generate-images:
461465
.PHONY: pr
462466
pr:
463467
$(GO) run contrib/pr/checkout.go $(PR)
468+
469+
.PHONY: golangci-lint
470+
golangci-lint:
471+
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
472+
export BINARY="golangci-lint"; \
473+
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.16.0; \
474+
fi
475+
golangci-lint run

cmd/admin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ func runUpdateOauth(c *cli.Context) error {
481481
}
482482

483483
// update custom URL mapping
484-
var customURLMapping *oauth2.CustomURLMapping
484+
var customURLMapping = &oauth2.CustomURLMapping{}
485485

486486
if oAuth2Config.CustomURLMapping != nil {
487487
customURLMapping.TokenURL = oAuth2Config.CustomURLMapping.TokenURL

cmd/cert.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,28 @@ func runCert(c *cli.Context) error {
170170
if err != nil {
171171
log.Fatalf("Failed to open cert.pem for writing: %v", err)
172172
}
173-
pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
174-
certOut.Close()
173+
err = pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
174+
if err != nil {
175+
log.Fatalf("Failed to encode certificate: %v", err)
176+
}
177+
err = certOut.Close()
178+
if err != nil {
179+
log.Fatalf("Failed to write cert: %v", err)
180+
}
175181
log.Println("Written cert.pem")
176182

177183
keyOut, err := os.OpenFile("key.pem", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
178184
if err != nil {
179185
log.Fatalf("Failed to open key.pem for writing: %v", err)
180186
}
181-
pem.Encode(keyOut, pemBlockForKey(priv))
182-
keyOut.Close()
187+
err = pem.Encode(keyOut, pemBlockForKey(priv))
188+
if err != nil {
189+
log.Fatalf("Failed to encode key: %v", err)
190+
}
191+
err = keyOut.Close()
192+
if err != nil {
193+
log.Fatalf("Failed to write key: %v", err)
194+
}
183195
log.Println("Written key.pem")
184-
185196
return nil
186197
}

cmd/convert.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2019 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package cmd
6+
7+
import (
8+
"fmt"
9+
10+
"code.gitea.io/gitea/models"
11+
"code.gitea.io/gitea/modules/log"
12+
"code.gitea.io/gitea/modules/setting"
13+
14+
"github.com/urfave/cli"
15+
)
16+
17+
// CmdConvert represents the available convert sub-command.
18+
var CmdConvert = cli.Command{
19+
Name: "convert",
20+
Usage: "Convert the database",
21+
Description: "A command to convert an existing MySQL database from utf8 to utf8mb4",
22+
Action: runConvert,
23+
}
24+
25+
func runConvert(ctx *cli.Context) error {
26+
if err := initDB(); err != nil {
27+
return err
28+
}
29+
30+
log.Trace("AppPath: %s", setting.AppPath)
31+
log.Trace("AppWorkPath: %s", setting.AppWorkPath)
32+
log.Trace("Custom path: %s", setting.CustomPath)
33+
log.Trace("Log path: %s", setting.LogRootPath)
34+
models.LoadConfigs()
35+
36+
if models.DbCfg.Type != "mysql" {
37+
fmt.Println("This command can only be used with a MySQL database")
38+
return nil
39+
}
40+
41+
if err := models.ConvertUtf8ToUtf8mb4(); err != nil {
42+
log.Fatal("Failed to convert database from utf8 to utf8mb4: %v", err)
43+
return err
44+
}
45+
46+
fmt.Println("Converted successfully, please confirm your database's character set is now utf8mb4")
47+
48+
return nil
49+
}

cmd/serv.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
)
3131

3232
const (
33-
accessDenied = "Repository does not exist or you do not have access"
3433
lfsAuthenticateVerb = "git-lfs-authenticate"
3534
)
3635

@@ -67,7 +66,7 @@ func checkLFSVersion() {
6766
}
6867

6968
func setup(logPath string) {
70-
log.DelLogger("console")
69+
_ = log.DelLogger("console")
7170
setting.NewContext()
7271
checkLFSVersion()
7372
}
@@ -112,7 +111,9 @@ func runServ(c *cli.Context) error {
112111
}
113112

114113
if len(c.Args()) < 1 {
115-
cli.ShowSubcommandHelp(c)
114+
if err := cli.ShowSubcommandHelp(c); err != nil {
115+
fmt.Printf("error showing subcommand help: %v\n", err)
116+
}
116117
return nil
117118
}
118119

@@ -209,7 +210,7 @@ func runServ(c *cli.Context) error {
209210
os.Setenv(models.EnvRepoIsWiki, strconv.FormatBool(results.IsWiki))
210211
os.Setenv(models.EnvRepoName, results.RepoName)
211212
os.Setenv(models.EnvRepoUsername, results.OwnerName)
212-
os.Setenv(models.EnvPusherName, username)
213+
os.Setenv(models.EnvPusherName, results.UserName)
213214
os.Setenv(models.EnvPusherID, strconv.FormatInt(results.UserID, 10))
214215
os.Setenv(models.ProtectedBranchRepoID, strconv.FormatInt(results.RepoID, 10))
215216
os.Setenv(models.ProtectedBranchPRID, fmt.Sprintf("%d", 0))

cmd/web.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,16 @@ func runWeb(ctx *cli.Context) error {
178178
}
179179
err = runHTTPS(listenAddr, setting.CertFile, setting.KeyFile, context2.ClearHandler(m))
180180
case setting.FCGI:
181-
listener, err := net.Listen("tcp", listenAddr)
181+
var listener net.Listener
182+
listener, err = net.Listen("tcp", listenAddr)
182183
if err != nil {
183184
log.Fatal("Failed to bind %s: %v", listenAddr, err)
184185
}
185-
defer listener.Close()
186+
defer func() {
187+
if err := listener.Close(); err != nil {
188+
log.Fatal("Failed to stop server: %v", err)
189+
}
190+
}()
186191
err = fcgi.Serve(listener, context2.ClearHandler(m))
187192
case setting.UnixSocket:
188193
if err := os.Remove(listenAddr); err != nil && !os.IsNotExist(err) {

contrib/pr/checkout.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ func runPR() {
9191
routers.NewServices()
9292
//x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
9393

94-
var helper testfixtures.Helper
95-
helper = &testfixtures.SQLite{}
94+
var helper testfixtures.Helper = &testfixtures.SQLite{}
9695
models.NewEngine(func(_ *xorm.Engine) error {
9796
return nil
9897
})

docs/content/doc/usage/command-line.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Admin operations:
6262
- `--password value`: Password. Required.
6363
- `--email value`: Email. Required.
6464
- `--admin`: If provided, this makes the user an admin. Optional.
65+
- `--access-token`: If provided, an access token will be created for the user. Optional. (default: false).
6566
- `--must-change-password`: If provided, the created user will be required to choose a newer password after
6667
the initial login. Optional. (default: true).
6768
- ``--random-password``: If provided, a randomly generated password will be used as the password of

integrations/api_repo_file_content_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"testing"
1212

1313
"code.gitea.io/gitea/models"
14-
"code.gitea.io/gitea/modules/base"
1514
"code.gitea.io/gitea/modules/context"
1615
"code.gitea.io/gitea/modules/setting"
1716
api "code.gitea.io/gitea/modules/structs"
@@ -98,7 +97,7 @@ func testAPIGetFileContents(t *testing.T, u *url.URL) {
9897
resp = session.MakeRequest(t, req, http.StatusInternalServerError)
9998
expectedAPIError := context.APIError{
10099
Message: "object does not exist [id: " + branch + ", rel_path: ]",
101-
URL: base.DocURL,
100+
URL: setting.API.SwaggerURL,
102101
}
103102
var apiError context.APIError
104103
DecodeJSON(t, resp, &apiError)

integrations/api_repo_file_create_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"testing"
1414

1515
"code.gitea.io/gitea/models"
16-
"code.gitea.io/gitea/modules/base"
1716
"code.gitea.io/gitea/modules/context"
1817
"code.gitea.io/gitea/modules/git"
1918
"code.gitea.io/gitea/modules/setting"
@@ -146,8 +145,8 @@ func TestAPICreateFile(t *testing.T) {
146145
var fileResponse api.FileResponse
147146
DecodeJSON(t, resp, &fileResponse)
148147
expectedSHA := "a635aa942442ddfdba07468cf9661c08fbdf0ebf"
149-
expectedHTMLURL := fmt.Sprintf("http://localhost:"+setting.HTTPPort+"/user2/repo1/blob/new_branch/new/file%d.txt", fileID)
150-
expectedDownloadURL := fmt.Sprintf("http://localhost:"+setting.HTTPPort+"/user2/repo1/raw/branch/new_branch/new/file%d.txt", fileID)
148+
expectedHTMLURL := fmt.Sprintf(setting.AppURL+"user2/repo1/blob/new_branch/new/file%d.txt", fileID)
149+
expectedDownloadURL := fmt.Sprintf(setting.AppURL+"user2/repo1/raw/branch/new_branch/new/file%d.txt", fileID)
151150
assert.EqualValues(t, expectedSHA, fileResponse.Content.SHA)
152151
assert.EqualValues(t, expectedHTMLURL, fileResponse.Content.HTMLURL)
153152
assert.EqualValues(t, expectedDownloadURL, fileResponse.Content.DownloadURL)
@@ -160,7 +159,7 @@ func TestAPICreateFile(t *testing.T) {
160159
resp = session.MakeRequest(t, req, http.StatusInternalServerError)
161160
expectedAPIError := context.APIError{
162161
Message: "repository file already exists [path: " + treePath + "]",
163-
URL: base.DocURL,
162+
URL: setting.API.SwaggerURL,
164163
}
165164
var apiError context.APIError
166165
DecodeJSON(t, resp, &apiError)

integrations/api_repo_file_delete_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"testing"
1212

1313
"code.gitea.io/gitea/models"
14-
"code.gitea.io/gitea/modules/base"
1514
"code.gitea.io/gitea/modules/context"
15+
"code.gitea.io/gitea/modules/setting"
1616
api "code.gitea.io/gitea/modules/structs"
1717

1818
"github.com/stretchr/testify/assert"
@@ -102,7 +102,7 @@ func TestAPIDeleteFile(t *testing.T) {
102102
resp = session.MakeRequest(t, req, http.StatusInternalServerError)
103103
expectedAPIError := context.APIError{
104104
Message: "sha does not match [given: " + deleteFileOptions.SHA + ", expected: " + correctSHA + "]",
105-
URL: base.DocURL,
105+
URL: setting.API.SwaggerURL,
106106
}
107107
var apiError context.APIError
108108
DecodeJSON(t, resp, &apiError)

0 commit comments

Comments
 (0)