Skip to content

Commit 41fbd31

Browse files
authored
Merge branch 'main' into fix-repo-topic-edit
2 parents 81c9a99 + 75022f8 commit 41fbd31

File tree

87 files changed

+2185
-791
lines changed

Some content is hidden

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

87 files changed

+2185
-791
lines changed

.drone.yml

Lines changed: 336 additions & 126 deletions
Large diffs are not rendered by default.

.stylelintrc.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
plugins:
22
- stylelint-declaration-strict-value
33

4+
ignoreFiles:
5+
- "**/*.go"
6+
47
overrides:
58
- files: ["**/*.less"]
69
customSyntax: postcss-less
710
- files: ["**/chroma/*", "**/codemirror/*", "**/standalone/*", "**/console/*"]
811
rules:
912
scale-unlimited/declaration-strict-value: null
13+
- files: ["**/chroma/*", "**/codemirror/*"]
14+
rules:
15+
block-no-empty: null
1016

1117
rules:
1218
alpha-value-notation: null

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ help:
190190
@echo " - deps install dependencies"
191191
@echo " - deps-frontend install frontend dependencies"
192192
@echo " - deps-backend install backend dependencies"
193+
@echo " - deps-tools install tool dependencies"
193194
@echo " - lint lint everything"
194195
@echo " - lint-frontend lint frontend files"
195196
@echo " - lint-backend lint backend files"
@@ -821,14 +822,17 @@ docs:
821822
cd docs; make trans-copy clean build-offline;
822823

823824
.PHONY: deps
824-
deps: deps-frontend deps-backend
825+
deps: deps-frontend deps-backend deps-tools
825826

826827
.PHONY: deps-frontend
827828
deps-frontend: node_modules
828829

829830
.PHONY: deps-backend
830831
deps-backend:
831832
$(GO) mod download
833+
834+
.PHONY: deps-tools
835+
deps-tools:
832836
$(GO) install $(AIR_PACKAGE)
833837
$(GO) install $(EDITORCONFIG_CHECKER_PACKAGE)
834838
$(GO) install $(ERRCHECK_PACKAGE)

cmd/admin.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package cmd
77
import (
88
"errors"
99
"fmt"
10+
"net/url"
1011
"os"
1112
"strings"
1213
"text/tabwriter"
@@ -469,11 +470,19 @@ func runAddOauth(c *cli.Context) error {
469470
return err
470471
}
471472

473+
config := parseOAuth2Config(c)
474+
if config.Provider == "openidConnect" {
475+
discoveryURL, err := url.Parse(config.OpenIDConnectAutoDiscoveryURL)
476+
if err != nil || (discoveryURL.Scheme != "http" && discoveryURL.Scheme != "https") {
477+
return fmt.Errorf("invalid Auto Discovery URL: %s (this must be a valid URL starting with http:// or https://)", config.OpenIDConnectAutoDiscoveryURL)
478+
}
479+
}
480+
472481
return auth_model.CreateSource(&auth_model.Source{
473482
Type: auth_model.OAuth2,
474483
Name: c.String("name"),
475484
IsActive: true,
476-
Cfg: parseOAuth2Config(c),
485+
Cfg: config,
477486
})
478487
}
479488

contrib/init/ubuntu/gitea

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/sh
2+
### BEGIN INIT INFO
3+
# Provides: gitea
4+
# Required-Start: $syslog $network
5+
# Required-Stop: $syslog
6+
# Default-Start: 2 3 4 5
7+
# Default-Stop: 0 1 6
8+
# Short-Description: A self-hosted Git service written in Go.
9+
# Description: A self-hosted Git service written in Go.
10+
### END INIT INFO
11+
12+
# Do NOT "set -e"
13+
14+
# PATH should only include /usr/* if it runs after the mountnfs.sh script
15+
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
16+
DESC="Gitea - Git with a cup of tea"
17+
NAME=gitea
18+
SERVICEVERBOSE=yes
19+
PIDFILE=/run/$NAME.pid
20+
SCRIPTNAME=/etc/init.d/$NAME
21+
WORKINGDIR=/var/lib/$NAME
22+
DAEMON=/usr/local/bin/$NAME
23+
DAEMON_ARGS="web -c /etc/$NAME/app.ini"
24+
USER=git
25+
STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/1/KILL/5}"
26+
27+
# Read configuration variable file if it is present
28+
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
29+
30+
# Exit if the package is not installed
31+
[ -x "$DAEMON" ] || exit 0
32+
33+
do_start()
34+
{
35+
GITEA_ENVS="USER=$USER GITEA_WORK_DIR=$WORKINGDIR HOME=/home/$USER"
36+
GITEA_EXEC="$DAEMON -- $DAEMON_ARGS"
37+
sh -c "start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\
38+
--background --chdir $WORKINGDIR --chuid $USER \\
39+
--exec /bin/bash -- -c '/usr/bin/env $GITEA_ENVS $GITEA_EXEC'"
40+
}
41+
42+
do_stop()
43+
{
44+
start-stop-daemon --stop --quiet --retry=$STOP_SCHEDULE --pidfile $PIDFILE --name $NAME --oknodo
45+
rm -f $PIDFILE
46+
}
47+
48+
do_status()
49+
{
50+
if [ -f $PIDFILE ]; then
51+
if kill -0 $(cat "$PIDFILE"); then
52+
echo "$NAME is running, PID is $(cat $PIDFILE)"
53+
else
54+
echo "$NAME process is dead, but pidfile exists"
55+
fi
56+
else
57+
echo "$NAME is not running"
58+
fi
59+
}
60+
61+
case "$1" in
62+
start)
63+
echo "Starting $DESC" "$NAME"
64+
do_start
65+
;;
66+
stop)
67+
echo "Stopping $DESC" "$NAME"
68+
do_stop
69+
;;
70+
status)
71+
do_status
72+
;;
73+
restart)
74+
echo "Restarting $DESC" "$NAME"
75+
do_stop
76+
do_start
77+
;;
78+
*)
79+
echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
80+
exit 2
81+
;;
82+
esac
83+
84+
exit 0

custom/conf/app.example.ini

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,22 @@ ROUTER = console
576576
;; The routing level will default to that of the system but individual router level can be set in
577577
;; [log.<mode>.router] LEVEL
578578
;;
579+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
580+
;;
581+
;; Print request id which parsed from request headers in access log, when access log is enabled.
582+
;; * E.g:
583+
;; * In request Header: X-Request-ID: test-id-123
584+
;; * Configuration in app.ini: REQUEST_ID_HEADERS = X-Request-ID
585+
;; * Print in log: 127.0.0.1:58384 - - [14/Feb/2023:16:33:51 +0800] "test-id-123"
586+
;;
587+
;; If you configure more than one in the .ini file, it will match in the order of configuration,
588+
;; and the first match will be finally printed in the log.
589+
;; * E.g:
590+
;; * In reuqest Header: X-Trace-ID: trace-id-1q2w3e4r
591+
;; * Configuration in app.ini: REQUEST_ID_HEADERS = X-Request-ID, X-Trace-ID, X-Req-ID
592+
;; * Print in log: 127.0.0.1:58384 - - [14/Feb/2023:16:33:51 +0800] "trace-id-1q2w3e4r"
593+
;;
594+
;; REQUEST_ID_HEADERS =
579595

580596
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
581597
;;

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,13 @@ Default templates for project boards:
881881
- `Identity`: the SignedUserName or `"-"` if not logged in.
882882
- `Start`: the start time of the request.
883883
- `ResponseWriter`: the responseWriter from the request.
884+
- `RequestID`: the value matching REQUEST_ID_HEADERS(default: `-`, if not matched).
884885
- You must be very careful to ensure that this template does not throw errors or panics as this template runs outside of the panic/recovery script.
886+
- `REQUEST_ID_HEADERS`: **\<empty\>**: You can configure multiple values that are splited by comma here. It will match in the order of configuration, and the first match will be finally printed in the access log.
887+
- e.g.
888+
- In the Request Header: X-Request-ID: **test-id-123**
889+
- Configuration in app.ini: REQUEST_ID_HEADERS = X-Request-ID
890+
- Print in log: 127.0.0.1:58384 - - [14/Feb/2023:16:33:51 +0800] "**test-id-123**" ...
885891

886892
### Log subsections (`log.name`, `log.name.*`)
887893

docs/content/doc/advanced/config-cheat-sheet.zh-cn.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,22 @@ test01.xls: application/vnd.ms-excel; charset=binary
262262

263263
- `ROOT_PATH`: 日志文件根目录。
264264
- `MODE`: 日志记录模式,默认是为 `console`。如果要写到多个通道,用逗号分隔
265-
- `LEVEL`: 日志级别,默认为`Trace`
265+
- `LEVEL`: 日志级别,默认为 `Trace`
266+
- `DISABLE_ROUTER_LOG`: 关闭日志中的路由日志。
267+
- `ENABLE_ACCESS_LOG`: 是否开启 Access Log, 默认为 false。
268+
- `ACCESS_LOG_TEMPLATE`: `access.log` 输出内容的模板,默认模板:**`{{.Ctx.RemoteAddr}} - {{.Identity}} {{.Start.Format "[02/Jan/2006:15:04:05 -0700]" }} "{{.Ctx.Req.Method}} {{.Ctx.Req.URL.RequestURI}} {{.Ctx.Req.Proto}}" {{.ResponseWriter.Status}} {{.ResponseWriter.Size}} "{{.Ctx.Req.Referer}}\" \"{{.Ctx.Req.UserAgent}}"`**
269+
模板支持以下参数:
270+
- `Ctx`: 请求上下文。
271+
- `Identity`: 登录用户名,默认: “`-`”。
272+
- `Start`: 请求开始时间。
273+
- `ResponseWriter`:
274+
- `RequestID`: 从请求头中解析得到的与 `REQUEST_ID_HEADERS` 匹配的值,默认: “`-`”。
275+
- 一定要谨慎配置该模板,否则可能会引起panic.
276+
- `REQUEST_ID_HEADERS`: 从 Request Header 中匹配指定 Key,并将匹配到的值输出到 `access.log` 中(需要在 `ACCESS_LOG_TEMPLATE` 中指定输出位置)。如果在该参数中配置多个 Key, 请用逗号分割,程序将按照配置的顺序进行匹配。
277+
- 示例:
278+
- 请求头: X-Request-ID: **test-id-123**
279+
- 配置文件: REQUEST_ID_HEADERS = X-Request-ID
280+
- 日志输出: 127.0.0.1:58384 - - [14/Feb/2023:16:33:51 +0800] "**test-id-123**" ...
266281

267282
## Cron (`cron`)
268283

docs/content/doc/developers/oauth2-provider.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Gitea supports the following scopes for tokens:
6060
| &nbsp;&nbsp;&nbsp; **write:public_key** | Grant read/write access to public keys |
6161
| &nbsp;&nbsp;&nbsp; **read:public_key** | Grant read-only access to public keys |
6262
| **admin:org_hook** | Grants full access to organizational-level hooks |
63+
| **admin:user_hook** | Grants full access to user-level hooks |
6364
| **notification** | Grants full access to notifications |
6465
| **user** | Grants full access to user profile info |
6566
| &nbsp;&nbsp;&nbsp; **read:user** | Grants read access to user's profile |

docs/content/doc/packages/maven.en-us.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Publish [Maven](https://maven.apache.org) packages for your user or organization
2323
## Requirements
2424

2525
To work with the Maven package registry, you can use [Maven](https://maven.apache.org/install.html) or [Gradle](https://gradle.org/install/).
26-
The following examples use `Maven`.
26+
The following examples use `Maven` and `Gradle Groovy`.
2727

2828
## Configuring the package registry
2929

@@ -73,6 +73,40 @@ Afterwards add the following sections to your project `pom.xml` file:
7373
| `access_token` | Your [personal access token]({{< relref "doc/developers/api-usage.en-us.md#authentication" >}}). |
7474
| `owner` | The owner of the package. |
7575

76+
### Gradle variant
77+
78+
When you plan to add some packages from Gitea instance in your project, you should add it in repositories section:
79+
80+
```groovy
81+
repositories {
82+
// other repositories
83+
maven { url "https://gitea.example.com/api/packages/{owner}/maven" }
84+
}
85+
```
86+
87+
In Groovy gradle you may include next script in your publishing part:
88+
89+
```groovy
90+
publishing {
91+
// other settings of publication
92+
repositories {
93+
maven {
94+
name = "Gitea"
95+
url = uri("https://gitea.example.com/api/packages/{owner}/maven")
96+
97+
credentials(HttpHeaderCredentials) {
98+
name = "Authorization"
99+
value = "token {access_token}"
100+
}
101+
102+
authentication {
103+
header(HttpHeaderAuthentication)
104+
}
105+
}
106+
}
107+
}
108+
```
109+
76110
## Publish a package
77111

78112
To publish a package simply run:
@@ -81,6 +115,12 @@ To publish a package simply run:
81115
mvn deploy
82116
```
83117

118+
Or call `gradle` with task `publishAllPublicationsToGiteaRepository` in case you are using gradle:
119+
120+
```groovy
121+
./gradlew publishAllPublicationsToGiteaRepository
122+
```
123+
84124
If you want to publish a prebuild package to the registry, you can use [`mvn deploy:deploy-file`](https://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html):
85125

86126
```shell
@@ -105,6 +145,12 @@ To install a Maven package from the package registry, add a new dependency to yo
105145
</dependency>
106146
```
107147

148+
And analog in gradle groovy:
149+
150+
```groovy
151+
implementation "com.test.package:test_project:1.0.0"
152+
```
153+
108154
Afterwards run:
109155

110156
```shell

models/auth/token_scope.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const (
3232

3333
AccessTokenScopeAdminOrgHook AccessTokenScope = "admin:org_hook"
3434

35+
AccessTokenScopeAdminUserHook AccessTokenScope = "admin:user_hook"
36+
3537
AccessTokenScopeNotification AccessTokenScope = "notification"
3638

3739
AccessTokenScopeUser AccessTokenScope = "user"
@@ -64,7 +66,7 @@ type AccessTokenScopeBitmap uint64
6466
const (
6567
// AccessTokenScopeAllBits is the bitmap of all access token scopes, except `sudo`.
6668
AccessTokenScopeAllBits AccessTokenScopeBitmap = AccessTokenScopeRepoBits |
67-
AccessTokenScopeAdminOrgBits | AccessTokenScopeAdminPublicKeyBits | AccessTokenScopeAdminOrgHookBits |
69+
AccessTokenScopeAdminOrgBits | AccessTokenScopeAdminPublicKeyBits | AccessTokenScopeAdminOrgHookBits | AccessTokenScopeAdminUserHookBits |
6870
AccessTokenScopeNotificationBits | AccessTokenScopeUserBits | AccessTokenScopeDeleteRepoBits |
6971
AccessTokenScopePackageBits | AccessTokenScopeAdminGPGKeyBits | AccessTokenScopeAdminApplicationBits
7072

@@ -86,6 +88,8 @@ const (
8688

8789
AccessTokenScopeAdminOrgHookBits AccessTokenScopeBitmap = 1 << iota
8890

91+
AccessTokenScopeAdminUserHookBits AccessTokenScopeBitmap = 1 << iota
92+
8993
AccessTokenScopeNotificationBits AccessTokenScopeBitmap = 1 << iota
9094

9195
AccessTokenScopeUserBits AccessTokenScopeBitmap = 1<<iota | AccessTokenScopeReadUserBits | AccessTokenScopeUserEmailBits | AccessTokenScopeUserFollowBits
@@ -123,6 +127,7 @@ var allAccessTokenScopes = []AccessTokenScope{
123127
AccessTokenScopeAdminPublicKey, AccessTokenScopeWritePublicKey, AccessTokenScopeReadPublicKey,
124128
AccessTokenScopeAdminRepoHook, AccessTokenScopeWriteRepoHook, AccessTokenScopeReadRepoHook,
125129
AccessTokenScopeAdminOrgHook,
130+
AccessTokenScopeAdminUserHook,
126131
AccessTokenScopeNotification,
127132
AccessTokenScopeUser, AccessTokenScopeReadUser, AccessTokenScopeUserEmail, AccessTokenScopeUserFollow,
128133
AccessTokenScopeDeleteRepo,
@@ -147,6 +152,7 @@ var allAccessTokenScopeBits = map[AccessTokenScope]AccessTokenScopeBitmap{
147152
AccessTokenScopeWriteRepoHook: AccessTokenScopeWriteRepoHookBits,
148153
AccessTokenScopeReadRepoHook: AccessTokenScopeReadRepoHookBits,
149154
AccessTokenScopeAdminOrgHook: AccessTokenScopeAdminOrgHookBits,
155+
AccessTokenScopeAdminUserHook: AccessTokenScopeAdminUserHookBits,
150156
AccessTokenScopeNotification: AccessTokenScopeNotificationBits,
151157
AccessTokenScopeUser: AccessTokenScopeUserBits,
152158
AccessTokenScopeReadUser: AccessTokenScopeReadUserBits,
@@ -263,7 +269,7 @@ func (bitmap AccessTokenScopeBitmap) ToScope() AccessTokenScope {
263269
scope := AccessTokenScope(strings.Join(scopes, ","))
264270
scope = AccessTokenScope(strings.ReplaceAll(
265271
string(scope),
266-
"repo,admin:org,admin:public_key,admin:org_hook,notification,user,delete_repo,package,admin:gpg_key,admin:application",
272+
"repo,admin:org,admin:public_key,admin:org_hook,admin:user_hook,notification,user,delete_repo,package,admin:gpg_key,admin:application",
267273
"all",
268274
))
269275
return scope

models/auth/token_scope_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func TestAccessTokenScope_Normalize(t *testing.T) {
4040
{"admin:gpg_key,write:gpg_key,user", "user,admin:gpg_key", nil},
4141
{"admin:application,write:application,user", "user,admin:application", nil},
4242
{"all", "all", nil},
43-
{"repo,admin:org,admin:public_key,admin:repo_hook,admin:org_hook,notification,user,delete_repo,package,admin:gpg_key,admin:application", "all", nil},
44-
{"repo,admin:org,admin:public_key,admin:repo_hook,admin:org_hook,notification,user,delete_repo,package,admin:gpg_key,admin:application,sudo", "all,sudo", nil},
43+
{"repo,admin:org,admin:public_key,admin:repo_hook,admin:org_hook,admin:user_hook,notification,user,delete_repo,package,admin:gpg_key,admin:application", "all", nil},
44+
{"repo,admin:org,admin:public_key,admin:repo_hook,admin:org_hook,admin:user_hook,notification,user,delete_repo,package,admin:gpg_key,admin:application,sudo", "all,sudo", nil},
4545
}
4646

4747
for _, test := range tests {

models/fixtures/webhook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
-
1818
id: 3
19-
org_id: 3
19+
owner_id: 3
2020
repo_id: 3
2121
url: www.example.com/url3
2222
content_type: 1 # json

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ var migrations = []Migration{
467467

468468
// v244 -> v245
469469
NewMigration("Add NeedApproval to actions tables", v1_20.AddNeedApprovalToActionRun),
470+
// v245 -> v246
471+
NewMigration("Rename Webhook org_id to owner_id", v1_20.RenameWebhookOrgToOwner),
470472
}
471473

472474
// GetCurrentDBVersion returns the current db version

0 commit comments

Comments
 (0)