Skip to content

Commit 2691234

Browse files
committed
Merge branch 'main-IB#1105051' of github.com:ibpl/gitea into main-IB#1105051
2 parents 5c8f905 + 2b6990c commit 2691234

File tree

609 files changed

+7025
-5361
lines changed

Some content is hidden

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

609 files changed

+7025
-5361
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
* text=auto eol=lf
22
/vendor/** -text -eol linguist-vendored
33
/public/vendor/** -text -eol linguist-vendored
4+
/web_src/js/vendor/** -text -eol linguist-vendored
45
/templates/**/*.tmpl linguist-language=Handlebars
56
/.eslintrc linguist-language=YAML
67
/.stylelintrc linguist-language=YAML

.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ linters:
1717
- bidichk
1818
- ineffassign
1919
- revive
20+
- gofumpt
2021
enable-all: false
2122
disable-all: true
2223
fast: false
@@ -57,6 +58,9 @@ linters-settings:
5758
- name: errorf
5859
- name: duplicated-imports
5960
- name: modifies-value-receiver
61+
gofumpt:
62+
extra-rules: true
63+
lang-version: 1.16
6064

6165
issues:
6266
exclude-rules:

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ For imports you should use the following format (_without_ the comments)
141141
```go
142142
import (
143143
// stdlib
144-
"encoding/json"
145144
"fmt"
145+
"math"
146146

147147
// local packages
148148
"code.gitea.io/gitea/models"

Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
2-
###################################
3-
#Build stage - temporarily using techknowlogick image until we upgrade to latest official alpine/go image
4-
FROM techknowlogick/go:1.17-alpine3.13 AS build-env
1+
#Build stage
2+
FROM golang:1.17-alpine3.15 AS build-env
53

64
ARG GOPROXY
75
ENV GOPROXY ${GOPROXY:-direct}
@@ -25,7 +23,7 @@ RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
2523
# Begin env-to-ini build
2624
RUN go build contrib/environment-to-ini/environment-to-ini.go
2725

28-
FROM alpine:3.13
26+
FROM alpine:3.15
2927
LABEL maintainer="[email protected]"
3028

3129
EXPOSE 22 3000

Dockerfile.rootless

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
2-
###################################
3-
#Build stage - temporarily using techknowlogick image until we upgrade to latest official alpine/go image
4-
FROM techknowlogick/go:1.17-alpine3.13 AS build-env
1+
#Build stage
2+
FROM golang:1.17-alpine3.15 AS build-env
53

64
ARG GOPROXY
75
ENV GOPROXY ${GOPROXY:-direct}
@@ -25,7 +23,7 @@ RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
2523
# Begin env-to-ini build
2624
RUN go build contrib/environment-to-ini/environment-to-ini.go
2725

28-
FROM alpine:3.13
26+
FROM alpine:3.15
2927
LABEL maintainer="[email protected]"
3028

3129
EXPOSE 2222 3000

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,10 @@ clean:
231231

232232
.PHONY: fmt
233233
fmt:
234-
@echo "Running gitea-fmt(with gofmt)..."
235-
@$(GO) run build/code-batch-process.go gitea-fmt -s -w '{file-list}'
234+
@hash xgogofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
235+
$(GO) install mvdan.cc/gofumpt@latest; \
236+
fi
237+
gofumpt -w -l -extra -lang 1.16 .
236238

237239
.PHONY: vet
238240
vet:

build/code-batch-process.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (fc *fileCollector) collectFiles() (res [][]string, err error) {
136136
}
137137

138138
// substArgFiles expands the {file-list} to a real file list for commands
139-
func substArgFiles(args []string, files []string) []string {
139+
func substArgFiles(args, files []string) []string {
140140
for i, s := range args {
141141
if s == "{file-list}" {
142142
newArgs := append(args[:i], files...)

build/codeformat/formatimports.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ var importPackageGroupOrders = map[string]int{
2020

2121
var errInvalidCommentBetweenImports = errors.New("comments between imported packages are invalid, please move comments to the end of the package line")
2222

23-
var importBlockBegin = []byte("\nimport (\n")
24-
var importBlockEnd = []byte("\n)")
23+
var (
24+
importBlockBegin = []byte("\nimport (\n")
25+
importBlockEnd = []byte("\n)")
26+
)
2527

2628
type importLineParsed struct {
2729
group string
@@ -59,8 +61,10 @@ func parseImportLine(line string) (*importLineParsed, error) {
5961
return il, nil
6062
}
6163

62-
type importLineGroup []*importLineParsed
63-
type importLineGroupMap map[string]importLineGroup
64+
type (
65+
importLineGroup []*importLineParsed
66+
importLineGroupMap map[string]importLineGroup
67+
)
6468

6569
func formatGoImports(contentBytes []byte) ([]byte, error) {
6670
p1 := bytes.Index(contentBytes, importBlockBegin)
@@ -153,7 +157,7 @@ func formatGoImports(contentBytes []byte) ([]byte, error) {
153157
return formattedBytes, nil
154158
}
155159

156-
//FormatGoImports format the imports by our rules (see unit tests)
160+
// FormatGoImports format the imports by our rules (see unit tests)
157161
func FormatGoImports(file string) error {
158162
f, err := os.Open(file)
159163
if err != nil {
@@ -177,7 +181,7 @@ func FormatGoImports(file string) error {
177181
if bytes.Equal(contentBytes, formattedBytes) {
178182
return nil
179183
}
180-
f, err = os.OpenFile(file, os.O_TRUNC|os.O_WRONLY, 0644)
184+
f, err = os.OpenFile(file, os.O_TRUNC|os.O_WRONLY, 0o644)
181185
if err != nil {
182186
return err
183187
}

build/generate-bindata.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/shurcooL/vfsgen"
2121
)
2222

23-
func needsUpdate(dir string, filename string) (bool, []byte) {
23+
func needsUpdate(dir, filename string) (bool, []byte) {
2424
needRegen := false
2525
_, err := os.Stat(filename)
2626
if err != nil {
@@ -50,7 +50,6 @@ func needsUpdate(dir string, filename string) (bool, []byte) {
5050
newHash := hasher.Sum([]byte{})
5151

5252
if bytes.Compare(oldHash, newHash) != 0 {
53-
5453
return true, newHash
5554
}
5655

@@ -87,5 +86,5 @@ func main() {
8786
if err != nil {
8887
log.Fatalf("%v\n", err)
8988
}
90-
_ = os.WriteFile(filename+".hash", newHash, 0666)
89+
_ = os.WriteFile(filename+".hash", newHash, 0o666)
9190
}

build/generate-emoji.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ const (
3030
maxUnicodeVersion = 12
3131
)
3232

33-
var (
34-
flagOut = flag.String("o", "modules/emoji/emoji_data.go", "out")
35-
)
33+
var flagOut = flag.String("o", "modules/emoji/emoji_data.go", "out")
3634

3735
// Gemoji is a set of emoji data.
3836
type Gemoji []Emoji
@@ -68,7 +66,7 @@ func main() {
6866
}
6967

7068
// write
71-
err = os.WriteFile(*flagOut, buf, 0644)
69+
err = os.WriteFile(*flagOut, buf, 0o644)
7270
if err != nil {
7371
log.Fatal(err)
7472
}
@@ -109,7 +107,7 @@ func generate() ([]byte, error) {
109107
return nil, err
110108
}
111109

112-
var skinTones = make(map[string]string)
110+
skinTones := make(map[string]string)
113111

114112
skinTones["\U0001f3fb"] = "Light Skin Tone"
115113
skinTones["\U0001f3fc"] = "Medium-Light Skin Tone"
@@ -119,7 +117,7 @@ func generate() ([]byte, error) {
119117

120118
var tmp Gemoji
121119

122-
//filter out emoji that require greater than max unicode version
120+
// filter out emoji that require greater than max unicode version
123121
for i := range data {
124122
val, _ := strconv.ParseFloat(data[i].UnicodeVersion, 64)
125123
if int(val) <= maxUnicodeVersion {
@@ -158,7 +156,7 @@ func generate() ([]byte, error) {
158156

159157
// write a JSON file to use with tribute (write before adding skin tones since we can't support them there yet)
160158
file, _ := json.Marshal(data)
161-
_ = os.WriteFile("assets/emoji.json", file, 0644)
159+
_ = os.WriteFile("assets/emoji.json", file, 0o644)
162160

163161
// Add skin tones to emoji that support it
164162
var (

build/generate-gitignores.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ func main() {
3434
flag.Parse()
3535

3636
file, err := os.CreateTemp(os.TempDir(), prefix)
37-
3837
if err != nil {
3938
log.Fatalf("Failed to create temp file. %s", err)
4039
}
@@ -65,7 +64,6 @@ func main() {
6564
}
6665

6766
gz, err := gzip.NewReader(file)
68-
6967
if err != nil {
7068
log.Fatalf("Failed to gunzip the archive. %s", err)
7169
}
@@ -96,7 +94,6 @@ func main() {
9694
}
9795

9896
out, err := os.Create(path.Join(destination, strings.TrimSuffix(filepath.Base(hdr.Name), ".gitignore")))
99-
10097
if err != nil {
10198
log.Fatalf("Failed to create new file. %s", err)
10299
}
@@ -119,7 +116,7 @@ func main() {
119116
}
120117
// Write data to dst
121118
dst = path.Join(destination, dst)
122-
err = os.WriteFile(dst, data, 0644)
119+
err = os.WriteFile(dst, data, 0o644)
123120
if err != nil {
124121
log.Fatalf("Failed to write new file. %s", err)
125122
}

build/generate-licenses.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ func main() {
3434
flag.Parse()
3535

3636
file, err := os.CreateTemp(os.TempDir(), prefix)
37-
3837
if err != nil {
3938
log.Fatalf("Failed to create temp file. %s", err)
4039
}
@@ -66,7 +65,6 @@ func main() {
6665
}
6766

6867
gz, err := gzip.NewReader(file)
69-
7068
if err != nil {
7169
log.Fatalf("Failed to gunzip the archive. %s", err)
7270
}
@@ -100,7 +98,6 @@ func main() {
10098
continue
10199
}
102100
out, err := os.Create(path.Join(destination, strings.TrimSuffix(filepath.Base(hdr.Name), ".txt")))
103-
104101
if err != nil {
105102
log.Fatalf("Failed to create new file. %s", err)
106103
}

build/gocovmerge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"golang.org/x/tools/cover"
2323
)
2424

25-
func mergeProfiles(p *cover.Profile, merge *cover.Profile) {
25+
func mergeProfiles(p, merge *cover.Profile) {
2626
if p.Mode != merge.Mode {
2727
log.Fatalf("cannot merge profiles with different modes")
2828
}

cmd/admin.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ func runCreateUser(c *cli.Context) error {
525525
}
526526

527527
// always default to true
528-
var changePassword = true
528+
changePassword := true
529529

530530
// If this is the first user being created.
531531
// Take it as the admin and don't force a password update.
@@ -577,7 +577,6 @@ func runListUsers(c *cli.Context) error {
577577
}
578578

579579
users, err := user_model.GetAllUsers()
580-
581580
if err != nil {
582581
return err
583582
}
@@ -601,7 +600,6 @@ func runListUsers(c *cli.Context) error {
601600

602601
w.Flush()
603602
return nil
604-
605603
}
606604

607605
func runDeleteUser(c *cli.Context) error {
@@ -669,7 +667,7 @@ func runRepoSyncReleases(_ *cli.Context) error {
669667
log.Trace("Processing next %d repos of %d", len(repos), count)
670668
for _, repo := range repos {
671669
log.Trace("Synchronizing repo %s with path %s", repo.FullName(), repo.RepoPath())
672-
gitRepo, err := git.OpenRepository(repo.RepoPath())
670+
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
673671
if err != nil {
674672
log.Warn("OpenRepository: %v", err)
675673
continue
@@ -826,7 +824,6 @@ func runUpdateOauth(c *cli.Context) error {
826824

827825
if c.IsSet("required-claim-name") {
828826
oAuth2Config.RequiredClaimName = c.String("required-claim-name")
829-
830827
}
831828
if c.IsSet("required-claim-value") {
832829
oAuth2Config.RequiredClaimValue = c.String("required-claim-value")
@@ -843,7 +840,7 @@ func runUpdateOauth(c *cli.Context) error {
843840
}
844841

845842
// update custom URL mapping
846-
var customURLMapping = &oauth2.CustomURLMapping{}
843+
customURLMapping := &oauth2.CustomURLMapping{}
847844

848845
if oAuth2Config.CustomURLMapping != nil {
849846
customURLMapping.TokenURL = oAuth2Config.CustomURLMapping.TokenURL
@@ -926,7 +923,7 @@ func runAddSMTP(c *cli.Context) error {
926923
if !c.IsSet("port") {
927924
return errors.New("port must be set")
928925
}
929-
var active = true
926+
active := true
930927
if c.IsSet("active") {
931928
active = c.BoolT("active")
932929
}
@@ -994,7 +991,6 @@ func runListAuth(c *cli.Context) error {
994991
}
995992

996993
authSources, err := auth.Sources()
997-
998994
if err != nil {
999995
return err
1000996
}

0 commit comments

Comments
 (0)