mirror of
https://github.com/go-gitea/gitea
synced 2025-07-31 22:58:35 +00:00
Run gopls modernize
on codebase (#34751)
Recent modernize fixes: https://github.com/golang/tools/commits/master/gopls/internal/analysis/modernize
This commit is contained in:
@@ -177,7 +177,7 @@ func parseOAuth2Config(form forms.AuthenticationForm) *oauth2.Source {
|
||||
customURLMapping = nil
|
||||
}
|
||||
var scopes []string
|
||||
for _, s := range strings.Split(form.Oauth2Scopes, ",") {
|
||||
for s := range strings.SplitSeq(form.Oauth2Scopes, ",") {
|
||||
s = strings.TrimSpace(s)
|
||||
if s != "" {
|
||||
scopes = append(scopes, s)
|
||||
|
@@ -61,7 +61,7 @@ func TestCache(ctx *context.Context) {
|
||||
|
||||
func shadowPasswordKV(cfgItem, splitter string) string {
|
||||
fields := strings.Split(cfgItem, splitter)
|
||||
for i := 0; i < len(fields); i++ {
|
||||
for i := range fields {
|
||||
if strings.HasPrefix(fields[i], "password=") {
|
||||
fields[i] = "password=******"
|
||||
break
|
||||
|
@@ -16,13 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func MonitorDiagnosis(ctx *context.Context) {
|
||||
seconds := ctx.FormInt64("seconds")
|
||||
if seconds <= 1 {
|
||||
seconds = 1
|
||||
}
|
||||
if seconds > 300 {
|
||||
seconds = 300
|
||||
}
|
||||
seconds := min(max(ctx.FormInt64("seconds"), 1), 300)
|
||||
|
||||
httplib.ServeSetHeaders(ctx.Resp, &httplib.ServeHeaderOptions{
|
||||
ContentType: "application/zip",
|
||||
|
@@ -26,10 +26,7 @@ func Notices(ctx *context.Context) {
|
||||
ctx.Data["PageIsAdminNotices"] = true
|
||||
|
||||
total := system_model.CountNotices(ctx)
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
|
||||
notices, err := system_model.Notices(ctx, page, setting.UI.Admin.NoticePagingNum)
|
||||
if err != nil {
|
||||
|
@@ -24,10 +24,7 @@ const (
|
||||
|
||||
// Packages shows all packages
|
||||
func Packages(ctx *context.Context) {
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
query := ctx.FormTrim("q")
|
||||
packageType := ctx.FormTrim("type")
|
||||
sort := ctx.FormTrim("sort")
|
||||
|
@@ -349,10 +349,7 @@ func RegisterOpenIDPost(ctx *context.Context) {
|
||||
context.VerifyCaptcha(ctx, tplSignUpOID, form)
|
||||
}
|
||||
|
||||
length := setting.MinPasswordLength
|
||||
if length < 256 {
|
||||
length = 256
|
||||
}
|
||||
length := max(setting.MinPasswordLength, 256)
|
||||
password, err := util.CryptoRandomString(int64(length))
|
||||
if err != nil {
|
||||
ctx.RenderWithErr(err.Error(), tplSignUpOID, form)
|
||||
|
@@ -132,7 +132,7 @@ func prepareMockDataBadgeActionsSvg(ctx *context.Context) {
|
||||
selectedStyle := ctx.FormString("style", badge.DefaultStyle)
|
||||
var badges []badge.Badge
|
||||
badges = append(badges, badge.GenerateBadge("啊啊啊啊啊啊啊啊啊啊啊啊", "🌞🌞🌞🌞🌞", "green"))
|
||||
for r := rune(0); r < 256; r++ {
|
||||
for r := range rune(256) {
|
||||
if unicode.IsPrint(r) {
|
||||
s := strings.Repeat(string(r), 15)
|
||||
badges = append(badges, badge.GenerateBadge(s, util.TruncateRunes(s, 7), "green"))
|
||||
|
@@ -5,6 +5,7 @@ package explore
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"slices"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
@@ -94,11 +95,8 @@ func Code(ctx *context.Context) {
|
||||
loadRepoIDs := make([]int64, 0, len(searchResults))
|
||||
for _, result := range searchResults {
|
||||
var find bool
|
||||
for _, id := range loadRepoIDs {
|
||||
if id == result.RepoID {
|
||||
find = true
|
||||
break
|
||||
}
|
||||
if slices.Contains(loadRepoIDs, result.RepoID) {
|
||||
find = true
|
||||
}
|
||||
if !find {
|
||||
loadRepoIDs = append(loadRepoIDs, result.RepoID)
|
||||
|
@@ -28,10 +28,7 @@ func Members(ctx *context.Context) {
|
||||
ctx.Data["Title"] = org.FullName
|
||||
ctx.Data["PageIsOrgMembers"] = true
|
||||
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
|
||||
opts := &organization.FindOrgMembersOpts{
|
||||
Doer: ctx.Doer,
|
||||
|
@@ -53,10 +53,7 @@ func Projects(ctx *context.Context) {
|
||||
|
||||
isShowClosed := strings.ToLower(ctx.FormTrim("state")) == "closed"
|
||||
keyword := ctx.FormTrim("q")
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
|
||||
var projectType project_model.Type
|
||||
if ctx.ContextUser.IsOrganization() {
|
||||
|
@@ -377,10 +377,8 @@ func workflowDispatchConfig(w *model.Workflow) *WorkflowDispatch {
|
||||
if !decodeNode(w.RawOn, &val) {
|
||||
return nil
|
||||
}
|
||||
for _, v := range val {
|
||||
if v == "workflow_dispatch" {
|
||||
return &WorkflowDispatch{}
|
||||
}
|
||||
if slices.Contains(val, "workflow_dispatch") {
|
||||
return &WorkflowDispatch{}
|
||||
}
|
||||
case yaml.MappingNode:
|
||||
var val map[string]yaml.Node
|
||||
|
@@ -45,10 +45,7 @@ func Branches(ctx *context.Context) {
|
||||
ctx.Data["PageIsViewCode"] = true
|
||||
ctx.Data["PageIsBranches"] = true
|
||||
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
pageSize := setting.Git.BranchesRangeSize
|
||||
|
||||
kw := ctx.FormString("q")
|
||||
|
@@ -67,10 +67,7 @@ func Commits(ctx *context.Context) {
|
||||
|
||||
commitsCount := ctx.Repo.CommitsCount
|
||||
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
|
||||
pageSize := ctx.FormInt("limit")
|
||||
if pageSize <= 0 {
|
||||
@@ -230,10 +227,7 @@ func FileHistory(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
|
||||
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(
|
||||
git.CommitsByFileAndRangeOptions{
|
||||
|
@@ -817,7 +817,7 @@ func cleanUploadFileName(name string) string {
|
||||
// Rebase the filename
|
||||
name = util.PathJoinRel(name)
|
||||
// Git disallows any filenames to have a .git directory in them.
|
||||
for _, part := range strings.Split(name, "/") {
|
||||
for part := range strings.SplitSeq(name, "/") {
|
||||
if strings.ToLower(part) == ".git" {
|
||||
return ""
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -363,12 +364,7 @@ func containsParentDirectorySeparator(v string) bool {
|
||||
if !strings.Contains(v, "..") {
|
||||
return false
|
||||
}
|
||||
for _, ent := range strings.FieldsFunc(v, isSlashRune) {
|
||||
if ent == ".." {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(strings.FieldsFunc(v, isSlashRune), "..")
|
||||
}
|
||||
|
||||
func isSlashRune(r rune) bool { return r == '/' || r == '\\' }
|
||||
|
@@ -212,7 +212,7 @@ func getActionIssues(ctx *context.Context) issues_model.IssueList {
|
||||
return nil
|
||||
}
|
||||
issueIDs := make([]int64, 0, 10)
|
||||
for _, stringIssueID := range strings.Split(commaSeparatedIssueIDs, ",") {
|
||||
for stringIssueID := range strings.SplitSeq(commaSeparatedIssueIDs, ",") {
|
||||
issueID, err := strconv.ParseInt(stringIssueID, 10, 64)
|
||||
if err != nil {
|
||||
ctx.ServerError("ParseInt", err)
|
||||
|
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"maps"
|
||||
"net/http"
|
||||
"slices"
|
||||
"sort"
|
||||
@@ -136,9 +137,7 @@ func NewIssue(ctx *context.Context) {
|
||||
|
||||
ret := issue_service.ParseTemplatesFromDefaultBranch(ctx.Repo.Repository, ctx.Repo.GitRepo)
|
||||
templateLoaded, errs := setTemplateIfExists(ctx, issueTemplateKey, IssueTemplateCandidates, pageMetaData)
|
||||
for k, v := range errs {
|
||||
ret.TemplateErrors[k] = v
|
||||
}
|
||||
maps.Copy(ret.TemplateErrors, errs)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
@@ -38,10 +38,7 @@ func Milestones(ctx *context.Context) {
|
||||
isShowClosed := ctx.FormString("state") == "closed"
|
||||
sortType := ctx.FormString("sort")
|
||||
keyword := ctx.FormTrim("q")
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
|
||||
miles, total, err := db.FindAndCount[issues_model.Milestone](ctx, issues_model.FindMilestoneOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
|
@@ -21,10 +21,7 @@ const (
|
||||
|
||||
// Packages displays a list of all packages in the repository
|
||||
func Packages(ctx *context.Context) {
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
query := ctx.FormTrim("q")
|
||||
packageType := ctx.FormTrim("type")
|
||||
|
||||
|
@@ -61,10 +61,7 @@ func Projects(ctx *context.Context) {
|
||||
isShowClosed := strings.ToLower(ctx.FormTrim("state")) == "closed"
|
||||
keyword := ctx.FormTrim("q")
|
||||
repo := ctx.Repo.Repository
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
|
||||
ctx.Data["OpenCount"] = repo.NumOpenProjects
|
||||
ctx.Data["ClosedCount"] = repo.NumClosedProjects
|
||||
|
@@ -88,7 +88,7 @@ func checkContextUser(ctx *context.Context, uid int64) *user_model.User {
|
||||
}
|
||||
|
||||
var orgsAvailable []*organization.Organization
|
||||
for i := 0; i < len(orgs); i++ {
|
||||
for i := range orgs {
|
||||
if ctx.Doer.CanCreateRepoIn(orgs[i].AsUser()) {
|
||||
orgsAvailable = append(orgsAvailable, orgs[i])
|
||||
}
|
||||
|
@@ -45,10 +45,7 @@ func LFSFiles(ctx *context.Context) {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
}
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
total, err := git_model.CountLFSMetaObjects(ctx, ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("LFSFiles", err)
|
||||
@@ -77,10 +74,7 @@ func LFSLocks(ctx *context.Context) {
|
||||
}
|
||||
ctx.Data["LFSFilesLink"] = ctx.Repo.RepoLink + "/settings/lfs"
|
||||
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
total, err := git_model.CountLFSLockByRepoID(ctx, ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("LFSLocks", err)
|
||||
|
@@ -417,10 +417,7 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
|
||||
ctx.Data["CommitCount"] = commitsCount
|
||||
|
||||
// get page
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
|
||||
// get Commit Count
|
||||
commitsHistory, err := wikiRepo.CommitsByFileAndRange(
|
||||
|
@@ -108,10 +108,7 @@ func Runners(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
|
||||
opts := actions_model.FindRunnerOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
@@ -179,10 +176,7 @@ func RunnersEdit(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
|
||||
runnerID := ctx.PathParamInt64("runnerid")
|
||||
ownerID := rCtx.OwnerID
|
||||
|
@@ -5,6 +5,7 @@ package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"slices"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
@@ -87,11 +88,8 @@ func CodeSearch(ctx *context.Context) {
|
||||
loadRepoIDs := make([]int64, 0, len(searchResults))
|
||||
for _, result := range searchResults {
|
||||
var find bool
|
||||
for _, id := range loadRepoIDs {
|
||||
if id == result.RepoID {
|
||||
find = true
|
||||
break
|
||||
}
|
||||
if slices.Contains(loadRepoIDs, result.RepoID) {
|
||||
find = true
|
||||
}
|
||||
if !find {
|
||||
loadRepoIDs = append(loadRepoIDs, result.RepoID)
|
||||
|
@@ -197,7 +197,7 @@ func Milestones(ctx *context.Context) {
|
||||
reposQuery = reposQuery[1 : len(reposQuery)-1]
|
||||
// for each ID (delimiter ",") add to int to repoIDs
|
||||
|
||||
for _, rID := range strings.Split(reposQuery, ",") {
|
||||
for rID := range strings.SplitSeq(reposQuery, ",") {
|
||||
// Ensure nonempty string entries
|
||||
if rID != "" && rID != "0" {
|
||||
rIDint64, err := strconv.ParseInt(rID, 10, 64)
|
||||
@@ -520,10 +520,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
|
||||
opts.IsClosed = optional.Some(isShowClosed)
|
||||
|
||||
// Make sure page number is at least 1. Will be posted to ctx.Data.
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
opts.Paginator = &db.ListOptions{
|
||||
Page: page,
|
||||
PageSize: setting.UI.IssuePagingNum,
|
||||
|
@@ -203,10 +203,7 @@ func NotificationPurgePost(ctx *context.Context) {
|
||||
|
||||
// NotificationSubscriptions returns the list of subscribed issues
|
||||
func NotificationSubscriptions(ctx *context.Context) {
|
||||
page := ctx.FormInt("page")
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
|
||||
sortType := ctx.FormString("sort")
|
||||
ctx.Data["SortType"] = sortType
|
||||
@@ -331,10 +328,7 @@ func NotificationSubscriptions(ctx *context.Context) {
|
||||
|
||||
// NotificationWatching returns the list of watching repos
|
||||
func NotificationWatching(ctx *context.Context) {
|
||||
page := ctx.FormInt("page")
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
|
||||
keyword := ctx.FormTrim("q")
|
||||
ctx.Data["Keyword"] = keyword
|
||||
|
@@ -46,10 +46,7 @@ func ListPackages(ctx *context.Context) {
|
||||
ctx.ServerError("RenderUserOrgHeader", err)
|
||||
return
|
||||
}
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
query := ctx.FormTrim("q")
|
||||
packageType := ctx.FormTrim("type")
|
||||
|
||||
@@ -320,10 +317,7 @@ func ListPackageVersions(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
page := ctx.FormInt("page")
|
||||
if page <= 1 {
|
||||
page = 1
|
||||
}
|
||||
page := max(ctx.FormInt("page"), 1)
|
||||
pagination := &db.ListOptions{
|
||||
PageSize: setting.UI.PackagesPagingNum,
|
||||
Page: page,
|
||||
|
Reference in New Issue
Block a user