Skip to content

Commit 1ca9738

Browse files
committed
Merge branch 'main' into lunny/fix_tag_404
2 parents 5420a32 + 9043584 commit 1ca9738

File tree

138 files changed

+3741
-943
lines changed

Some content is hidden

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

138 files changed

+3741
-943
lines changed

.github/workflows/cron-lock.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,4 @@ jobs:
2020
- uses: dessant/lock-threads@v5
2121
with:
2222
issue-inactive-days: 10
23-
issue-comment: |
24-
Automatically locked because of our [CONTRIBUTING guidelines](https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md#issue-locking)
2523
pr-inactive-days: 7
26-
pr-comment: |
27-
Automatically locked because of our [CONTRIBUTING guidelines](https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md#issue-locking)

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ _test
1515

1616
# MS VSCode
1717
.vscode
18-
__debug_bin
18+
__debug_bin*
1919

2020
*.cgo1.go
2121
*.cgo2.c

custom/conf/app.example.ini

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,12 @@ LEVEL = Info
956956
;GO_GET_CLONE_URL_PROTOCOL = https
957957
;;
958958
;; Close issues as long as a commit on any branch marks it as fixed
959+
;DEFAULT_CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH = false
960+
;;
961+
;; Allow users to push local repositories to Gitea and have them automatically created for a user or an org
962+
;ENABLE_PUSH_CREATE_USER = false
963+
;ENABLE_PUSH_CREATE_ORG = false
964+
;;
959965
;; Comma separated list of globally disabled repo units. Allowed values: repo.issues, repo.ext_issues, repo.pulls, repo.wiki, repo.ext_wiki, repo.projects, repo.packages, repo.actions.
960966
;DISABLED_REPO_UNITS =
961967
;;
@@ -1474,8 +1480,9 @@ LEVEL = Info
14741480
;;
14751481
;; Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled
14761482
;DEFAULT_EMAIL_NOTIFICATIONS = enabled
1477-
;; Disabled features for users, could be "deletion", more features can be disabled in future
1483+
;; Disabled features for users, could be "deletion","manage_gpg_keys" more features can be disabled in future
14781484
;; - deletion: a user cannot delete their own account
1485+
;; - manage_gpg_keys: a user cannot configure gpg keys
14791486
;USER_DISABLED_FEATURES =
14801487

14811488
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,9 @@ And the following unique queues:
518518

519519
- `DEFAULT_EMAIL_NOTIFICATIONS`: **enabled**: Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled
520520
- `DISABLE_REGULAR_ORG_CREATION`: **false**: Disallow regular (non-admin) users from creating organizations.
521-
- `USER_DISABLED_FEATURES`: **_empty_** Disabled features for users, could be `deletion` and more features can be added in future.
521+
- `USER_DISABLED_FEATURES`: **_empty_** Disabled features for users, could be `deletion`, `manage_gpg_keys` and more features can be added in future.
522522
- `deletion`: User cannot delete their own account.
523+
- `manage_gpg_keys`: User cannot configure gpg keys
523524

524525
## Security (`security`)
525526

docs/content/administration/config-cheat-sheet.zh-cn.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,9 @@ Gitea 创建以下非唯一队列:
497497

498498
- `DEFAULT_EMAIL_NOTIFICATIONS`: **enabled**:用户电子邮件通知的默认配置(用户可配置)。选项:enabled、onmention、disabled
499499
- `DISABLE_REGULAR_ORG_CREATION`: **false**:禁止普通(非管理员)用户创建组织。
500-
- `USER_DISABLED_FEATURES`:**_empty_** 禁用的用户特性,当前允许为空或者 `deletion`, 未来可以增加更多设置。
500+
- `USER_DISABLED_FEATURES`:**_empty_** 禁用的用户特性,当前允许为空或者 `deletion``manage_gpg_keys` 未来可以增加更多设置。
501501
- `deletion`: 用户不能通过界面或者API删除他自己。
502+
- `manage_gpg_keys`: 用户不能配置 GPG 密钥
502503

503504
## 安全性 (`security`)
504505

docs/content/administration/mail-templates.en-us.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ Please check [Gitea's logs](administration/logging-config.md) for error messages
224224
{{if not (eq .Body "")}}
225225
<h3>Message content</h3>
226226
<hr>
227-
{{.Body | Str2html}}
227+
{{.Body | SanitizeHTML}}
228228
{{end}}
229229
</p>
230230
<hr>
@@ -260,19 +260,19 @@ The template system contains several functions that can be used to further proce
260260
the messages. Here's a list of some of them:
261261

262262
| Name | Parameters | Available | Usage |
263-
| ---------------- | ----------- | --------- | --------------------------------------------------------------------------- |
263+
| ---------------- | ----------- | --------- |-----------------------------------------------------------------------------|
264264
| `AppUrl` | - | Any | Gitea's URL |
265265
| `AppName` | - | Any | Set from `app.ini`, usually "Gitea" |
266266
| `AppDomain` | - | Any | Gitea's host name |
267267
| `EllipsisString` | string, int | Any | Truncates a string to the specified length; adds ellipsis as needed |
268-
| `Str2html` | string | Body only | Sanitizes text by removing any HTML tags from it. |
268+
| `SanitizeHTML` | string | Body only | Sanitizes text by removing any dangerous HTML tags from it. |
269269
| `SafeHTML` | string | Body only | Takes the input as HTML; can be used for `.ReviewComments.RenderedContent`. |
270270

271271
These are _functions_, not metadata, so they have to be used:
272272

273273
```html
274-
Like this: {{Str2html "Escape<my>text"}}
275-
Or this: {{"Escape<my>text" | Str2html}}
274+
Like this: {{SanitizeHTML "Escape<my>text"}}
275+
Or this: {{"Escape<my>text" | SanitizeHTML}}
276276
Or this: {{AppUrl}}
277277
But not like this: {{.AppUrl}}
278278
```

docs/content/administration/mail-templates.zh-cn.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ _主题_ 和 _邮件正文_ 由 [Golang的模板引擎](https://go.dev/pkg/text/
207207
{{if not (eq .Body "")}}
208208
<h3>消息内容:</h3>
209209
<hr>
210-
{{.Body | Str2html}}
210+
{{.Body | SanitizeHTML}}
211211
{{end}}
212212
</p>
213213
<hr>
@@ -242,20 +242,20 @@ _主题_ 和 _邮件正文_ 由 [Golang的模板引擎](https://go.dev/pkg/text/
242242

243243
模板系统包含一些函数,可用于进一步处理和格式化消息。以下是其中一些函数的列表:
244244

245-
| 函数名 | 参数 | 可用于 | 用法 |
246-
|------------------| ----------- | ------------ | --------------------------------------------------------------------------------- |
247-
| `AppUrl` | - | 任何地方 | Gitea 的 URL |
248-
| `AppName` | - | 任何地方 |`app.ini` 中设置,通常为 "Gitea" |
249-
| `AppDomain` | - | 任何地方 | Gitea 的主机名 |
250-
| `EllipsisString` | string, int | 任何地方 | 将字符串截断为指定长度;根据需要添加省略号 |
251-
| `Str2html` | string | 仅正文部分 | 通过删除其中的 HTML 标签对文本进行清理 |
252-
| `SafeHTML` | string | 仅正文部分 | 将输入作为 HTML 处理;可用于 `.ReviewComments.RenderedContent` 等字段 |
245+
| 函数名 | 参数 | 可用于 | 用法 |
246+
|------------------| ----------- | ------------ |---------------------------------------------------------|
247+
| `AppUrl` | - | 任何地方 | Gitea 的 URL |
248+
| `AppName` | - | 任何地方 |`app.ini` 中设置,通常为 "Gitea" |
249+
| `AppDomain` | - | 任何地方 | Gitea 的主机名 |
250+
| `EllipsisString` | string, int | 任何地方 | 将字符串截断为指定长度;根据需要添加省略号 |
251+
| `SanitizeHTML` | string | 仅正文部分 | 通过删除其中的危险 HTML 标签对文本进行清理 |
252+
| `SafeHTML` | string | 仅正文部分 | 将输入作为 HTML 处理;可用于 `.ReviewComments.RenderedContent` 等字段 |
253253

254254
这些都是 _函数_,而不是元数据,因此必须按以下方式使用:
255255

256256
```html
257-
像这样使用: {{Str2html "Escape<my>text"}}
258-
或者这样使用: {{"Escape<my>text" | Str2html}}
257+
像这样使用: {{SanitizeHTML "Escape<my>text"}}
258+
或者这样使用: {{"Escape<my>text" | SanitizeHTML}}
259259
或者这样使用: {{AppUrl}}
260260
但不要像这样使用: {{.AppUrl}}
261261
```

docs/content/help/faq.en-us.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,11 @@ Our translations are currently crowd-sourced on our [Crowdin project](https://cr
221221

222222
Whether you want to change a translation or add a new one, it will need to be there as all translations are overwritten in our CI via the Crowdin integration.
223223

224-
## Push Hook / Webhook aren't running
224+
## Push Hook / Webhook / Actions aren't running
225225

226-
If you can push but can't see push activities on the home dashboard, or the push doesn't trigger webhook, there are a few possibilities:
226+
If you can push but can't see push activities on the home dashboard, or the push doesn't trigger webhook and Actions workflows, it's likely that the git hooks are not working.
227+
228+
There are a few possibilities:
227229

228230
1. The git hooks are out of sync: run "Resynchronize pre-receive, update and post-receive hooks of all repositories" on the site admin panel
229231
2. The git repositories (and hooks) are stored on some filesystems (ex: mounted by NAS) which don't support script execution, make sure the filesystem supports `chmod a+x any-script`

docs/content/help/faq.zh-cn.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,11 @@ Gitea还提供了自己的SSH服务器,用于在SSHD不可用时使用。
225225

226226
无论您想要更改翻译还是添加新的翻译,都需要在Crowdin集成中进行,因为所有翻译都会被CI覆盖。
227227

228-
## 推送钩子/ Webhook未运行
228+
## 推送钩子/ Webhook / Actions 未运行
229229

230-
如果您可以推送但无法在主页仪表板上看到推送活动,或者推送不触发Webhook,有几种可能性:
230+
如果您可以推送但无法在主页仪表板上看到推送活动,或者推送不触发 Webhook 和 Actions,可能是 git 钩子不工作而导致的。
231+
232+
这可能是由于以下原因:
231233

232234
1. Git钩子不同步:在站点管理面板上运行“重新同步所有仓库的pre-receive、update和post-receive钩子”
233235
2. Git仓库(和钩子)存储在一些不支持脚本执行的文件系统上(例如由NAS挂载),请确保文件系统支持`chmod a+x any-script`

models/fixtures/action_run.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,22 @@
1717
updated: 1683636626
1818
need_approval: 0
1919
approved_by: 0
20+
-
21+
id: 792
22+
title: "update actions"
23+
repo_id: 4
24+
owner_id: 1
25+
workflow_id: "artifact.yaml"
26+
index: 188
27+
trigger_user_id: 1
28+
ref: "refs/heads/master"
29+
commit_sha: "c2d72f548424103f01ee1dc02889c1e2bff816b0"
30+
event: "push"
31+
is_fork_pull_request: 0
32+
status: 1
33+
started: 1683636528
34+
stopped: 1683636626
35+
created: 1683636108
36+
updated: 1683636626
37+
need_approval: 0
38+
approved_by: 0

models/fixtures/action_run_job.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,17 @@
1212
status: 1
1313
started: 1683636528
1414
stopped: 1683636626
15+
-
16+
id: 193
17+
run_id: 792
18+
repo_id: 4
19+
owner_id: 1
20+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
21+
is_fork_pull_request: 0
22+
name: job_2
23+
attempt: 1
24+
job_id: job_2
25+
task_id: 48
26+
status: 1
27+
started: 1683636528
28+
stopped: 1683636626

models/fixtures/action_task.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,23 @@
1818
log_length: 707
1919
log_size: 90179
2020
log_expired: 0
21+
-
22+
id: 48
23+
job_id: 193
24+
attempt: 1
25+
runner_id: 1
26+
status: 6 # 6 is the status code for "running", running task can upload artifacts
27+
started: 1683636528
28+
stopped: 1683636626
29+
repo_id: 4
30+
owner_id: 1
31+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
32+
is_fork_pull_request: 0
33+
token_hash: ffffcfffffffbffffffffffffffffefffffffafffffffffffffffffffffffffffffdffffffffffffffffffffffffffffffff
34+
token_salt: ffffffffff
35+
token_last_eight: ffffffff
36+
log_filename: artifact-test2/2f/47.log
37+
log_in_storage: 1
38+
log_length: 707
39+
log_size: 90179
40+
log_expired: 0

models/issues/comment.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package issues
88
import (
99
"context"
1010
"fmt"
11+
"html/template"
1112
"strconv"
1213
"unicode/utf8"
1314

@@ -259,8 +260,8 @@ type Comment struct {
259260
CommitID int64
260261
Line int64 // - previous line / + proposed line
261262
TreePath string
262-
Content string `xorm:"LONGTEXT"`
263-
RenderedContent string `xorm:"-"`
263+
Content string `xorm:"LONGTEXT"`
264+
RenderedContent template.HTML `xorm:"-"`
264265

265266
// Path represents the 4 lines of code cemented by this comment
266267
Patch string `xorm:"-"`

models/issues/content_history.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,9 @@ func FetchIssueContentHistoryList(dbCtx context.Context, issueID, commentID int6
172172

173173
// HasIssueContentHistory check if a ContentHistory entry exists
174174
func HasIssueContentHistory(dbCtx context.Context, issueID, commentID int64) (bool, error) {
175-
exists, err := db.GetEngine(dbCtx).Cols("id").Exist(&ContentHistory{
176-
IssueID: issueID,
177-
CommentID: commentID,
178-
})
175+
exists, err := db.GetEngine(dbCtx).Where(builder.Eq{"issue_id": issueID, "comment_id": commentID}).Exist(&ContentHistory{})
179176
if err != nil {
180-
log.Error("can not fetch issue content history. err=%v", err)
181-
return false, err
177+
return false, fmt.Errorf("can not check issue content history. err: %w", err)
182178
}
183179
return exists, err
184180
}

models/issues/content_history_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,22 @@ func TestContentHistory(t *testing.T) {
7878
assert.EqualValues(t, 7, list2[1].HistoryID)
7979
assert.EqualValues(t, 4, list2[2].HistoryID)
8080
}
81+
82+
func TestHasIssueContentHistoryForCommentOnly(t *testing.T) {
83+
assert.NoError(t, unittest.PrepareTestDatabase())
84+
85+
_ = db.TruncateBeans(db.DefaultContext, &issues_model.ContentHistory{})
86+
87+
hasHistory1, _ := issues_model.HasIssueContentHistory(db.DefaultContext, 10, 0)
88+
assert.False(t, hasHistory1)
89+
hasHistory2, _ := issues_model.HasIssueContentHistory(db.DefaultContext, 10, 100)
90+
assert.False(t, hasHistory2)
91+
92+
_ = issues_model.SaveIssueContentHistory(db.DefaultContext, 1, 10, 100, timeutil.TimeStampNow(), "c-a", true)
93+
_ = issues_model.SaveIssueContentHistory(db.DefaultContext, 1, 10, 100, timeutil.TimeStampNow().Add(5), "c-b", false)
94+
95+
hasHistory1, _ = issues_model.HasIssueContentHistory(db.DefaultContext, 10, 0)
96+
assert.False(t, hasHistory1)
97+
hasHistory2, _ = issues_model.HasIssueContentHistory(db.DefaultContext, 10, 100)
98+
assert.True(t, hasHistory2)
99+
}

models/issues/issue.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package issues
77
import (
88
"context"
99
"fmt"
10+
"html/template"
1011
"regexp"
1112
"slices"
1213

@@ -105,7 +106,7 @@ type Issue struct {
105106
OriginalAuthorID int64 `xorm:"index"`
106107
Title string `xorm:"name"`
107108
Content string `xorm:"LONGTEXT"`
108-
RenderedContent string `xorm:"-"`
109+
RenderedContent template.HTML `xorm:"-"`
109110
Labels []*Label `xorm:"-"`
110111
MilestoneID int64 `xorm:"INDEX"`
111112
Milestone *Milestone `xorm:"-"`

models/issues/milestone.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package issues
66
import (
77
"context"
88
"fmt"
9+
"html/template"
910
"strings"
1011

1112
"code.gitea.io/gitea/models/db"
@@ -47,8 +48,8 @@ type Milestone struct {
4748
RepoID int64 `xorm:"INDEX"`
4849
Repo *repo_model.Repository `xorm:"-"`
4950
Name string
50-
Content string `xorm:"TEXT"`
51-
RenderedContent string `xorm:"-"`
51+
Content string `xorm:"TEXT"`
52+
RenderedContent template.HTML `xorm:"-"`
5253
IsClosed bool
5354
NumIssues int
5455
NumClosedIssues int

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ var migrations = []Migration{
558558
NewMigration("Add PreviousDuration to ActionRun", v1_22.AddPreviousDurationToActionRun),
559559
// v286 -> v287
560560
NewMigration("Add support for SHA256 git repositories", v1_22.AdjustDBForSha256),
561+
// v287 -> v288
562+
NewMigration("Use Slug instead of ID for Badges", v1_22.UseSlugInsteadOfIDForBadges),
561563
}
562564

563565
// GetCurrentDBVersion returns the current db version

models/migrations/v1_22/v287.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_22 //nolint
5+
6+
import (
7+
"xorm.io/xorm"
8+
)
9+
10+
type BadgeUnique struct {
11+
ID int64 `xorm:"pk autoincr"`
12+
Slug string `xorm:"UNIQUE"`
13+
}
14+
15+
func (BadgeUnique) TableName() string {
16+
return "badge"
17+
}
18+
19+
func UseSlugInsteadOfIDForBadges(x *xorm.Engine) error {
20+
type Badge struct {
21+
Slug string
22+
}
23+
24+
err := x.Sync(new(Badge))
25+
if err != nil {
26+
return err
27+
}
28+
29+
sess := x.NewSession()
30+
defer sess.Close()
31+
if err := sess.Begin(); err != nil {
32+
return err
33+
}
34+
35+
_, err = sess.Exec("UPDATE `badge` SET `slug` = `id` Where `slug` IS NULL")
36+
if err != nil {
37+
return err
38+
}
39+
40+
err = sess.Sync(new(BadgeUnique))
41+
if err != nil {
42+
return err
43+
}
44+
45+
return sess.Commit()
46+
}

0 commit comments

Comments
 (0)