Skip to content

Commit e1057cc

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix line height on inline code preview (go-gitea#30372) Refactor more filterslice (go-gitea#30370) Fix ambiguous id when fetch Actions tasks (go-gitea#30382) Fix floated list items (go-gitea#30377) Fix actions design about default actions download url (go-gitea#30360) Add container.FilterSlice function (go-gitea#30339) Fix label-list rendering in timeline, decrease gap (go-gitea#30342) Performance optimization for git push (go-gitea#30104) Reduce checkbox size to 15px (go-gitea#30346)
2 parents d5add2e + 6cac11c commit e1057cc

29 files changed

+287
-287
lines changed

cmd/hook.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -448,21 +448,24 @@ Gitea or set your environment appropriately.`, "")
448448

449449
func hookPrintResults(results []private.HookPostReceiveBranchResult) {
450450
for _, res := range results {
451-
if !res.Message {
452-
continue
453-
}
451+
hookPrintResult(res.Message, res.Create, res.Branch, res.URL)
452+
}
453+
}
454454

455-
fmt.Fprintln(os.Stderr, "")
456-
if res.Create {
457-
fmt.Fprintf(os.Stderr, "Create a new pull request for '%s':\n", res.Branch)
458-
fmt.Fprintf(os.Stderr, " %s\n", res.URL)
459-
} else {
460-
fmt.Fprint(os.Stderr, "Visit the existing pull request:\n")
461-
fmt.Fprintf(os.Stderr, " %s\n", res.URL)
462-
}
463-
fmt.Fprintln(os.Stderr, "")
464-
os.Stderr.Sync()
455+
func hookPrintResult(output, isCreate bool, branch, url string) {
456+
if !output {
457+
return
458+
}
459+
fmt.Fprintln(os.Stderr, "")
460+
if isCreate {
461+
fmt.Fprintf(os.Stderr, "Create a new pull request for '%s':\n", branch)
462+
fmt.Fprintf(os.Stderr, " %s\n", url)
463+
} else {
464+
fmt.Fprint(os.Stderr, "Visit the existing pull request:\n")
465+
fmt.Fprintf(os.Stderr, " %s\n", url)
465466
}
467+
fmt.Fprintln(os.Stderr, "")
468+
os.Stderr.Sync()
466469
}
467470

468471
func pushOptions() map[string]string {
@@ -691,6 +694,12 @@ Gitea or set your environment appropriately.`, "")
691694
}
692695
err = writeFlushPktLine(ctx, os.Stdout)
693696

697+
if err == nil {
698+
for _, res := range resp.Results {
699+
hookPrintResult(res.ShouldShowMessage, res.IsCreatePR, res.HeadBranch, res.URL)
700+
}
701+
}
702+
694703
return err
695704
}
696705

docs/content/usage/actions/design.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ However, if a job container tries to fetch code from localhost, it will fail bec
104104
### Connection 3, act runner to internet
105105

106106
When you use some actions like `actions/checkout@v4`, the act runner downloads the scripts, not the job containers.
107-
By default, it downloads from [gitea.com](http://gitea.com/), so it requires access to the internet.
107+
By default, it downloads from [github.com](http://github.com/), so it requires access to the internet. If you configure the `DEFAULT_ACTIONS_URL` to `self`, then it will download from your Gitea instance by default. Then it will not connect to internet when downloading the action itself.
108108
It also downloads some docker images from Docker Hub by default, which also requires internet access.
109109

110110
However, internet access is not strictly necessary.

docs/content/usage/actions/design.zh-cn.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ act runner 必须能够连接到Gitea以接收任务并发送执行结果回来
105105
### 连接 3,act runner到互联网
106106

107107
当您使用诸如 `actions/checkout@v4` 的一些Actions时,act runner下载的是脚本,而不是Job容器。
108-
默认情况下,它从[gitea.com](http://gitea.com/)下载,因此需要访问互联网。
108+
默认情况下,它从[github.com](http://github.com/)下载,因此需要访问互联网。如果您设置的是 self,
109+
那么默认将从您的当前Gitea实例下载,那么此步骤不需要连接到互联网。
109110
它还默认从Docker Hub下载一些Docker镜像,这也需要互联网访问。
110111

111112
然而,互联网访问并不是绝对必需的。

models/actions/run_job_list.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ import (
1616
type ActionJobList []*ActionRunJob
1717

1818
func (jobs ActionJobList) GetRunIDs() []int64 {
19-
ids := make(container.Set[int64], len(jobs))
20-
for _, j := range jobs {
21-
if j.RunID == 0 {
22-
continue
23-
}
24-
ids.Add(j.RunID)
25-
}
26-
return ids.Values()
19+
return container.FilterSlice(jobs, func(j *ActionRunJob) (int64, bool) {
20+
return j.RunID, j.RunID != 0
21+
})
2722
}
2823

2924
func (jobs ActionJobList) LoadRuns(ctx context.Context, withRepo bool) error {

models/actions/run_list.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,15 @@ type RunList []*ActionRun
1919

2020
// GetUserIDs returns a slice of user's id
2121
func (runs RunList) GetUserIDs() []int64 {
22-
ids := make(container.Set[int64], len(runs))
23-
for _, run := range runs {
24-
ids.Add(run.TriggerUserID)
25-
}
26-
return ids.Values()
22+
return container.FilterSlice(runs, func(run *ActionRun) (int64, bool) {
23+
return run.TriggerUserID, true
24+
})
2725
}
2826

2927
func (runs RunList) GetRepoIDs() []int64 {
30-
ids := make(container.Set[int64], len(runs))
31-
for _, run := range runs {
32-
ids.Add(run.RepoID)
33-
}
34-
return ids.Values()
28+
return container.FilterSlice(runs, func(run *ActionRun) (int64, bool) {
29+
return run.RepoID, true
30+
})
3531
}
3632

3733
func (runs RunList) LoadTriggerUser(ctx context.Context) error {

models/actions/runner_list.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ type RunnerList []*ActionRunner
1616

1717
// GetUserIDs returns a slice of user's id
1818
func (runners RunnerList) GetUserIDs() []int64 {
19-
ids := make(container.Set[int64], len(runners))
20-
for _, runner := range runners {
21-
if runner.OwnerID == 0 {
22-
continue
23-
}
24-
ids.Add(runner.OwnerID)
25-
}
26-
return ids.Values()
19+
return container.FilterSlice(runners, func(runner *ActionRunner) (int64, bool) {
20+
return runner.OwnerID, runner.OwnerID != 0
21+
})
2722
}
2823

2924
func (runners RunnerList) LoadOwners(ctx context.Context) error {
@@ -41,16 +36,9 @@ func (runners RunnerList) LoadOwners(ctx context.Context) error {
4136
}
4237

4338
func (runners RunnerList) getRepoIDs() []int64 {
44-
repoIDs := make(container.Set[int64], len(runners))
45-
for _, runner := range runners {
46-
if runner.RepoID == 0 {
47-
continue
48-
}
49-
if _, ok := repoIDs[runner.RepoID]; !ok {
50-
repoIDs[runner.RepoID] = struct{}{}
51-
}
52-
}
53-
return repoIDs.Values()
39+
return container.FilterSlice(runners, func(runner *ActionRunner) (int64, bool) {
40+
return runner.RepoID, runner.RepoID > 0
41+
})
5442
}
5543

5644
func (runners RunnerList) LoadRepos(ctx context.Context) error {

models/actions/schedule_list.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,15 @@ type ScheduleList []*ActionSchedule
1818

1919
// GetUserIDs returns a slice of user's id
2020
func (schedules ScheduleList) GetUserIDs() []int64 {
21-
ids := make(container.Set[int64], len(schedules))
22-
for _, schedule := range schedules {
23-
ids.Add(schedule.TriggerUserID)
24-
}
25-
return ids.Values()
21+
return container.FilterSlice(schedules, func(schedule *ActionSchedule) (int64, bool) {
22+
return schedule.TriggerUserID, true
23+
})
2624
}
2725

2826
func (schedules ScheduleList) GetRepoIDs() []int64 {
29-
ids := make(container.Set[int64], len(schedules))
30-
for _, schedule := range schedules {
31-
ids.Add(schedule.RepoID)
32-
}
33-
return ids.Values()
27+
return container.FilterSlice(schedules, func(schedule *ActionSchedule) (int64, bool) {
28+
return schedule.RepoID, true
29+
})
3430
}
3531

3632
func (schedules ScheduleList) LoadTriggerUser(ctx context.Context) error {

models/actions/schedule_spec_list.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ import (
1616
type SpecList []*ActionScheduleSpec
1717

1818
func (specs SpecList) GetScheduleIDs() []int64 {
19-
ids := make(container.Set[int64], len(specs))
20-
for _, spec := range specs {
21-
ids.Add(spec.ScheduleID)
22-
}
23-
return ids.Values()
19+
return container.FilterSlice(specs, func(spec *ActionScheduleSpec) (int64, bool) {
20+
return spec.ScheduleID, true
21+
})
2422
}
2523

2624
func (specs SpecList) LoadSchedules(ctx context.Context) error {
@@ -46,11 +44,9 @@ func (specs SpecList) LoadSchedules(ctx context.Context) error {
4644
}
4745

4846
func (specs SpecList) GetRepoIDs() []int64 {
49-
ids := make(container.Set[int64], len(specs))
50-
for _, spec := range specs {
51-
ids.Add(spec.RepoID)
52-
}
53-
return ids.Values()
47+
return container.FilterSlice(specs, func(spec *ActionScheduleSpec) (int64, bool) {
48+
return spec.RepoID, true
49+
})
5450
}
5551

5652
func (specs SpecList) LoadRepos(ctx context.Context) error {

models/actions/task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
228228
if runner.RepoID != 0 {
229229
jobCond = builder.Eq{"repo_id": runner.RepoID}
230230
} else if runner.OwnerID != 0 {
231-
jobCond = builder.In("repo_id", builder.Select("id").From("repository").
231+
jobCond = builder.In("repo_id", builder.Select("`repository`.id").From("repository").
232232
Join("INNER", "repo_unit", "`repository`.id = `repo_unit`.repo_id").
233233
Where(builder.Eq{"`repository`.owner_id": runner.OwnerID, "`repo_unit`.type": unit.TypeActions}))
234234
}

models/actions/task_list.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ import (
1616
type TaskList []*ActionTask
1717

1818
func (tasks TaskList) GetJobIDs() []int64 {
19-
ids := make(container.Set[int64], len(tasks))
20-
for _, t := range tasks {
21-
if t.JobID == 0 {
22-
continue
23-
}
24-
ids.Add(t.JobID)
25-
}
26-
return ids.Values()
19+
return container.FilterSlice(tasks, func(t *ActionTask) (int64, bool) {
20+
return t.JobID, t.JobID != 0
21+
})
2722
}
2823

2924
func (tasks TaskList) LoadJobs(ctx context.Context) error {

models/activities/action_list.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ import (
2222
type ActionList []*Action
2323

2424
func (actions ActionList) getUserIDs() []int64 {
25-
userIDs := make(container.Set[int64], len(actions))
26-
for _, action := range actions {
27-
userIDs.Add(action.ActUserID)
28-
}
29-
return userIDs.Values()
25+
return container.FilterSlice(actions, func(action *Action) (int64, bool) {
26+
return action.ActUserID, true
27+
})
3028
}
3129

3230
func (actions ActionList) LoadActUsers(ctx context.Context) (map[int64]*user_model.User, error) {
@@ -50,11 +48,9 @@ func (actions ActionList) LoadActUsers(ctx context.Context) (map[int64]*user_mod
5048
}
5149

5250
func (actions ActionList) getRepoIDs() []int64 {
53-
repoIDs := make(container.Set[int64], len(actions))
54-
for _, action := range actions {
55-
repoIDs.Add(action.RepoID)
56-
}
57-
return repoIDs.Values()
51+
return container.FilterSlice(actions, func(action *Action) (int64, bool) {
52+
return action.RepoID, true
53+
})
5854
}
5955

6056
func (actions ActionList) LoadRepositories(ctx context.Context) error {
@@ -80,18 +76,16 @@ func (actions ActionList) loadRepoOwner(ctx context.Context, userMap map[int64]*
8076
userMap = make(map[int64]*user_model.User)
8177
}
8278

83-
userSet := make(container.Set[int64], len(actions))
84-
for _, action := range actions {
79+
missingUserIDs := container.FilterSlice(actions, func(action *Action) (int64, bool) {
8580
if action.Repo == nil {
86-
continue
81+
return 0, false
8782
}
88-
if _, ok := userMap[action.Repo.OwnerID]; !ok {
89-
userSet.Add(action.Repo.OwnerID)
90-
}
91-
}
83+
_, alreadyLoaded := userMap[action.Repo.OwnerID]
84+
return action.Repo.OwnerID, !alreadyLoaded
85+
})
9286

9387
if err := db.GetEngine(ctx).
94-
In("id", userSet.Values()).
88+
In("id", missingUserIDs).
9589
Find(&userMap); err != nil {
9690
return fmt.Errorf("find user: %w", err)
9791
}

models/activities/notification_list.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,12 @@ func (nl NotificationList) LoadAttributes(ctx context.Context) error {
190190
}
191191

192192
func (nl NotificationList) getPendingRepoIDs() []int64 {
193-
ids := make(container.Set[int64], len(nl))
194-
for _, notification := range nl {
195-
if notification.Repository != nil {
196-
continue
193+
return container.FilterSlice(nl, func(n *Notification) (int64, bool) {
194+
if n.Repository != nil {
195+
return 0, false
197196
}
198-
ids.Add(notification.RepoID)
199-
}
200-
return ids.Values()
197+
return n.RepoID, true
198+
})
201199
}
202200

203201
// LoadRepos loads repositories from database

models/git/branch_list.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@ import (
1717
type BranchList []*Branch
1818

1919
func (branches BranchList) LoadDeletedBy(ctx context.Context) error {
20-
ids := container.Set[int64]{}
21-
for _, branch := range branches {
22-
if !branch.IsDeleted {
23-
continue
24-
}
25-
ids.Add(branch.DeletedByID)
26-
}
20+
ids := container.FilterSlice(branches, func(branch *Branch) (int64, bool) {
21+
return branch.DeletedByID, branch.IsDeleted
22+
})
23+
2724
usersMap := make(map[int64]*user_model.User, len(ids))
28-
if err := db.GetEngine(ctx).In("id", ids.Values()).Find(&usersMap); err != nil {
25+
if err := db.GetEngine(ctx).In("id", ids).Find(&usersMap); err != nil {
2926
return err
3027
}
3128
for _, branch := range branches {
@@ -41,14 +38,13 @@ func (branches BranchList) LoadDeletedBy(ctx context.Context) error {
4138
}
4239

4340
func (branches BranchList) LoadPusher(ctx context.Context) error {
44-
ids := container.Set[int64]{}
45-
for _, branch := range branches {
46-
if branch.PusherID > 0 { // pusher_id maybe zero because some branches are sync by backend with no pusher
47-
ids.Add(branch.PusherID)
48-
}
49-
}
41+
ids := container.FilterSlice(branches, func(branch *Branch) (int64, bool) {
42+
// pusher_id maybe zero because some branches are sync by backend with no pusher
43+
return branch.PusherID, branch.PusherID > 0
44+
})
45+
5046
usersMap := make(map[int64]*user_model.User, len(ids))
51-
if err := db.GetEngine(ctx).In("id", ids.Values()).Find(&usersMap); err != nil {
47+
if err := db.GetEngine(ctx).In("id", ids).Find(&usersMap); err != nil {
5248
return err
5349
}
5450
for _, branch := range branches {

models/issues/comment.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,10 +1272,9 @@ func InsertIssueComments(ctx context.Context, comments []*Comment) error {
12721272
return nil
12731273
}
12741274

1275-
issueIDs := make(container.Set[int64])
1276-
for _, comment := range comments {
1277-
issueIDs.Add(comment.IssueID)
1278-
}
1275+
issueIDs := container.FilterSlice(comments, func(comment *Comment) (int64, bool) {
1276+
return comment.IssueID, true
1277+
})
12791278

12801279
ctx, committer, err := db.TxContext(ctx)
12811280
if err != nil {
@@ -1298,7 +1297,7 @@ func InsertIssueComments(ctx context.Context, comments []*Comment) error {
12981297
}
12991298
}
13001299

1301-
for issueID := range issueIDs {
1300+
for _, issueID := range issueIDs {
13021301
if _, err := db.Exec(ctx, "UPDATE issue set num_comments = (SELECT count(*) FROM comment WHERE issue_id = ? AND `type`=?) WHERE id = ?",
13031302
issueID, CommentTypeComment, issueID); err != nil {
13041303
return err

0 commit comments

Comments
 (0)