Skip to content

Commit 1f35435

Browse files
authored
1 parent 71e4740 commit 1f35435

File tree

190 files changed

+369
-696
lines changed

Some content is hidden

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

190 files changed

+369
-696
lines changed

cmd/cert.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ func runCert(_ context.Context, c *cli.Command) error {
156156
BasicConstraintsValid: true,
157157
}
158158

159-
hosts := strings.Split(c.String("host"), ",")
160-
for _, h := range hosts {
159+
hosts := strings.SplitSeq(c.String("host"), ",")
160+
for h := range hosts {
161161
if ip := net.ParseIP(h); ip != nil {
162162
template.IPAddresses = append(template.IPAddresses, ip)
163163
} else {

cmd/dump_repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ func runDumpRepository(ctx context.Context, cmd *cli.Command) error {
137137
opts.PullRequests = true
138138
opts.ReleaseAssets = true
139139
} else {
140-
units := strings.Split(cmd.String("units"), ",")
141-
for _, unit := range units {
140+
units := strings.SplitSeq(cmd.String("units"), ",")
141+
for unit := range units {
142142
switch strings.ToLower(strings.TrimSpace(unit)) {
143143
case "":
144144
continue

cmd/hook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ func hookPrintResult(output, isCreate bool, branch, url string) {
480480
func pushOptions() map[string]string {
481481
opts := make(map[string]string)
482482
if pushCount, err := strconv.Atoi(os.Getenv(private.GitPushOptionCount)); err == nil {
483-
for idx := 0; idx < pushCount; idx++ {
483+
for idx := range pushCount {
484484
opt := os.Getenv(fmt.Sprintf("GIT_PUSH_OPTION_%d", idx))
485485
kv := strings.SplitN(opt, "=", 2)
486486
if len(kv) == 2 {
@@ -732,7 +732,7 @@ func readPktLine(ctx context.Context, in *bufio.Reader, requestType pktLineType)
732732

733733
// read prefix
734734
lengthBytes := make([]byte, 4)
735-
for i := 0; i < 4; i++ {
735+
for i := range 4 {
736736
lengthBytes[i], err = in.ReadByte()
737737
if err != nil {
738738
return nil, fail(ctx, "Protocol: stdin error", "Pkt-Line: read stdin failed : %v", err)

contrib/backport/backport.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ func determineRemote(ctx context.Context, forkUser string) (string, string, erro
337337
fmt.Fprintf(os.Stderr, "Unable to list git remotes:\n%s\n", string(out))
338338
return "", "", fmt.Errorf("unable to determine forked remote: %w", err)
339339
}
340-
lines := strings.Split(string(out), "\n")
341-
for _, line := range lines {
340+
lines := strings.SplitSeq(string(out), "\n")
341+
for line := range lines {
342342
fields := strings.Split(line, "\t")
343343
name, remote := fields[0], fields[1]
344344
// only look at pushers
@@ -356,12 +356,12 @@ func determineRemote(ctx context.Context, forkUser string) (string, string, erro
356356
if !strings.Contains(remote, forkUser) {
357357
continue
358358
}
359-
if strings.HasPrefix(remote, "git@github.com:") {
360-
forkUser = strings.TrimPrefix(remote, "git@github.com:")
361-
} else if strings.HasPrefix(remote, "https://github.com/") {
362-
forkUser = strings.TrimPrefix(remote, "https://github.com/")
363-
} else if strings.HasPrefix(remote, "https://www.github.com/") {
364-
forkUser = strings.TrimPrefix(remote, "https://www.github.com/")
359+
if after, ok := strings.CutPrefix(remote, "git@github.com:"); ok {
360+
forkUser = after
361+
} else if after, ok := strings.CutPrefix(remote, "https://github.com/"); ok {
362+
forkUser = after
363+
} else if after, ok := strings.CutPrefix(remote, "https://www.github.com/"); ok {
364+
forkUser = after
365365
} else if forkUser == "" {
366366
return "", "", fmt.Errorf("unable to extract forkUser from remote %s: %s", name, remote)
367367
}

models/actions/status.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package actions
55

66
import (
7+
"slices"
8+
79
"code.gitea.io/gitea/modules/translation"
810

911
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
@@ -88,12 +90,7 @@ func (s Status) IsBlocked() bool {
8890

8991
// In returns whether s is one of the given statuses
9092
func (s Status) In(statuses ...Status) bool {
91-
for _, v := range statuses {
92-
if s == v {
93-
return true
94-
}
95-
}
96-
return false
93+
return slices.Contains(statuses, s)
9794
}
9895

9996
func (s Status) AsResult() runnerv1.Result {

models/activities/action.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"net/url"
1111
"path"
12+
"slices"
1213
"strconv"
1314
"strings"
1415
"time"
@@ -125,12 +126,7 @@ func (at ActionType) String() string {
125126
}
126127

127128
func (at ActionType) InActions(actions ...string) bool {
128-
for _, action := range actions {
129-
if action == at.String() {
130-
return true
131-
}
132-
}
133-
return false
129+
return slices.Contains(actions, at.String())
134130
}
135131

136132
// Action represents user operation type and other information to

models/activities/notification_list.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,7 @@ func (nl NotificationList) LoadRepos(ctx context.Context) (repo_model.Repository
208208
repos := make(map[int64]*repo_model.Repository, len(repoIDs))
209209
left := len(repoIDs)
210210
for left > 0 {
211-
limit := db.DefaultMaxInSize
212-
if left < limit {
213-
limit = left
214-
}
211+
limit := min(left, db.DefaultMaxInSize)
215212
rows, err := db.GetEngine(ctx).
216213
In("id", repoIDs[:limit]).
217214
Rows(new(repo_model.Repository))
@@ -282,10 +279,7 @@ func (nl NotificationList) LoadIssues(ctx context.Context) ([]int, error) {
282279
issues := make(map[int64]*issues_model.Issue, len(issueIDs))
283280
left := len(issueIDs)
284281
for left > 0 {
285-
limit := db.DefaultMaxInSize
286-
if left < limit {
287-
limit = left
288-
}
282+
limit := min(left, db.DefaultMaxInSize)
289283
rows, err := db.GetEngine(ctx).
290284
In("id", issueIDs[:limit]).
291285
Rows(new(issues_model.Issue))
@@ -377,10 +371,7 @@ func (nl NotificationList) LoadUsers(ctx context.Context) ([]int, error) {
377371
users := make(map[int64]*user_model.User, len(userIDs))
378372
left := len(userIDs)
379373
for left > 0 {
380-
limit := db.DefaultMaxInSize
381-
if left < limit {
382-
limit = left
383-
}
374+
limit := min(left, db.DefaultMaxInSize)
384375
rows, err := db.GetEngine(ctx).
385376
In("id", userIDs[:limit]).
386377
Rows(new(user_model.User))
@@ -428,10 +419,7 @@ func (nl NotificationList) LoadComments(ctx context.Context) ([]int, error) {
428419
comments := make(map[int64]*issues_model.Comment, len(commentIDs))
429420
left := len(commentIDs)
430421
for left > 0 {
431-
limit := db.DefaultMaxInSize
432-
if left < limit {
433-
limit = left
434-
}
422+
limit := min(left, db.DefaultMaxInSize)
435423
rows, err := db.GetEngine(ctx).
436424
In("id", commentIDs[:limit]).
437425
Rows(new(issues_model.Comment))

models/activities/repo_activity.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,7 @@ func GetActivityStatsTopAuthors(ctx context.Context, repo *repo_model.Repository
139139
return v[i].Commits > v[j].Commits
140140
})
141141

142-
cnt := count
143-
if cnt > len(v) {
144-
cnt = len(v)
145-
}
142+
cnt := min(count, len(v))
146143

147144
return v[:cnt], nil
148145
}

models/auth/access_token_scope.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,7 @@ func GetRequiredScopes(level AccessTokenScopeLevel, scopeCategories ...AccessTok
213213

214214
// ContainsCategory checks if a list of categories contains a specific category
215215
func ContainsCategory(categories []AccessTokenScopeCategory, category AccessTokenScopeCategory) bool {
216-
for _, c := range categories {
217-
if c == category {
218-
return true
219-
}
220-
}
221-
return false
216+
return slices.Contains(categories, category)
222217
}
223218

224219
// GetScopeLevelFromAccessMode converts permission access mode to scope level

models/auth/oauth2.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"fmt"
1313
"net"
1414
"net/url"
15+
"slices"
1516
"strings"
1617

1718
"code.gitea.io/gitea/models/db"
@@ -511,12 +512,7 @@ func (grant *OAuth2Grant) IncreaseCounter(ctx context.Context) error {
511512

512513
// ScopeContains returns true if the grant scope contains the specified scope
513514
func (grant *OAuth2Grant) ScopeContains(scope string) bool {
514-
for _, currentScope := range strings.Split(grant.Scope, " ") {
515-
if scope == currentScope {
516-
return true
517-
}
518-
}
519-
return false
515+
return slices.Contains(strings.Split(grant.Scope, " "), scope)
520516
}
521517

522518
// SetNonce updates the current nonce value of a grant

0 commit comments

Comments
 (0)