From a78c2eae243077c1fed5f7b056c64072d3c63ac8 Mon Sep 17 00:00:00 2001 From: CaiCandong <50507092+CaiCandong@users.noreply.github.com> Date: Thu, 7 Sep 2023 17:37:47 +0800 Subject: Replace `util.SliceXxx` with `slices.Xxx` (#26958) --- models/actions/run.go | 3 ++- models/actions/run_job.go | 5 +++-- models/git/protected_branch.go | 3 ++- models/issues/issue.go | 5 +++-- models/repo/repo_unit.go | 3 ++- 5 files changed, 12 insertions(+), 7 deletions(-) (limited to 'models') diff --git a/models/actions/run.go b/models/actions/run.go index 18ed447e80..4853afc15b 100644 --- a/models/actions/run.go +++ b/models/actions/run.go @@ -6,6 +6,7 @@ package actions import ( "context" "fmt" + "slices" "strings" "time" @@ -350,7 +351,7 @@ func UpdateRun(ctx context.Context, run *ActionRun, cols ...string) error { // It's impossible that the run is not found, since Gitea never deletes runs. } - if run.Status != 0 || util.SliceContains(cols, "status") { + if run.Status != 0 || slices.Contains(cols, "status") { if run.RepoID == 0 { run, err = GetRunByID(ctx, run.ID) if err != nil { diff --git a/models/actions/run_job.go b/models/actions/run_job.go index 1da58bb659..4b8664077d 100644 --- a/models/actions/run_job.go +++ b/models/actions/run_job.go @@ -6,6 +6,7 @@ package actions import ( "context" "fmt" + "slices" "time" "code.gitea.io/gitea/models/db" @@ -107,11 +108,11 @@ func UpdateRunJob(ctx context.Context, job *ActionRunJob, cond builder.Cond, col return 0, err } - if affected == 0 || (!util.SliceContains(cols, "status") && job.Status == 0) { + if affected == 0 || (!slices.Contains(cols, "status") && job.Status == 0) { return affected, nil } - if affected != 0 && util.SliceContains(cols, "status") && job.Status.IsWaiting() { + if affected != 0 && slices.Contains(cols, "status") && job.Status.IsWaiting() { // if the status of job changes to waiting again, increase tasks version. if err := IncreaseTaskVersion(ctx, job.OwnerID, job.RepoID); err != nil { return 0, err diff --git a/models/git/protected_branch.go b/models/git/protected_branch.go index eef7e3935a..5ed1003749 100644 --- a/models/git/protected_branch.go +++ b/models/git/protected_branch.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "slices" "strings" "code.gitea.io/gitea/models/db" @@ -435,7 +436,7 @@ func updateTeamWhitelist(ctx context.Context, repo *repo_model.Repository, curre whitelist = make([]int64, 0, len(teams)) for i := range teams { - if util.SliceContains(newWhitelist, teams[i].ID) { + if slices.Contains(newWhitelist, teams[i].ID) { whitelist = append(whitelist, teams[i].ID) } } diff --git a/models/issues/issue.go b/models/issues/issue.go index f000f4c660..8f59c9cb42 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -8,6 +8,7 @@ import ( "context" "fmt" "regexp" + "slices" "code.gitea.io/gitea/models/db" project_model "code.gitea.io/gitea/models/project" @@ -605,7 +606,7 @@ func IsUserParticipantsOfIssue(user *user_model.User, issue *Issue) bool { log.Error(err.Error()) return false } - return util.SliceContains(userIDs, user.ID) + return slices.Contains(userIDs, user.ID) } // DependencyInfo represents high level information about an issue which is a dependency of another issue. @@ -630,7 +631,7 @@ func (issue *Issue) GetParticipantIDsByIssue(ctx context.Context) ([]int64, erro Find(&userIDs); err != nil { return nil, fmt.Errorf("get poster IDs: %w", err) } - if !util.SliceContains(userIDs, issue.PosterID) { + if !slices.Contains(userIDs, issue.PosterID) { return append(userIDs, issue.PosterID), nil } return userIDs, nil diff --git a/models/repo/repo_unit.go b/models/repo/repo_unit.go index cf9ff93d32..b8804c6df1 100644 --- a/models/repo/repo_unit.go +++ b/models/repo/repo_unit.go @@ -6,6 +6,7 @@ package repo import ( "context" "fmt" + "slices" "strings" "code.gitea.io/gitea/models/db" @@ -176,7 +177,7 @@ func (cfg *ActionsConfig) ToString() string { } func (cfg *ActionsConfig) IsWorkflowDisabled(file string) bool { - return util.SliceContains(cfg.DisabledWorkflows, file) + return slices.Contains(cfg.DisabledWorkflows, file) } func (cfg *ActionsConfig) DisableWorkflow(file string) { -- cgit v1.2.3