Skip to content

Commit 45a0b14

Browse files
committed
Merge master into master-IB#1105071
2 parents ad47535 + 25f7e1c commit 45a0b14

File tree

390 files changed

+18877
-5268
lines changed

Some content is hidden

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

390 files changed

+18877
-5268
lines changed

.changelog.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ groups:
2222
name: SECURITY
2323
labels:
2424
- kind/security
25+
-
26+
name: API
27+
labels:
28+
- kind/api
2529
-
2630
name: BUGFIXES
2731
labels:

.drone.yml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,6 @@ services:
113113
environment:
114114
MYSQL_ALLOW_EMPTY_PASSWORD: yes
115115
MYSQL_DATABASE: test
116-
GOPROXY: off
117-
TAGS: bindata sqlite sqlite_unlock_notify
118-
GITLAB_READ_TOKEN:
119-
from_secret: gitlab_read_token
120-
depends_on:
121-
- build
122-
when:
123-
branch:
124-
- master
125-
event:
126-
- push
127-
- pull_request
128116

129117
- name: mysql8
130118
pull: default
@@ -152,7 +140,7 @@ services:
152140
image: elasticsearch:7.5.0
153141

154142
- name: minio
155-
image: minio/minio:RELEASE.2020-05-16T01-33-21Z
143+
image: minio/minio:RELEASE.2020-10-09T22-55-05Z
156144
commands:
157145
- minio server /data
158146
environment:

.golangci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,12 @@ issues:
9898
- path: models/update.go
9999
linters:
100100
- unused
101+
- path: cmd/dump.go
102+
linters:
103+
- dupl
104+
- text: "commentFormatting: put a space between `//` and comment text"
105+
linters:
106+
- gocritic
107+
- text: "exitAfterDefer:"
108+
linters:
109+
- gocritic

CHANGELOG.md

Lines changed: 317 additions & 0 deletions
Large diffs are not rendered by default.

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ENV GOPROXY ${GOPROXY:-direct}
88

99
ARG GITEA_VERSION
1010
ARG TAGS="sqlite sqlite_unlock_notify"
11-
ENV TAGS "bindata $TAGS"
11+
ENV TAGS "bindata timetzdata $TAGS"
1212
ARG CGO_EXTRA_CFLAGS
1313

1414
#Build deps
@@ -38,7 +38,6 @@ RUN apk --no-cache add \
3838
s6 \
3939
sqlite \
4040
su-exec \
41-
tzdata \
4241
gnupg
4342

4443
RUN addgroup \

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,12 @@ endif
120120

121121
GO_SOURCES_OWN := $(filter-out vendor/% %/bindata.go, $(GO_SOURCES))
122122

123-
#To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger@v0.20.1
123+
#To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger
124124
SWAGGER := $(GO) run -mod=vendor github.com/go-swagger/go-swagger/cmd/swagger
125125
SWAGGER_SPEC := templates/swagger/v1_json.tmpl
126126
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl}}/api/v1"|g
127127
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl}}/api/v1"|"basePath": "/api/v1"|g
128+
SWAGGER_EXCLUDE := code.gitea.io/sdk
128129
SWAGGER_NEWLINE_COMMAND := -e '$$a\'
129130

130131
TEST_MYSQL_HOST ?= mysql:3306
@@ -185,7 +186,7 @@ help:
185186

186187
.PHONY: go-check
187188
go-check:
188-
$(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell go version | grep -Eo '[0-9]+\.[0-9.]+' | tr '.' ' ');))
189+
$(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell $(GO) version | grep -Eo '[0-9]+\.[0-9.]+' | tr '.' ' ');))
189190
@if [ "$(GO_VERSION)" -lt "$(MIN_GO_VERSION)" ]; then \
190191
echo "Gitea requires Go 1.13 or greater to build. You can get it at https://golang.org/dl/"; \
191192
exit 1; \
@@ -243,7 +244,7 @@ endif
243244

244245
.PHONY: generate-swagger
245246
generate-swagger:
246-
$(SWAGGER) generate spec -o './$(SWAGGER_SPEC)'
247+
$(SWAGGER) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)'
247248
$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
248249
$(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
249250

@@ -697,7 +698,7 @@ pr\#%: clean-all
697698
golangci-lint:
698699
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
699700
export BINARY="golangci-lint"; \
700-
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.30.0; \
701+
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.31.0; \
701702
fi
702703
golangci-lint run --timeout 5m
703704

cmd/dump.go

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"code.gitea.io/gitea/models"
1919
"code.gitea.io/gitea/modules/log"
2020
"code.gitea.io/gitea/modules/setting"
21+
"code.gitea.io/gitea/modules/storage"
2122
"code.gitea.io/gitea/modules/util"
2223

2324
"gitea.com/macaron/session"
@@ -57,6 +58,8 @@ func addRecursive(w archiver.Writer, dirPath string, absPath string, verbose boo
5758
if err != nil {
5859
return fmt.Errorf("Could not open directory %s: %s", absPath, err)
5960
}
61+
defer dir.Close()
62+
6063
files, err := dir.Readdir(0)
6164
if err != nil {
6265
return fmt.Errorf("Unable to list files in %s: %s", absPath, err)
@@ -197,6 +200,10 @@ func runDump(ctx *cli.Context) error {
197200
return err
198201
}
199202

203+
if err := storage.Init(); err != nil {
204+
return err
205+
}
206+
200207
if file == nil {
201208
file, err = os.Create(fileName)
202209
if err != nil {
@@ -231,11 +238,21 @@ func runDump(ctx *cli.Context) error {
231238
fatal("Failed to include repositories: %v", err)
232239
}
233240

234-
if _, err := os.Stat(setting.LFS.ContentPath); !os.IsNotExist(err) {
235-
log.Info("Dumping lfs... %s", setting.LFS.ContentPath)
236-
if err := addRecursive(w, "lfs", setting.LFS.ContentPath, verbose); err != nil {
237-
fatal("Failed to include lfs: %v", err)
241+
if err := storage.LFS.IterateObjects(func(objPath string, object storage.Object) error {
242+
info, err := object.Stat()
243+
if err != nil {
244+
return err
238245
}
246+
247+
return w.Write(archiver.File{
248+
FileInfo: archiver.FileInfo{
249+
FileInfo: info,
250+
CustomName: path.Join("data", "lfs", objPath),
251+
},
252+
ReadCloser: object,
253+
})
254+
}); err != nil {
255+
fatal("Failed to dump LFS objects: %v", err)
239256
}
240257
}
241258

@@ -302,13 +319,31 @@ func runDump(ctx *cli.Context) error {
302319
}
303320

304321
excludes = append(excludes, setting.RepoRootPath)
305-
excludes = append(excludes, setting.LFS.ContentPath)
322+
excludes = append(excludes, setting.LFS.Path)
323+
excludes = append(excludes, setting.Attachment.Path)
306324
excludes = append(excludes, setting.LogRootPath)
307325
if err := addRecursiveExclude(w, "data", setting.AppDataPath, excludes, verbose); err != nil {
308326
fatal("Failed to include data directory: %v", err)
309327
}
310328
}
311329

330+
if err := storage.Attachments.IterateObjects(func(objPath string, object storage.Object) error {
331+
info, err := object.Stat()
332+
if err != nil {
333+
return err
334+
}
335+
336+
return w.Write(archiver.File{
337+
FileInfo: archiver.FileInfo{
338+
FileInfo: info,
339+
CustomName: path.Join("data", "attachments", objPath),
340+
},
341+
ReadCloser: object,
342+
})
343+
}); err != nil {
344+
fatal("Failed to dump attachments: %v", err)
345+
}
346+
312347
// Doesn't check if LogRootPath exists before processing --skip-log intentionally,
313348
// ensuring that it's clear the dump is skipped whether the directory's initialized
314349
// yet or not.

cmd/hook.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ func runHookUpdate(c *cli.Context) error {
285285
}
286286

287287
func runHookPostReceive(c *cli.Context) error {
288+
// First of all run update-server-info no matter what
289+
if _, err := git.NewCommand("update-server-info").Run(); err != nil {
290+
return fmt.Errorf("Failed to call 'git update-server-info': %v", err)
291+
}
292+
293+
// Now if we're an internal don't do anything else
288294
if os.Getenv(models.EnvIsInternal) == "true" {
289295
return nil
290296
}

cmd/migrate_storage.go

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package cmd
77
import (
88
"context"
99
"fmt"
10+
"strings"
1011

1112
"code.gitea.io/gitea/models"
1213
"code.gitea.io/gitea/models/migrations"
@@ -30,9 +31,9 @@ var CmdMigrateStorage = cli.Command{
3031
Usage: "Kinds of files to migrate, currently only 'attachments' is supported",
3132
},
3233
cli.StringFlag{
33-
Name: "store, s",
34-
Value: "local",
35-
Usage: "New storage type, local or minio",
34+
Name: "storage, s",
35+
Value: "",
36+
Usage: "New storage type: local (default) or minio",
3637
},
3738
cli.StringFlag{
3839
Name: "path, p",
@@ -90,6 +91,20 @@ func migrateLFS(dstStorage storage.ObjectStorage) error {
9091
})
9192
}
9293

94+
func migrateAvatars(dstStorage storage.ObjectStorage) error {
95+
return models.IterateUser(func(user *models.User) error {
96+
_, err := storage.Copy(dstStorage, user.CustomAvatarRelativePath(), storage.Avatars, user.CustomAvatarRelativePath())
97+
return err
98+
})
99+
}
100+
101+
func migrateRepoAvatars(dstStorage storage.ObjectStorage) error {
102+
return models.IterateRepository(func(repo *models.Repository) error {
103+
_, err := storage.Copy(dstStorage, repo.CustomAvatarRelativePath(), storage.RepoAvatars, repo.CustomAvatarRelativePath())
104+
return err
105+
})
106+
}
107+
93108
func runMigrateStorage(ctx *cli.Context) error {
94109
if err := initDB(); err != nil {
95110
return err
@@ -106,40 +121,48 @@ func runMigrateStorage(ctx *cli.Context) error {
106121
return err
107122
}
108123

124+
goCtx := context.Background()
125+
109126
if err := storage.Init(); err != nil {
110127
return err
111128
}
112129

113130
var dstStorage storage.ObjectStorage
114131
var err error
115-
switch ctx.String("store") {
116-
case "local":
132+
switch strings.ToLower(ctx.String("storage")) {
133+
case "":
134+
fallthrough
135+
case string(storage.LocalStorageType):
117136
p := ctx.String("path")
118137
if p == "" {
119-
log.Fatal("Path must be given when store is loal")
138+
log.Fatal("Path must be given when storage is loal")
120139
return nil
121140
}
122-
dstStorage, err = storage.NewLocalStorage(p)
123-
case "minio":
141+
dstStorage, err = storage.NewLocalStorage(
142+
goCtx,
143+
storage.LocalStorageConfig{
144+
Path: p,
145+
})
146+
case string(storage.MinioStorageType):
124147
dstStorage, err = storage.NewMinioStorage(
125-
context.Background(),
126-
ctx.String("minio-endpoint"),
127-
ctx.String("minio-access-key-id"),
128-
ctx.String("minio-secret-access-key"),
129-
ctx.String("minio-bucket"),
130-
ctx.String("minio-location"),
131-
ctx.String("minio-base-path"),
132-
ctx.Bool("minio-use-ssl"),
133-
)
148+
goCtx,
149+
storage.MinioStorageConfig{
150+
Endpoint: ctx.String("minio-endpoint"),
151+
AccessKeyID: ctx.String("minio-access-key-id"),
152+
SecretAccessKey: ctx.String("minio-secret-access-key"),
153+
Bucket: ctx.String("minio-bucket"),
154+
Location: ctx.String("minio-location"),
155+
BasePath: ctx.String("minio-base-path"),
156+
UseSSL: ctx.Bool("minio-use-ssl"),
157+
})
134158
default:
135-
return fmt.Errorf("Unsupported attachments store type: %s", ctx.String("store"))
159+
return fmt.Errorf("Unsupported storage type: %s", ctx.String("storage"))
136160
}
137-
138161
if err != nil {
139162
return err
140163
}
141164

142-
tp := ctx.String("type")
165+
tp := strings.ToLower(ctx.String("type"))
143166
switch tp {
144167
case "attachments":
145168
if err := migrateAttachments(dstStorage); err != nil {
@@ -149,6 +172,14 @@ func runMigrateStorage(ctx *cli.Context) error {
149172
if err := migrateLFS(dstStorage); err != nil {
150173
return err
151174
}
175+
case "avatars":
176+
if err := migrateAvatars(dstStorage); err != nil {
177+
return err
178+
}
179+
case "repo-avatars":
180+
if err := migrateRepoAvatars(dstStorage); err != nil {
181+
return err
182+
}
152183
default:
153184
return fmt.Errorf("Unsupported storage: %s", ctx.String("type"))
154185
}

cmd/serv.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func setup(logPath string, debug bool) {
5454
_ = log.DelLogger("console")
5555
if debug {
5656
_ = log.NewLogger(1000, "console", "console", `{"level":"trace","stacktracelevel":"NONE","stderr":true}`)
57+
} else {
58+
_ = log.NewLogger(1000, "console", "console", `{"level":"fatal","stacktracelevel":"NONE","stderr":true}`)
5759
}
5860
setting.NewContext()
5961
if debug {
@@ -111,9 +113,12 @@ func runServ(c *cli.Context) error {
111113
if err != nil {
112114
fail("Internal error", "Failed to check provided key: %v", err)
113115
}
114-
if key.Type == models.KeyTypeDeploy {
116+
switch key.Type {
117+
case models.KeyTypeDeploy:
115118
println("Hi there! You've successfully authenticated with the deploy key named " + key.Name + ", but Gitea does not provide shell access.")
116-
} else {
119+
case models.KeyTypePrincipal:
120+
println("Hi there! You've successfully authenticated with the principal " + key.Content + ", but Gitea does not provide shell access.")
121+
default:
117122
println("Hi there, " + user.Name + "! You've successfully authenticated with the key named " + key.Name + ", but Gitea does not provide shell access.")
118123
}
119124
println("If this is unexpected, please log in with password and setup Gitea under another user.")

cmd/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func runLetsEncryptFallbackHandler(w http.ResponseWriter, r *http.Request) {
9393
// Remove the trailing slash at the end of setting.AppURL, the request
9494
// URI always contains a leading slash, which would result in a double
9595
// slash
96-
target := strings.TrimRight(setting.AppURL, "/") + r.URL.RequestURI()
96+
target := strings.TrimSuffix(setting.AppURL, "/") + r.URL.RequestURI()
9797
http.Redirect(w, r, target, http.StatusFound)
9898
}
9999

0 commit comments

Comments
 (0)