Skip to content

Commit 3cc7b7e

Browse files
committed
Merge branch 'master' into route-lfs-internally-fix-go-gitea#732
2 parents f89cabe + 2f39fc7 commit 3cc7b7e

File tree

241 files changed

+4068
-2263
lines changed

Some content is hidden

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

241 files changed

+4068
-2263
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: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ vet:
9797

9898
.PHONY: generate
9999
generate:
100-
@hash go-bindata > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
101-
$(GO) get -u github.com/jteeuwen/go-bindata/go-bindata; \
102-
fi
103-
$(GO) generate $(PACKAGES)
100+
GO111MODULE=on $(GO) generate $(PACKAGES)
104101

105102
.PHONY: generate-swagger
106103
generate-swagger:
@@ -138,6 +135,10 @@ errcheck:
138135

139136
.PHONY: lint
140137
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:
141142
@hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
142143
$(GO) get -u github.com/mgechev/revive; \
143144
fi
@@ -464,3 +465,11 @@ generate-images:
464465
.PHONY: pr
465466
pr:
466467
$(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: 9 additions & 8 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

@@ -53,7 +52,7 @@ func checkLFSVersion() {
5352
//Needs at least git v2.1.2
5453
binVersion, err := git.BinVersion()
5554
if err != nil {
56-
fail(fmt.Sprintf("Error retrieving git version: %v", err), fmt.Sprintf("Error retrieving git version: %v", err))
55+
fail("LFS server error", "Error retrieving git version: %v", err)
5756
}
5857

5958
if !version.Compare(binVersion, "2.1.2", ">=") {
@@ -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

@@ -199,17 +200,17 @@ func runServ(c *cli.Context) error {
199200
if private.IsErrServCommand(err) {
200201
errServCommand := err.(private.ErrServCommand)
201202
if errServCommand.StatusCode != http.StatusInternalServerError {
202-
fail("Unauthorized", errServCommand.Error())
203+
fail("Unauthorized", "%s", errServCommand.Error())
203204
} else {
204-
fail("Internal Server Error", errServCommand.Error())
205+
fail("Internal Server Error", "%s", errServCommand.Error())
205206
}
206207
}
207-
fail("Internal Server Error", err.Error())
208+
fail("Internal Server Error", "%s", err.Error())
208209
}
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

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

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ require (
3030
github.com/denisenkom/go-mssqldb v0.0.0-20181014144952-4e0d7dc8888f
3131
github.com/dgrijalva/jwt-go v0.0.0-20161101193935-9ed569b5d1ac
3232
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712 // indirect
33-
github.com/elazarl/go-bindata-assetfs v0.0.0-20151224045452-57eb5e1fc594 // indirect
3433
github.com/emirpasic/gods v1.12.0
3534
github.com/etcd-io/bbolt v1.3.2 // indirect
3635
github.com/ethantkoenig/rupture v0.0.0-20180203182544-0a76f03a811a
@@ -44,7 +43,6 @@ require (
4443
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 // indirect
4544
github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd // indirect
4645
github.com/glycerine/goconvey v0.0.0-20190315024820-982ee783a72e // indirect
47-
github.com/go-macaron/bindata v0.0.0-20161222093048-85786f57eee3
4846
github.com/go-macaron/binding v0.0.0-20160711225916-9440f336b443
4947
github.com/go-macaron/cache v0.0.0-20151013081102-561735312776
5048
github.com/go-macaron/captcha v0.0.0-20151123225153-8aa5919789ab
@@ -103,7 +101,9 @@ require (
103101
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
104102
github.com/satori/go.uuid v1.2.0
105103
github.com/sergi/go-diff v1.0.0
104+
github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b // indirect
106105
github.com/shurcooL/sanitized_anchor_name v0.0.0-20160918041101-1dba4b3954bc // indirect
106+
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
107107
github.com/siddontang/go-snappy v0.0.0-20140704025258-d8f7bb82a96d // indirect
108108
github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff // indirect
109109
github.com/steveyen/gtreap v0.0.0-20150807155958-0abe01ef9be2 // indirect

0 commit comments

Comments
 (0)