1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Replace util.SliceXxx with slices.Xxx (#26958)

This commit is contained in:
CaiCandong
2023-09-07 17:37:47 +08:00
committed by GitHub
parent e97e883ad5
commit a78c2eae24
16 changed files with 46 additions and 110 deletions

View File

@@ -12,6 +12,7 @@ import (
"math/big"
"net/http"
"net/url"
"slices"
"sort"
"strconv"
"strings"
@@ -3628,7 +3629,7 @@ func issuePosters(ctx *context.Context, isPullList bool) {
if search == "" && ctx.Doer != nil {
// the returned posters slice only contains limited number of users,
// to make the current user (doer) can quickly filter their own issues, always add doer to the posters slice
if !util.SliceContainsFunc(posters, func(user *user_model.User) bool { return user.ID == ctx.Doer.ID }) {
if !slices.ContainsFunc(posters, func(user *user_model.User) bool { return user.ID == ctx.Doer.ID }) {
posters = append(posters, ctx.Doer)
}
}

View File

@@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"net/http"
"slices"
"strings"
"code.gitea.io/gitea/models"
@@ -659,7 +660,7 @@ func GetBranchesList(ctx *context.Context) {
}
resp := &branchTagSearchResponse{}
// always put default branch on the top if it exists
if util.SliceContains(branches, ctx.Repo.Repository.DefaultBranch) {
if slices.Contains(branches, ctx.Repo.Repository.DefaultBranch) {
branches = util.SliceRemoveAll(branches, ctx.Repo.Repository.DefaultBranch)
branches = append([]string{ctx.Repo.Repository.DefaultBranch}, branches...)
}
@@ -693,7 +694,7 @@ func PrepareBranchList(ctx *context.Context) {
return
}
// always put default branch on the top if it exists
if util.SliceContains(brs, ctx.Repo.Repository.DefaultBranch) {
if slices.Contains(brs, ctx.Repo.Repository.DefaultBranch) {
brs = util.SliceRemoveAll(brs, ctx.Repo.Repository.DefaultBranch)
brs = append([]string{ctx.Repo.Repository.DefaultBranch}, brs...)
}

View File

@@ -14,6 +14,7 @@ import (
"net/http"
"net/url"
"path"
"slices"
"strings"
"time"
@@ -370,7 +371,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
if workFlowErr != nil {
ctx.Data["FileError"] = ctx.Locale.Tr("actions.runs.invalid_workflow_helper", workFlowErr.Error())
}
} else if util.SliceContains([]string{"CODEOWNERS", "docs/CODEOWNERS", ".gitea/CODEOWNERS"}, ctx.Repo.TreePath) {
} else if slices.Contains([]string{"CODEOWNERS", "docs/CODEOWNERS", ".gitea/CODEOWNERS"}, ctx.Repo.TreePath) {
if data, err := blob.GetBlobContent(setting.UI.MaxDisplayFileSize); err == nil {
_, warnings := issue_model.GetCodeOwnersFromContent(ctx, data)
if len(warnings) > 0 {

View File

@@ -9,6 +9,7 @@ import (
"fmt"
"net/http"
"regexp"
"slices"
"sort"
"strconv"
"strings"
@@ -290,7 +291,7 @@ func Milestones(ctx *context.Context) {
if len(repoIDs) == 0 {
repoIDs = showRepoIds.Values()
}
repoIDs = util.SliceRemoveAllFunc(repoIDs, func(v int64) bool {
repoIDs = slices.DeleteFunc(repoIDs, func(v int64) bool {
return !showRepoIds.Contains(v)
})
@@ -534,7 +535,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
// Gets set when clicking filters on the issues overview page.
selectedRepoIDs := getRepoIDs(ctx.FormString("repos"))
// Remove repo IDs that are not accessible to the user.
selectedRepoIDs = util.SliceRemoveAllFunc(selectedRepoIDs, func(v int64) bool {
selectedRepoIDs = slices.DeleteFunc(selectedRepoIDs, func(v int64) bool {
return !accessibleRepos.Contains(v)
})
if len(selectedRepoIDs) > 0 {