Skip to content

Commit b476683

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Breaking summary for template refactoring (go-gitea#29395) [skip ci] Updated translations via Crowdin Fix incorrect cookie path for AppSubURL (go-gitea#29534) gitea.service: Remove syslog.target (go-gitea#29550) Add option to set language in admin user view (go-gitea#28449) Fix elipsis button not working if the last commit loading is deferred (go-gitea#29544) Fix incorrect relative/absolute URL usages (go-gitea#29531) Add support for API blob upload of release attachments (go-gitea#29507) Fix queue worker incorrectly stopped when there are still more items in the queue (go-gitea#29532) remove util.OptionalBool and related functions (go-gitea#29513) Rename Action.GetDisplayName to GetActDisplayName (go-gitea#29540) Make PR form use toast to show error message (go-gitea#29545)
2 parents 768e1ba + e71b692 commit b476683

File tree

103 files changed

+574
-539
lines changed

Some content is hidden

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

103 files changed

+574
-539
lines changed

contrib/systemd/gitea.service

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[Unit]
22
Description=Gitea (Git with a cup of tea)
3-
After=syslog.target
43
After=network.target
54
###
65
# Don't forget to add the database service dependencies

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,14 @@ This template produces something along these lines:
259259
The template system contains several functions that can be used to further process and format
260260
the messages. Here's a list of some of them:
261261

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

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

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,14 @@ _主题_ 和 _邮件正文_ 由 [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-
| `SanitizeHTML` | 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 处理;可用于输出原始的 HTML 内容 |
253253

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

models/actions/runner.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
repo_model "code.gitea.io/gitea/models/repo"
1414
"code.gitea.io/gitea/models/shared/types"
1515
user_model "code.gitea.io/gitea/models/user"
16+
"code.gitea.io/gitea/modules/optional"
1617
"code.gitea.io/gitea/modules/timeutil"
1718
"code.gitea.io/gitea/modules/translation"
1819
"code.gitea.io/gitea/modules/util"
@@ -159,7 +160,7 @@ type FindRunnerOptions struct {
159160
OwnerID int64
160161
Sort string
161162
Filter string
162-
IsOnline util.OptionalBool
163+
IsOnline optional.Option[bool]
163164
WithAvailable bool // not only runners belong to, but also runners can be used
164165
}
165166

@@ -186,10 +187,12 @@ func (opts FindRunnerOptions) ToConds() builder.Cond {
186187
cond = cond.And(builder.Like{"name", opts.Filter})
187188
}
188189

189-
if opts.IsOnline.IsTrue() {
190-
cond = cond.And(builder.Gt{"last_online": time.Now().Add(-RunnerOfflineTime).Unix()})
191-
} else if opts.IsOnline.IsFalse() {
192-
cond = cond.And(builder.Lte{"last_online": time.Now().Add(-RunnerOfflineTime).Unix()})
190+
if opts.IsOnline.Has() {
191+
if opts.IsOnline.Value() {
192+
cond = cond.And(builder.Gt{"last_online": time.Now().Add(-RunnerOfflineTime).Unix()})
193+
} else {
194+
cond = cond.And(builder.Lte{"last_online": time.Now().Add(-RunnerOfflineTime).Unix()})
195+
}
193196
}
194197
return cond
195198
}

models/activities/action.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ func (a *Action) ShortActUserName(ctx context.Context) string {
225225
return base.EllipsisString(a.GetActUserName(ctx), 20)
226226
}
227227

228-
// GetDisplayName gets the action's display name based on DEFAULT_SHOW_FULL_NAME, or falls back to the username if it is blank.
229-
func (a *Action) GetDisplayName(ctx context.Context) string {
228+
// GetActDisplayName gets the action's display name based on DEFAULT_SHOW_FULL_NAME, or falls back to the username if it is blank.
229+
func (a *Action) GetActDisplayName(ctx context.Context) string {
230230
if setting.UI.DefaultShowFullName {
231231
trimmedFullName := strings.TrimSpace(a.GetActFullName(ctx))
232232
if len(trimmedFullName) > 0 {
@@ -236,8 +236,8 @@ func (a *Action) GetDisplayName(ctx context.Context) string {
236236
return a.ShortActUserName(ctx)
237237
}
238238

239-
// GetDisplayNameTitle gets the action's display name used for the title (tooltip) based on DEFAULT_SHOW_FULL_NAME
240-
func (a *Action) GetDisplayNameTitle(ctx context.Context) string {
239+
// GetActDisplayNameTitle gets the action's display name used for the title (tooltip) based on DEFAULT_SHOW_FULL_NAME
240+
func (a *Action) GetActDisplayNameTitle(ctx context.Context) string {
241241
if setting.UI.DefaultShowFullName {
242242
return a.ShortActUserName(ctx)
243243
}

models/auth/source.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"code.gitea.io/gitea/models/db"
1313
"code.gitea.io/gitea/modules/log"
14+
"code.gitea.io/gitea/modules/optional"
1415
"code.gitea.io/gitea/modules/timeutil"
1516
"code.gitea.io/gitea/modules/util"
1617

@@ -243,14 +244,14 @@ func CreateSource(ctx context.Context, source *Source) error {
243244

244245
type FindSourcesOptions struct {
245246
db.ListOptions
246-
IsActive util.OptionalBool
247+
IsActive optional.Option[bool]
247248
LoginType Type
248249
}
249250

250251
func (opts FindSourcesOptions) ToConds() builder.Cond {
251252
conds := builder.NewCond()
252-
if !opts.IsActive.IsNone() {
253-
conds = conds.And(builder.Eq{"is_active": opts.IsActive.IsTrue()})
253+
if opts.IsActive.Has() {
254+
conds = conds.And(builder.Eq{"is_active": opts.IsActive.Value()})
254255
}
255256
if opts.LoginType != NoType {
256257
conds = conds.And(builder.Eq{"`type`": opts.LoginType})
@@ -262,7 +263,7 @@ func (opts FindSourcesOptions) ToConds() builder.Cond {
262263
// source of type LoginSSPI
263264
func IsSSPIEnabled(ctx context.Context) bool {
264265
exist, err := db.Exist[Source](ctx, FindSourcesOptions{
265-
IsActive: util.OptionalBoolTrue,
266+
IsActive: optional.Some(true),
266267
LoginType: SSPI,
267268
}.ToConds())
268269
if err != nil {

models/issues/comment.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"code.gitea.io/gitea/modules/gitrepo"
2323
"code.gitea.io/gitea/modules/json"
2424
"code.gitea.io/gitea/modules/log"
25+
"code.gitea.io/gitea/modules/optional"
2526
"code.gitea.io/gitea/modules/references"
2627
"code.gitea.io/gitea/modules/structs"
2728
"code.gitea.io/gitea/modules/timeutil"
@@ -1038,8 +1039,8 @@ type FindCommentsOptions struct {
10381039
TreePath string
10391040
Type CommentType
10401041
IssueIDs []int64
1041-
Invalidated util.OptionalBool
1042-
IsPull util.OptionalBool
1042+
Invalidated optional.Option[bool]
1043+
IsPull optional.Option[bool]
10431044
}
10441045

10451046
// ToConds implements FindOptions interface
@@ -1071,11 +1072,11 @@ func (opts FindCommentsOptions) ToConds() builder.Cond {
10711072
if len(opts.TreePath) > 0 {
10721073
cond = cond.And(builder.Eq{"comment.tree_path": opts.TreePath})
10731074
}
1074-
if !opts.Invalidated.IsNone() {
1075-
cond = cond.And(builder.Eq{"comment.invalidated": opts.Invalidated.IsTrue()})
1075+
if opts.Invalidated.Has() {
1076+
cond = cond.And(builder.Eq{"comment.invalidated": opts.Invalidated.Value()})
10761077
}
1077-
if opts.IsPull != util.OptionalBoolNone {
1078-
cond = cond.And(builder.Eq{"issue.is_pull": opts.IsPull.IsTrue()})
1078+
if opts.IsPull.Has() {
1079+
cond = cond.And(builder.Eq{"issue.is_pull": opts.IsPull.Value()})
10791080
}
10801081
return cond
10811082
}
@@ -1084,7 +1085,7 @@ func (opts FindCommentsOptions) ToConds() builder.Cond {
10841085
func FindComments(ctx context.Context, opts *FindCommentsOptions) (CommentList, error) {
10851086
comments := make([]*Comment, 0, 10)
10861087
sess := db.GetEngine(ctx).Where(opts.ToConds())
1087-
if opts.RepoID > 0 || opts.IsPull != util.OptionalBoolNone {
1088+
if opts.RepoID > 0 || opts.IsPull.Has() {
10881089
sess.Join("INNER", "issue", "issue.id = comment.issue_id")
10891090
}
10901091

models/issues/issue_search.go

+11-14
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
repo_model "code.gitea.io/gitea/models/repo"
1414
"code.gitea.io/gitea/models/unit"
1515
user_model "code.gitea.io/gitea/models/user"
16-
"code.gitea.io/gitea/modules/util"
16+
"code.gitea.io/gitea/modules/optional"
1717

1818
"xorm.io/builder"
1919
"xorm.io/xorm"
@@ -33,8 +33,8 @@ type IssuesOptions struct { //nolint
3333
MilestoneIDs []int64
3434
ProjectID int64
3535
ProjectBoardID int64
36-
IsClosed util.OptionalBool
37-
IsPull util.OptionalBool
36+
IsClosed optional.Option[bool]
37+
IsPull optional.Option[bool]
3838
LabelIDs []int64
3939
IncludedLabelNames []string
4040
ExcludedLabelNames []string
@@ -45,7 +45,7 @@ type IssuesOptions struct { //nolint
4545
UpdatedBeforeUnix int64
4646
// prioritize issues from this repo
4747
PriorityRepoID int64
48-
IsArchived util.OptionalBool
48+
IsArchived optional.Option[bool]
4949
Org *organization.Organization // issues permission scope
5050
Team *organization.Team // issues permission scope
5151
User *user_model.User // issues permission scope
@@ -210,8 +210,8 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
210210

211211
applyRepoConditions(sess, opts)
212212

213-
if !opts.IsClosed.IsNone() {
214-
sess.And("issue.is_closed=?", opts.IsClosed.IsTrue())
213+
if opts.IsClosed.Has() {
214+
sess.And("issue.is_closed=?", opts.IsClosed.Value())
215215
}
216216

217217
if opts.AssigneeID > 0 {
@@ -253,21 +253,18 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
253253

254254
applyProjectBoardCondition(sess, opts)
255255

256-
switch opts.IsPull {
257-
case util.OptionalBoolTrue:
258-
sess.And("issue.is_pull=?", true)
259-
case util.OptionalBoolFalse:
260-
sess.And("issue.is_pull=?", false)
256+
if opts.IsPull.Has() {
257+
sess.And("issue.is_pull=?", opts.IsPull.Value())
261258
}
262259

263-
if opts.IsArchived != util.OptionalBoolNone {
264-
sess.And(builder.Eq{"repository.is_archived": opts.IsArchived.IsTrue()})
260+
if opts.IsArchived.Has() {
261+
sess.And(builder.Eq{"repository.is_archived": opts.IsArchived.Value()})
265262
}
266263

267264
applyLabelsCondition(sess, opts)
268265

269266
if opts.User != nil {
270-
sess.And(issuePullAccessibleRepoCond("issue.repo_id", opts.User.ID, opts.Org, opts.Team, opts.IsPull.IsTrue()))
267+
sess.And(issuePullAccessibleRepoCond("issue.repo_id", opts.User.ID, opts.Org, opts.Team, opts.IsPull.Value()))
271268
}
272269

273270
return sess

models/issues/issue_stats.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99

1010
"code.gitea.io/gitea/models/db"
11-
"code.gitea.io/gitea/modules/util"
1211

1312
"xorm.io/builder"
1413
"xorm.io/xorm"
@@ -170,11 +169,8 @@ func applyIssuesOptions(sess *xorm.Session, opts *IssuesOptions, issueIDs []int6
170169
applyReviewedCondition(sess, opts.ReviewedID)
171170
}
172171

173-
switch opts.IsPull {
174-
case util.OptionalBoolTrue:
175-
sess.And("issue.is_pull=?", true)
176-
case util.OptionalBoolFalse:
177-
sess.And("issue.is_pull=?", false)
172+
if opts.IsPull.Has() {
173+
sess.And("issue.is_pull=?", opts.IsPull.Value())
178174
}
179175

180176
return sess

models/issues/label.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"code.gitea.io/gitea/models/db"
1414
"code.gitea.io/gitea/modules/label"
15+
"code.gitea.io/gitea/modules/optional"
1516
"code.gitea.io/gitea/modules/timeutil"
1617
"code.gitea.io/gitea/modules/util"
1718

@@ -126,7 +127,7 @@ func (l *Label) CalOpenOrgIssues(ctx context.Context, repoID, labelID int64) {
126127
counts, _ := CountIssuesByRepo(ctx, &IssuesOptions{
127128
RepoIDs: []int64{repoID},
128129
LabelIDs: []int64{labelID},
129-
IsClosed: util.OptionalBoolFalse,
130+
IsClosed: optional.Some(false),
130131
})
131132

132133
for _, count := range counts {

models/issues/milestone.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"code.gitea.io/gitea/models/db"
1313
repo_model "code.gitea.io/gitea/models/repo"
14+
"code.gitea.io/gitea/modules/optional"
1415
api "code.gitea.io/gitea/modules/structs"
1516
"code.gitea.io/gitea/modules/timeutil"
1617
"code.gitea.io/gitea/modules/util"
@@ -302,7 +303,7 @@ func DeleteMilestoneByRepoID(ctx context.Context, repoID, id int64) error {
302303
}
303304
numClosedMilestones, err := db.Count[Milestone](ctx, FindMilestoneOptions{
304305
RepoID: repo.ID,
305-
IsClosed: util.OptionalBoolTrue,
306+
IsClosed: optional.Some(true),
306307
})
307308
if err != nil {
308309
return err

models/issues/milestone_list.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99

1010
"code.gitea.io/gitea/models/db"
11-
"code.gitea.io/gitea/modules/util"
11+
"code.gitea.io/gitea/modules/optional"
1212

1313
"xorm.io/builder"
1414
)
@@ -28,7 +28,7 @@ func (milestones MilestoneList) getMilestoneIDs() []int64 {
2828
type FindMilestoneOptions struct {
2929
db.ListOptions
3030
RepoID int64
31-
IsClosed util.OptionalBool
31+
IsClosed optional.Option[bool]
3232
Name string
3333
SortType string
3434
RepoCond builder.Cond
@@ -40,8 +40,8 @@ func (opts FindMilestoneOptions) ToConds() builder.Cond {
4040
if opts.RepoID != 0 {
4141
cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
4242
}
43-
if opts.IsClosed != util.OptionalBoolNone {
44-
cond = cond.And(builder.Eq{"is_closed": opts.IsClosed.IsTrue()})
43+
if opts.IsClosed.Has() {
44+
cond = cond.And(builder.Eq{"is_closed": opts.IsClosed.Value()})
4545
}
4646
if opts.RepoCond != nil && opts.RepoCond.IsValid() {
4747
cond = cond.And(builder.In("repo_id", builder.Select("id").From("repository").Where(opts.RepoCond)))

0 commit comments

Comments
 (0)