Skip to content

Commit b9455b3

Browse files
authored
Merge branch 'main' into refactor-git-cmd
2 parents eb12e65 + 3c5655c commit b9455b3

File tree

21 files changed

+301
-184
lines changed

21 files changed

+301
-184
lines changed

.drone.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ steps:
2525
- make deps-frontend
2626

2727
- name: deps-backend
28-
image: golang:1.19
28+
image: golang:1.20
2929
pull: always
3030
commands:
3131
- make deps-backend
@@ -88,7 +88,7 @@ steps:
8888
depends_on: [deps-frontend]
8989

9090
- name: checks-backend
91-
image: golang:1.19
91+
image: golang:1.20
9292
commands:
9393
- make --always-make checks-backend # ensure the 'go-licenses' make target runs
9494
depends_on: [deps-backend]
@@ -109,7 +109,7 @@ steps:
109109
depends_on: [deps-frontend]
110110

111111
- name: build-backend-no-gcc
112-
image: golang:1.18 # this step is kept as the lowest version of golang that we support
112+
image: golang:1.19 # this step is kept as the lowest version of golang that we support
113113
pull: always
114114
environment:
115115
GO111MODULE: on
@@ -122,7 +122,7 @@ steps:
122122
path: /go
123123

124124
- name: build-backend-arm64
125-
image: golang:1.19
125+
image: golang:1.20
126126
environment:
127127
GO111MODULE: on
128128
GOPROXY: https://goproxy.io
@@ -138,7 +138,7 @@ steps:
138138
path: /go
139139

140140
- name: build-backend-windows
141-
image: golang:1.19
141+
image: golang:1.20
142142
environment:
143143
GO111MODULE: on
144144
GOPROXY: https://goproxy.io
@@ -153,7 +153,7 @@ steps:
153153
path: /go
154154

155155
- name: build-backend-386
156-
image: golang:1.19
156+
image: golang:1.20
157157
environment:
158158
GO111MODULE: on
159159
GOPROXY: https://goproxy.io
@@ -247,7 +247,7 @@ steps:
247247
- pull_request
248248

249249
- name: deps-backend
250-
image: golang:1.19
250+
image: golang:1.20
251251
pull: always
252252
commands:
253253
- make deps-backend
@@ -364,7 +364,7 @@ steps:
364364
path: /go
365365

366366
- name: generate-coverage
367-
image: golang:1.19
367+
image: golang:1.20
368368
commands:
369369
- make coverage
370370
environment:
@@ -440,7 +440,7 @@ steps:
440440
- pull_request
441441

442442
- name: deps-backend
443-
image: golang:1.19
443+
image: golang:1.20
444444
pull: always
445445
commands:
446446
- make deps-backend
@@ -557,7 +557,7 @@ steps:
557557
- name: test-e2e
558558
image: mcr.microsoft.com/playwright:v1.29.2-focal
559559
commands:
560-
- curl -sLO https://go.dev/dl/go1.19.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.19.linux-amd64.tar.gz
560+
- curl -sLO https://go.dev/dl/go1.20.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.20.linux-amd64.tar.gz
561561
- groupadd --gid 1001 gitea && useradd -m --gid 1001 --uid 1001 gitea
562562
- apt-get -qq update && apt-get -qqy install build-essential
563563
- export TEST_PGSQL_SCHEMA=''
@@ -656,7 +656,7 @@ trigger:
656656

657657
steps:
658658
- name: download
659-
image: golang:1.19
659+
image: golang:1.20
660660
pull: always
661661
commands:
662662
- timeout -s ABRT 40m make generate-license generate-gitignore
@@ -720,7 +720,7 @@ steps:
720720
- make deps-frontend
721721

722722
- name: deps-backend
723-
image: golang:1.19
723+
image: golang:1.20
724724
pull: always
725725
commands:
726726
- make deps-backend
@@ -729,7 +729,7 @@ steps:
729729
path: /go
730730

731731
- name: static
732-
image: techknowlogick/xgo:go-1.19.x
732+
image: techknowlogick/xgo:go-1.20.x
733733
pull: always
734734
commands:
735735
# Upgrade to node 18 once https://github.com/techknowlogick/xgo/issues/163 is resolved
@@ -841,7 +841,7 @@ steps:
841841
- make deps-frontend
842842

843843
- name: deps-backend
844-
image: golang:1.19
844+
image: golang:1.20
845845
pull: always
846846
commands:
847847
- make deps-backend
@@ -850,7 +850,7 @@ steps:
850850
path: /go
851851

852852
- name: static
853-
image: techknowlogick/xgo:go-1.19.x
853+
image: techknowlogick/xgo:go-1.20.x
854854
pull: always
855855
commands:
856856
# Upgrade to node 18 once https://github.com/techknowlogick/xgo/issues/163 is resolved
@@ -932,7 +932,7 @@ trigger:
932932

933933
steps:
934934
- name: build-docs
935-
image: golang:1.19
935+
image: golang:1.20
936936
commands:
937937
- cd docs
938938
- make trans-copy clean build

.golangci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ linters:
2828
fast: false
2929

3030
run:
31-
go: 1.19
31+
go: 1.20
3232
timeout: 10m
3333
skip-dirs:
3434
- node_modules
@@ -74,7 +74,7 @@ linters-settings:
7474
- name: modifies-value-receiver
7575
gofumpt:
7676
extra-rules: true
77-
lang-version: "1.19"
77+
lang-version: "1.20"
7878
depguard:
7979
list-type: denylist
8080
# Check the list against standard lib.

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Build stage
2-
FROM golang:1.19-alpine3.17 AS build-env
2+
FROM golang:1.20-alpine3.17 AS build-env
33

44
ARG GOPROXY
55
ENV GOPROXY ${GOPROXY:-direct}

Dockerfile.rootless

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Build stage
2-
FROM golang:1.19-alpine3.17 AS build-env
2+
FROM golang:1.20-alpine3.17 AS build-env
33

44
ARG GOPROXY
55
ENV GOPROXY ${GOPROXY:-direct}

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ SHASUM ?= shasum -a 256
2323
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
2424
COMMA := ,
2525

26-
XGO_VERSION := go-1.19.x
26+
XGO_VERSION := go-1.20.x
2727

2828
AIR_PACKAGE ?= github.com/cosmtrek/[email protected]
2929
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/[email protected]
3030
ERRCHECK_PACKAGE ?= github.com/kisielk/[email protected]
3131
GOFUMPT_PACKAGE ?= mvdan.cc/[email protected]
32-
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1
32+
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.0
3333
GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/[email protected]
3434
MISSPELL_PACKAGE ?= github.com/client9/misspell/cmd/[email protected]
3535
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/[email protected]

docs/config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ params:
1919
author: The Gitea Authors
2020
website: https://docs.gitea.io
2121
version: 1.18.1
22-
minGoVersion: 1.18
23-
goVersion: 1.19
22+
minGoVersion: 1.19
23+
goVersion: 1.20
2424
minNodeVersion: 16
2525
search: nav
2626
repo: "https://github.com/go-gitea/gitea"

docs/content/doc/features/authentication.en-us.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,22 @@ Before activating SSPI single sign-on authentication (SSO) you have to prepare y
329329
- You have added the URL of the web app to the `Local intranet zone`
330330
- The clocks of the server and client should not differ with more than 5 minutes (depends on group policy)
331331
- `Integrated Windows Authentication` should be enabled in Internet Explorer (under `Advanced settings`)
332+
333+
## Reverse Proxy
334+
335+
Gitea supports Reverse Proxy Header authentication, it will read headers as a trusted login user name or user email address. This hasn't been enabled by default, you can enable it with
336+
337+
```ini
338+
[service]
339+
ENABLE_REVERSE_PROXY_AUTHENTICATION = true
340+
```
341+
342+
The default login user name is in the `X-WEBAUTH-USER` header, you can change it via changing `REVERSE_PROXY_AUTHENTICATION_USER` in app.ini. If the user doesn't exist, you can enable automatic registration with `ENABLE_REVERSE_PROXY_AUTO_REGISTRATION=true`.
343+
344+
The default login user email is `X-WEBAUTH-EMAIL`, you can change it via changing `REVERSE_PROXY_AUTHENTICATION_EMAIL` in app.ini, this could also be disabled with `ENABLE_REVERSE_PROXY_EMAIL`
345+
346+
If set `ENABLE_REVERSE_PROXY_FULL_NAME=true`, a user full name expected in `X-WEBAUTH-FULLNAME` will be assigned to the user when auto creating the user. You can also change the header name with `REVERSE_PROXY_AUTHENTICATION_FULL_NAME`.
347+
348+
You can also limit the reverse proxy's IP address range with `REVERSE_PROXY_TRUSTED_PROXIES` which default value is `127.0.0.0/8,::1/128`. By `REVERSE_PROXY_LIMIT`, you can limit trusted proxies level.
349+
350+
Notice: Reverse Proxy Auth doesn't support the API. You still need an access token or basic auth to make API requests.

docs/content/doc/features/authentication.zh-cn.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,21 @@ menu:
1515

1616
# 认证
1717

18-
## TBD
18+
## 反向代理认证
19+
20+
Gitea 支持通过读取反向代理传递的 HTTP 头中的登录名或者 email 地址来支持反向代理来认证。默认是不启用的,你可以用以下配置启用。
21+
22+
```ini
23+
[service]
24+
ENABLE_REVERSE_PROXY_AUTHENTICATION = true
25+
```
26+
27+
默认的登录用户名的 HTTP 头是 `X-WEBAUTH-USER`,你可以通过修改 `REVERSE_PROXY_AUTHENTICATION_USER` 来变更它。如果用户不存在,可以自动创建用户,当然你需要修改 `ENABLE_REVERSE_PROXY_AUTO_REGISTRATION=true` 来启用它。
28+
29+
默认的登录用户 Email 的 HTTP 头是 `X-WEBAUTH-EMAIL`,你可以通过修改 `REVERSE_PROXY_AUTHENTICATION_EMAIL` 来变更它。如果用户不存在,可以自动创建用户,当然你需要修改 `ENABLE_REVERSE_PROXY_AUTO_REGISTRATION=true` 来启用它。你也可以通过修改 `ENABLE_REVERSE_PROXY_EMAIL` 来启用或停用这个 HTTP 头。
30+
31+
如果设置了 `ENABLE_REVERSE_PROXY_FULL_NAME=true`,则用户的全名会从 `X-WEBAUTH-FULLNAME` 读取,这样在自动创建用户时将使用这个字段作为用户全名,你也可以通过修改 `REVERSE_PROXY_AUTHENTICATION_FULL_NAME` 来变更 HTTP 头。
32+
33+
你也可以通过修改 `REVERSE_PROXY_TRUSTED_PROXIES` 来设置反向代理的IP地址范围,加强安全性,默认值是 `127.0.0.0/8,::1/128`。 通过 `REVERSE_PROXY_LIMIT`, 可以设置最多信任几级反向代理。
34+
35+
注意:反向代理认证不支持认证 API,API 仍旧需要用 access token 来进行认证。

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module code.gitea.io/gitea
22

3-
go 1.18
3+
go 1.19
44

55
require (
66
code.gitea.io/actions-proto-go v0.2.0

models/db/sql_postgres_with_schema.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ func (d *postgresSchemaDriver) Open(name string) (driver.Conn, error) {
3737
}
3838
schemaValue, _ := driver.String.ConvertValue(setting.Database.Schema)
3939

40-
// golangci lint is incorrect here - there is no benefit to using driver.ExecerContext here
41-
// and in any case pq does not implement it
42-
if execer, ok := conn.(driver.Execer); ok { //nolint
40+
if execer, ok := conn.(driver.Execer); ok {
4341
_, err := execer.Exec(`SELECT set_config(
4442
'search_path',
4543
$1 || ',' || current_setting('search_path'),
@@ -63,8 +61,7 @@ func (d *postgresSchemaDriver) Open(name string) (driver.Conn, error) {
6361

6462
// driver.String.ConvertValue will never return err for string
6563

66-
// golangci lint is incorrect here - there is no benefit to using stmt.ExecWithContext here
67-
_, err = stmt.Exec([]driver.Value{schemaValue}) //nolint
64+
_, err = stmt.Exec([]driver.Value{schemaValue})
6865
if err != nil {
6966
_ = conn.Close()
7067
return nil, err

models/issues/pull.go

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"fmt"
1010
"io"
11+
"strconv"
1112
"strings"
1213

1314
"code.gitea.io/gitea/models/db"
@@ -132,6 +133,27 @@ const (
132133
PullRequestStatusAncestor
133134
)
134135

136+
func (status PullRequestStatus) String() string {
137+
switch status {
138+
case PullRequestStatusConflict:
139+
return "CONFLICT"
140+
case PullRequestStatusChecking:
141+
return "CHECKING"
142+
case PullRequestStatusMergeable:
143+
return "MERGEABLE"
144+
case PullRequestStatusManuallyMerged:
145+
return "MANUALLY_MERGED"
146+
case PullRequestStatusError:
147+
return "ERROR"
148+
case PullRequestStatusEmpty:
149+
return "EMPTY"
150+
case PullRequestStatusAncestor:
151+
return "ANCESTOR"
152+
default:
153+
return strconv.Itoa(int(status))
154+
}
155+
}
156+
135157
// PullRequestFlow the flow of pull request
136158
type PullRequestFlow int
137159

@@ -202,6 +224,42 @@ func DeletePullsByBaseRepoID(ctx context.Context, repoID int64) error {
202224
return err
203225
}
204226

227+
// ColorFormat writes a colored string to identify this struct
228+
func (pr *PullRequest) ColorFormat(s fmt.State) {
229+
if pr == nil {
230+
log.ColorFprintf(s, "PR[%d]%s#%d[%s...%s:%s]",
231+
log.NewColoredIDValue(0),
232+
log.NewColoredValue("<nil>/<nil>"),
233+
log.NewColoredIDValue(0),
234+
log.NewColoredValue("<nil>"),
235+
log.NewColoredValue("<nil>/<nil>"),
236+
log.NewColoredValue("<nil>"),
237+
)
238+
return
239+
}
240+
241+
log.ColorFprintf(s, "PR[%d]", log.NewColoredIDValue(pr.ID))
242+
if pr.BaseRepo != nil {
243+
log.ColorFprintf(s, "%s#%d[%s...", log.NewColoredValue(pr.BaseRepo.FullName()),
244+
log.NewColoredIDValue(pr.Index), log.NewColoredValue(pr.BaseBranch))
245+
} else {
246+
log.ColorFprintf(s, "Repo[%d]#%d[%s...", log.NewColoredIDValue(pr.BaseRepoID),
247+
log.NewColoredIDValue(pr.Index), log.NewColoredValue(pr.BaseBranch))
248+
}
249+
if pr.HeadRepoID == pr.BaseRepoID {
250+
log.ColorFprintf(s, "%s]", log.NewColoredValue(pr.HeadBranch))
251+
} else if pr.HeadRepo != nil {
252+
log.ColorFprintf(s, "%s:%s]", log.NewColoredValue(pr.HeadRepo.FullName()), log.NewColoredValue(pr.HeadBranch))
253+
} else {
254+
log.ColorFprintf(s, "Repo[%d]:%s]", log.NewColoredIDValue(pr.HeadRepoID), log.NewColoredValue(pr.HeadBranch))
255+
}
256+
}
257+
258+
// String represents the pr as a simple string
259+
func (pr *PullRequest) String() string {
260+
return log.ColorFormatAsString(pr)
261+
}
262+
205263
// MustHeadUserName returns the HeadRepo's username if failed return blank
206264
func (pr *PullRequest) MustHeadUserName(ctx context.Context) string {
207265
if err := pr.LoadHeadRepo(ctx); err != nil {
@@ -234,7 +292,8 @@ func (pr *PullRequest) LoadAttributes(ctx context.Context) (err error) {
234292
return nil
235293
}
236294

237-
// LoadHeadRepo loads the head repository
295+
// LoadHeadRepo loads the head repository, pr.HeadRepo will remain nil if it does not exist
296+
// and thus ErrRepoNotExist will never be returned
238297
func (pr *PullRequest) LoadHeadRepo(ctx context.Context) (err error) {
239298
if !pr.isHeadRepoLoaded && pr.HeadRepo == nil && pr.HeadRepoID > 0 {
240299
if pr.HeadRepoID == pr.BaseRepoID {
@@ -249,14 +308,14 @@ func (pr *PullRequest) LoadHeadRepo(ctx context.Context) (err error) {
249308

250309
pr.HeadRepo, err = repo_model.GetRepositoryByID(ctx, pr.HeadRepoID)
251310
if err != nil && !repo_model.IsErrRepoNotExist(err) { // Head repo maybe deleted, but it should still work
252-
return fmt.Errorf("GetRepositoryByID(head): %w", err)
311+
return fmt.Errorf("pr[%d].LoadHeadRepo[%d]: %w", pr.ID, pr.HeadRepoID, err)
253312
}
254313
pr.isHeadRepoLoaded = true
255314
}
256315
return nil
257316
}
258317

259-
// LoadBaseRepo loads the target repository
318+
// LoadBaseRepo loads the target repository. ErrRepoNotExist may be returned.
260319
func (pr *PullRequest) LoadBaseRepo(ctx context.Context) (err error) {
261320
if pr.BaseRepo != nil {
262321
return nil
@@ -274,7 +333,7 @@ func (pr *PullRequest) LoadBaseRepo(ctx context.Context) (err error) {
274333

275334
pr.BaseRepo, err = repo_model.GetRepositoryByID(ctx, pr.BaseRepoID)
276335
if err != nil {
277-
return fmt.Errorf("repo_model.GetRepositoryByID(base): %w", err)
336+
return fmt.Errorf("pr[%d].LoadBaseRepo[%d]: %w", pr.ID, pr.BaseRepoID, err)
278337
}
279338
return nil
280339
}

0 commit comments

Comments
 (0)