Skip to content

Commit c0766f2

Browse files
authored
Merge branch 'main' into fix-htmlurl
2 parents 818a5f4 + 6465f94 commit c0766f2

File tree

109 files changed

+2510
-502
lines changed

Some content is hidden

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

109 files changed

+2510
-502
lines changed

models/actions/runner.go

Lines changed: 8 additions & 5 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 5 additions & 4 deletions
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/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: 8 additions & 7 deletions
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"
@@ -1036,8 +1037,8 @@ type FindCommentsOptions struct {
10361037
TreePath string
10371038
Type CommentType
10381039
IssueIDs []int64
1039-
Invalidated util.OptionalBool
1040-
IsPull util.OptionalBool
1040+
Invalidated optional.Option[bool]
1041+
IsPull optional.Option[bool]
10411042
}
10421043

10431044
// ToConds implements FindOptions interface
@@ -1069,11 +1070,11 @@ func (opts FindCommentsOptions) ToConds() builder.Cond {
10691070
if len(opts.TreePath) > 0 {
10701071
cond = cond.And(builder.Eq{"comment.tree_path": opts.TreePath})
10711072
}
1072-
if !opts.Invalidated.IsNone() {
1073-
cond = cond.And(builder.Eq{"comment.invalidated": opts.Invalidated.IsTrue()})
1073+
if opts.Invalidated.Has() {
1074+
cond = cond.And(builder.Eq{"comment.invalidated": opts.Invalidated.Value()})
10741075
}
1075-
if opts.IsPull != util.OptionalBoolNone {
1076-
cond = cond.And(builder.Eq{"issue.is_pull": opts.IsPull.IsTrue()})
1076+
if opts.IsPull.Has() {
1077+
cond = cond.And(builder.Eq{"issue.is_pull": opts.IsPull.Value()})
10771078
}
10781079
return cond
10791080
}
@@ -1082,7 +1083,7 @@ func (opts FindCommentsOptions) ToConds() builder.Cond {
10821083
func FindComments(ctx context.Context, opts *FindCommentsOptions) (CommentList, error) {
10831084
comments := make([]*Comment, 0, 10)
10841085
sess := db.GetEngine(ctx).Where(opts.ToConds())
1085-
if opts.RepoID > 0 || opts.IsPull != util.OptionalBoolNone {
1086+
if opts.RepoID > 0 || opts.IsPull.Has() {
10861087
sess.Join("INNER", "issue", "issue.id = comment.issue_id")
10871088
}
10881089

models/issues/issue_search.go

Lines changed: 11 additions & 14 deletions
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"
@@ -34,8 +34,8 @@ type IssuesOptions struct { //nolint
3434
MilestoneIDs []int64
3535
ProjectID int64
3636
ProjectBoardID int64
37-
IsClosed util.OptionalBool
38-
IsPull util.OptionalBool
37+
IsClosed optional.Option[bool]
38+
IsPull optional.Option[bool]
3939
LabelIDs []int64
4040
IncludedLabelNames []string
4141
ExcludedLabelNames []string
@@ -46,7 +46,7 @@ type IssuesOptions struct { //nolint
4646
UpdatedBeforeUnix int64
4747
// prioritize issues from this repo
4848
PriorityRepoID int64
49-
IsArchived util.OptionalBool
49+
IsArchived optional.Option[bool]
5050
Org *organization.Organization // issues permission scope
5151
Team *organization.Team // issues permission scope
5252
User *user_model.User // issues permission scope
@@ -217,8 +217,8 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
217217

218218
applyRepoConditions(sess, opts)
219219

220-
if !opts.IsClosed.IsNone() {
221-
sess.And("issue.is_closed=?", opts.IsClosed.IsTrue())
220+
if opts.IsClosed.Has() {
221+
sess.And("issue.is_closed=?", opts.IsClosed.Value())
222222
}
223223

224224
if opts.AssigneeID > 0 {
@@ -260,21 +260,18 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
260260

261261
applyProjectBoardCondition(sess, opts)
262262

263-
switch opts.IsPull {
264-
case util.OptionalBoolTrue:
265-
sess.And("issue.is_pull=?", true)
266-
case util.OptionalBoolFalse:
267-
sess.And("issue.is_pull=?", false)
263+
if opts.IsPull.Has() {
264+
sess.And("issue.is_pull=?", opts.IsPull.Value())
268265
}
269266

270-
if opts.IsArchived != util.OptionalBoolNone {
271-
sess.And(builder.Eq{"repository.is_archived": opts.IsArchived.IsTrue()})
267+
if opts.IsArchived.Has() {
268+
sess.And(builder.Eq{"repository.is_archived": opts.IsArchived.Value()})
272269
}
273270

274271
applyLabelsCondition(sess, opts)
275272

276273
if opts.User != nil {
277-
sess.And(issuePullAccessibleRepoCond("issue.repo_id", opts.User.ID, opts.Org, opts.Team, opts.IsPull.IsTrue()))
274+
sess.And(issuePullAccessibleRepoCond("issue.repo_id", opts.User.ID, opts.Org, opts.Team, opts.IsPull.Value()))
278275
}
279276

280277
return sess

models/issues/issue_stats.go

Lines changed: 2 additions & 6 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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)