Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
zjjhot committed Apr 10, 2024
2 parents d5add2e + 6cac11c commit e1057cc
Show file tree
Hide file tree
Showing 29 changed files with 287 additions and 287 deletions.
35 changes: 22 additions & 13 deletions cmd/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,21 +448,24 @@ Gitea or set your environment appropriately.`, "")

func hookPrintResults(results []private.HookPostReceiveBranchResult) {
for _, res := range results {
if !res.Message {
continue
}
hookPrintResult(res.Message, res.Create, res.Branch, res.URL)
}
}

fmt.Fprintln(os.Stderr, "")
if res.Create {
fmt.Fprintf(os.Stderr, "Create a new pull request for '%s':\n", res.Branch)
fmt.Fprintf(os.Stderr, " %s\n", res.URL)
} else {
fmt.Fprint(os.Stderr, "Visit the existing pull request:\n")
fmt.Fprintf(os.Stderr, " %s\n", res.URL)
}
fmt.Fprintln(os.Stderr, "")
os.Stderr.Sync()
func hookPrintResult(output, isCreate bool, branch, url string) {
if !output {
return
}
fmt.Fprintln(os.Stderr, "")
if isCreate {
fmt.Fprintf(os.Stderr, "Create a new pull request for '%s':\n", branch)
fmt.Fprintf(os.Stderr, " %s\n", url)
} else {
fmt.Fprint(os.Stderr, "Visit the existing pull request:\n")
fmt.Fprintf(os.Stderr, " %s\n", url)
}
fmt.Fprintln(os.Stderr, "")
os.Stderr.Sync()
}

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

if err == nil {
for _, res := range resp.Results {
hookPrintResult(res.ShouldShowMessage, res.IsCreatePR, res.HeadBranch, res.URL)
}
}

return err
}

Expand Down
2 changes: 1 addition & 1 deletion docs/content/usage/actions/design.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ However, if a job container tries to fetch code from localhost, it will fail bec
### Connection 3, act runner to internet

When you use some actions like `actions/checkout@v4`, the act runner downloads the scripts, not the job containers.
By default, it downloads from [gitea.com](http://gitea.com/), so it requires access to the internet.
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.
It also downloads some docker images from Docker Hub by default, which also requires internet access.

However, internet access is not strictly necessary.
Expand Down
3 changes: 2 additions & 1 deletion docs/content/usage/actions/design.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ act runner 必须能够连接到Gitea以接收任务并发送执行结果回来
### 连接 3,act runner到互联网

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

然而,互联网访问并不是绝对必需的。
Expand Down
11 changes: 3 additions & 8 deletions models/actions/run_job_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ import (
type ActionJobList []*ActionRunJob

func (jobs ActionJobList) GetRunIDs() []int64 {
ids := make(container.Set[int64], len(jobs))
for _, j := range jobs {
if j.RunID == 0 {
continue
}
ids.Add(j.RunID)
}
return ids.Values()
return container.FilterSlice(jobs, func(j *ActionRunJob) (int64, bool) {
return j.RunID, j.RunID != 0
})
}

func (jobs ActionJobList) LoadRuns(ctx context.Context, withRepo bool) error {
Expand Down
16 changes: 6 additions & 10 deletions models/actions/run_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@ type RunList []*ActionRun

// GetUserIDs returns a slice of user's id
func (runs RunList) GetUserIDs() []int64 {
ids := make(container.Set[int64], len(runs))
for _, run := range runs {
ids.Add(run.TriggerUserID)
}
return ids.Values()
return container.FilterSlice(runs, func(run *ActionRun) (int64, bool) {
return run.TriggerUserID, true
})
}

func (runs RunList) GetRepoIDs() []int64 {
ids := make(container.Set[int64], len(runs))
for _, run := range runs {
ids.Add(run.RepoID)
}
return ids.Values()
return container.FilterSlice(runs, func(run *ActionRun) (int64, bool) {
return run.RepoID, true
})
}

func (runs RunList) LoadTriggerUser(ctx context.Context) error {
Expand Down
24 changes: 6 additions & 18 deletions models/actions/runner_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ type RunnerList []*ActionRunner

// GetUserIDs returns a slice of user's id
func (runners RunnerList) GetUserIDs() []int64 {
ids := make(container.Set[int64], len(runners))
for _, runner := range runners {
if runner.OwnerID == 0 {
continue
}
ids.Add(runner.OwnerID)
}
return ids.Values()
return container.FilterSlice(runners, func(runner *ActionRunner) (int64, bool) {
return runner.OwnerID, runner.OwnerID != 0
})
}

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

func (runners RunnerList) getRepoIDs() []int64 {
repoIDs := make(container.Set[int64], len(runners))
for _, runner := range runners {
if runner.RepoID == 0 {
continue
}
if _, ok := repoIDs[runner.RepoID]; !ok {
repoIDs[runner.RepoID] = struct{}{}
}
}
return repoIDs.Values()
return container.FilterSlice(runners, func(runner *ActionRunner) (int64, bool) {
return runner.RepoID, runner.RepoID > 0
})
}

func (runners RunnerList) LoadRepos(ctx context.Context) error {
Expand Down
16 changes: 6 additions & 10 deletions models/actions/schedule_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,15 @@ type ScheduleList []*ActionSchedule

// GetUserIDs returns a slice of user's id
func (schedules ScheduleList) GetUserIDs() []int64 {
ids := make(container.Set[int64], len(schedules))
for _, schedule := range schedules {
ids.Add(schedule.TriggerUserID)
}
return ids.Values()
return container.FilterSlice(schedules, func(schedule *ActionSchedule) (int64, bool) {
return schedule.TriggerUserID, true
})
}

func (schedules ScheduleList) GetRepoIDs() []int64 {
ids := make(container.Set[int64], len(schedules))
for _, schedule := range schedules {
ids.Add(schedule.RepoID)
}
return ids.Values()
return container.FilterSlice(schedules, func(schedule *ActionSchedule) (int64, bool) {
return schedule.RepoID, true
})
}

func (schedules ScheduleList) LoadTriggerUser(ctx context.Context) error {
Expand Down
16 changes: 6 additions & 10 deletions models/actions/schedule_spec_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ import (
type SpecList []*ActionScheduleSpec

func (specs SpecList) GetScheduleIDs() []int64 {
ids := make(container.Set[int64], len(specs))
for _, spec := range specs {
ids.Add(spec.ScheduleID)
}
return ids.Values()
return container.FilterSlice(specs, func(spec *ActionScheduleSpec) (int64, bool) {
return spec.ScheduleID, true
})
}

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

func (specs SpecList) GetRepoIDs() []int64 {
ids := make(container.Set[int64], len(specs))
for _, spec := range specs {
ids.Add(spec.RepoID)
}
return ids.Values()
return container.FilterSlice(specs, func(spec *ActionScheduleSpec) (int64, bool) {
return spec.RepoID, true
})
}

func (specs SpecList) LoadRepos(ctx context.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion models/actions/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
if runner.RepoID != 0 {
jobCond = builder.Eq{"repo_id": runner.RepoID}
} else if runner.OwnerID != 0 {
jobCond = builder.In("repo_id", builder.Select("id").From("repository").
jobCond = builder.In("repo_id", builder.Select("`repository`.id").From("repository").
Join("INNER", "repo_unit", "`repository`.id = `repo_unit`.repo_id").
Where(builder.Eq{"`repository`.owner_id": runner.OwnerID, "`repo_unit`.type": unit.TypeActions}))
}
Expand Down
11 changes: 3 additions & 8 deletions models/actions/task_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ import (
type TaskList []*ActionTask

func (tasks TaskList) GetJobIDs() []int64 {
ids := make(container.Set[int64], len(tasks))
for _, t := range tasks {
if t.JobID == 0 {
continue
}
ids.Add(t.JobID)
}
return ids.Values()
return container.FilterSlice(tasks, func(t *ActionTask) (int64, bool) {
return t.JobID, t.JobID != 0
})
}

func (tasks TaskList) LoadJobs(ctx context.Context) error {
Expand Down
30 changes: 12 additions & 18 deletions models/activities/action_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ import (
type ActionList []*Action

func (actions ActionList) getUserIDs() []int64 {
userIDs := make(container.Set[int64], len(actions))
for _, action := range actions {
userIDs.Add(action.ActUserID)
}
return userIDs.Values()
return container.FilterSlice(actions, func(action *Action) (int64, bool) {
return action.ActUserID, true
})
}

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

func (actions ActionList) getRepoIDs() []int64 {
repoIDs := make(container.Set[int64], len(actions))
for _, action := range actions {
repoIDs.Add(action.RepoID)
}
return repoIDs.Values()
return container.FilterSlice(actions, func(action *Action) (int64, bool) {
return action.RepoID, true
})
}

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

userSet := make(container.Set[int64], len(actions))
for _, action := range actions {
missingUserIDs := container.FilterSlice(actions, func(action *Action) (int64, bool) {
if action.Repo == nil {
continue
return 0, false
}
if _, ok := userMap[action.Repo.OwnerID]; !ok {
userSet.Add(action.Repo.OwnerID)
}
}
_, alreadyLoaded := userMap[action.Repo.OwnerID]
return action.Repo.OwnerID, !alreadyLoaded
})

if err := db.GetEngine(ctx).
In("id", userSet.Values()).
In("id", missingUserIDs).
Find(&userMap); err != nil {
return fmt.Errorf("find user: %w", err)
}
Expand Down
12 changes: 5 additions & 7 deletions models/activities/notification_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,12 @@ func (nl NotificationList) LoadAttributes(ctx context.Context) error {
}

func (nl NotificationList) getPendingRepoIDs() []int64 {
ids := make(container.Set[int64], len(nl))
for _, notification := range nl {
if notification.Repository != nil {
continue
return container.FilterSlice(nl, func(n *Notification) (int64, bool) {
if n.Repository != nil {
return 0, false
}
ids.Add(notification.RepoID)
}
return ids.Values()
return n.RepoID, true
})
}

// LoadRepos loads repositories from database
Expand Down
26 changes: 11 additions & 15 deletions models/git/branch_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ import (
type BranchList []*Branch

func (branches BranchList) LoadDeletedBy(ctx context.Context) error {
ids := container.Set[int64]{}
for _, branch := range branches {
if !branch.IsDeleted {
continue
}
ids.Add(branch.DeletedByID)
}
ids := container.FilterSlice(branches, func(branch *Branch) (int64, bool) {
return branch.DeletedByID, branch.IsDeleted
})

usersMap := make(map[int64]*user_model.User, len(ids))
if err := db.GetEngine(ctx).In("id", ids.Values()).Find(&usersMap); err != nil {
if err := db.GetEngine(ctx).In("id", ids).Find(&usersMap); err != nil {
return err
}
for _, branch := range branches {
Expand All @@ -41,14 +38,13 @@ func (branches BranchList) LoadDeletedBy(ctx context.Context) error {
}

func (branches BranchList) LoadPusher(ctx context.Context) error {
ids := container.Set[int64]{}
for _, branch := range branches {
if branch.PusherID > 0 { // pusher_id maybe zero because some branches are sync by backend with no pusher
ids.Add(branch.PusherID)
}
}
ids := container.FilterSlice(branches, func(branch *Branch) (int64, bool) {
// pusher_id maybe zero because some branches are sync by backend with no pusher
return branch.PusherID, branch.PusherID > 0
})

usersMap := make(map[int64]*user_model.User, len(ids))
if err := db.GetEngine(ctx).In("id", ids.Values()).Find(&usersMap); err != nil {
if err := db.GetEngine(ctx).In("id", ids).Find(&usersMap); err != nil {
return err
}
for _, branch := range branches {
Expand Down
9 changes: 4 additions & 5 deletions models/issues/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -1272,10 +1272,9 @@ func InsertIssueComments(ctx context.Context, comments []*Comment) error {
return nil
}

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

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

for issueID := range issueIDs {
for _, issueID := range issueIDs {
if _, err := db.Exec(ctx, "UPDATE issue set num_comments = (SELECT count(*) FROM comment WHERE issue_id = ? AND `type`=?) WHERE id = ?",
issueID, CommentTypeComment, issueID); err != nil {
return err
Expand Down
Loading

0 comments on commit e1057cc

Please sign in to comment.