mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
enable staticcheck QFxxxx rules (#34064)
This commit is contained in:
@@ -162,8 +162,8 @@ func (r artifactV4Routes) buildSignature(endp, expires, artifactName string, tas
|
||||
mac.Write([]byte(endp))
|
||||
mac.Write([]byte(expires))
|
||||
mac.Write([]byte(artifactName))
|
||||
mac.Write([]byte(fmt.Sprint(taskID)))
|
||||
mac.Write([]byte(fmt.Sprint(artifactID)))
|
||||
fmt.Fprint(mac, taskID)
|
||||
fmt.Fprint(mac, artifactID)
|
||||
return mac.Sum(nil)
|
||||
}
|
||||
|
||||
|
@@ -46,13 +46,14 @@ func reqPackageAccess(accessMode perm.AccessMode) func(ctx *context.Context) {
|
||||
if ok { // it's a personal access token but not oauth2 token
|
||||
scopeMatched := false
|
||||
var err error
|
||||
if accessMode == perm.AccessModeRead {
|
||||
switch accessMode {
|
||||
case perm.AccessModeRead:
|
||||
scopeMatched, err = scope.HasScope(auth_model.AccessTokenScopeReadPackage)
|
||||
if err != nil {
|
||||
ctx.HTTPError(http.StatusInternalServerError, "HasScope", err.Error())
|
||||
return
|
||||
}
|
||||
} else if accessMode == perm.AccessModeWrite {
|
||||
case perm.AccessModeWrite:
|
||||
scopeMatched, err = scope.HasScope(auth_model.AccessTokenScopeWritePackage)
|
||||
if err != nil {
|
||||
ctx.HTTPError(http.StatusInternalServerError, "HasScope", err.Error())
|
||||
@@ -703,13 +704,14 @@ func ContainerRoutes() *web.Router {
|
||||
g.MatchPath("POST", "/<image:*>/blobs/uploads", reqPackageAccess(perm.AccessModeWrite), container.VerifyImageName, container.InitiateUploadBlob)
|
||||
g.MatchPath("GET", "/<image:*>/tags/list", container.VerifyImageName, container.GetTagList)
|
||||
g.MatchPath("GET,PATCH,PUT,DELETE", `/<image:*>/blobs/uploads/<uuid:[-.=\w]+>`, reqPackageAccess(perm.AccessModeWrite), container.VerifyImageName, func(ctx *context.Context) {
|
||||
if ctx.Req.Method == http.MethodGet {
|
||||
switch ctx.Req.Method {
|
||||
case http.MethodGet:
|
||||
container.GetUploadBlob(ctx)
|
||||
} else if ctx.Req.Method == http.MethodPatch {
|
||||
case http.MethodPatch:
|
||||
container.UploadBlob(ctx)
|
||||
} else if ctx.Req.Method == http.MethodPut {
|
||||
case http.MethodPut:
|
||||
container.EndUploadBlob(ctx)
|
||||
} else /* DELETE */ {
|
||||
default: /* DELETE */
|
||||
container.CancelUploadBlob(ctx)
|
||||
}
|
||||
})
|
||||
|
@@ -51,9 +51,10 @@ func ListHooks(ctx *context.APIContext) {
|
||||
// for compatibility the default value is true
|
||||
isSystemWebhook := optional.Some(true)
|
||||
typeValue := ctx.FormString("type")
|
||||
if typeValue == "default" {
|
||||
switch typeValue {
|
||||
case "default":
|
||||
isSystemWebhook = optional.Some(false)
|
||||
} else if typeValue == "all" {
|
||||
case "all":
|
||||
isSystemWebhook = optional.None[bool]()
|
||||
}
|
||||
|
||||
|
@@ -842,13 +842,13 @@ func verifyAuthWithOptions(options *common.VerifyOptions) func(ctx *context.APIC
|
||||
func individualPermsChecker(ctx *context.APIContext) {
|
||||
// org permissions have been checked in context.OrgAssignment(), but individual permissions haven't been checked.
|
||||
if ctx.ContextUser.IsIndividual() {
|
||||
switch {
|
||||
case ctx.ContextUser.Visibility == api.VisibleTypePrivate:
|
||||
switch ctx.ContextUser.Visibility {
|
||||
case api.VisibleTypePrivate:
|
||||
if ctx.Doer == nil || (ctx.ContextUser.ID != ctx.Doer.ID && !ctx.Doer.IsAdmin) {
|
||||
ctx.APIErrorNotFound("Visit Project", nil)
|
||||
return
|
||||
}
|
||||
case ctx.ContextUser.Visibility == api.VisibleTypeLimited:
|
||||
case api.VisibleTypeLimited:
|
||||
if ctx.Doer == nil {
|
||||
ctx.APIErrorNotFound("Visit Project", nil)
|
||||
return
|
||||
|
@@ -1103,8 +1103,8 @@ func DeleteArtifact(ctx *context.APIContext) {
|
||||
func buildSignature(endp string, expires, artifactID int64) []byte {
|
||||
mac := hmac.New(sha256.New, setting.GetGeneralTokenSigningSecret())
|
||||
mac.Write([]byte(endp))
|
||||
mac.Write([]byte(fmt.Sprint(expires)))
|
||||
mac.Write([]byte(fmt.Sprint(artifactID)))
|
||||
fmt.Fprint(mac, expires)
|
||||
fmt.Fprint(mac, artifactID)
|
||||
return mac.Sum(nil)
|
||||
}
|
||||
|
||||
|
@@ -24,9 +24,10 @@ import (
|
||||
|
||||
// appendPrivateInformation appends the owner and key type information to api.PublicKey
|
||||
func appendPrivateInformation(ctx std_ctx.Context, apiKey *api.PublicKey, key *asymkey_model.PublicKey, defaultUser *user_model.User) (*api.PublicKey, error) {
|
||||
if key.Type == asymkey_model.KeyTypeDeploy {
|
||||
switch key.Type {
|
||||
case asymkey_model.KeyTypeDeploy:
|
||||
apiKey.KeyType = "deploy"
|
||||
} else if key.Type == asymkey_model.KeyTypeUser {
|
||||
case asymkey_model.KeyTypeUser:
|
||||
apiKey.KeyType = "user"
|
||||
|
||||
if defaultUser.ID == key.OwnerID {
|
||||
@@ -38,7 +39,7 @@ func appendPrivateInformation(ctx std_ctx.Context, apiKey *api.PublicKey, key *a
|
||||
}
|
||||
apiKey.Owner = convert.ToUser(ctx, user, user)
|
||||
}
|
||||
} else {
|
||||
default:
|
||||
apiKey.KeyType = "unknown"
|
||||
}
|
||||
apiKey.ReadOnly = key.Mode == perm.AccessModeRead
|
||||
|
@@ -447,10 +447,7 @@ func preReceiveFor(ctx *preReceiveContext, refFullName git.RefName) {
|
||||
|
||||
baseBranchName := refFullName.ForBranchName()
|
||||
|
||||
baseBranchExist := false
|
||||
if gitrepo.IsBranchExist(ctx, ctx.Repo.Repository, baseBranchName) {
|
||||
baseBranchExist = true
|
||||
}
|
||||
baseBranchExist := gitrepo.IsBranchExist(ctx, ctx.Repo.Repository, baseBranchName)
|
||||
|
||||
if !baseBranchExist {
|
||||
for p, v := range baseBranchName {
|
||||
|
@@ -534,7 +534,8 @@ func createUserInContext(ctx *context.Context, tpl templates.TplName, form any,
|
||||
}
|
||||
if err := user_model.CreateUser(ctx, u, meta, overwrites); err != nil {
|
||||
if allowLink && (user_model.IsErrUserAlreadyExist(err) || user_model.IsErrEmailAlreadyUsed(err)) {
|
||||
if setting.OAuth2Client.AccountLinking == setting.OAuth2AccountLinkingAuto {
|
||||
switch setting.OAuth2Client.AccountLinking {
|
||||
case setting.OAuth2AccountLinkingAuto:
|
||||
var user *user_model.User
|
||||
user = &user_model.User{Name: u.Name}
|
||||
hasUser, err := user_model.GetUser(ctx, user)
|
||||
@@ -550,7 +551,7 @@ func createUserInContext(ctx *context.Context, tpl templates.TplName, form any,
|
||||
// TODO: probably we should respect 'remember' user's choice...
|
||||
linkAccount(ctx, user, *gothUser, true)
|
||||
return false // user is already created here, all redirects are handled
|
||||
} else if setting.OAuth2Client.AccountLinking == setting.OAuth2AccountLinkingLogin {
|
||||
case setting.OAuth2AccountLinkingLogin:
|
||||
showLinkingLogin(ctx, *gothUser)
|
||||
return false // user will be created only after linking login
|
||||
}
|
||||
|
@@ -155,9 +155,10 @@ func SignInOAuthCallback(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
if uname == "" {
|
||||
if setting.OAuth2Client.Username == setting.OAuth2UsernameNickname {
|
||||
switch setting.OAuth2Client.Username {
|
||||
case setting.OAuth2UsernameNickname:
|
||||
missingFields = append(missingFields, "nickname")
|
||||
} else if setting.OAuth2Client.Username == setting.OAuth2UsernamePreferredUsername {
|
||||
case setting.OAuth2UsernamePreferredUsername:
|
||||
missingFields = append(missingFields, "preferred_username")
|
||||
} // else: "UserID" and "Email" have been handled above separately
|
||||
}
|
||||
|
@@ -55,13 +55,14 @@ func Worktime(ctx *context.Context) {
|
||||
|
||||
var worktimeSumResult any
|
||||
var err error
|
||||
if worktimeBy == "milestones" {
|
||||
switch worktimeBy {
|
||||
case "milestones":
|
||||
worktimeSumResult, err = organization.GetWorktimeByMilestones(ctx.Org.Organization, unixFrom, unixTo)
|
||||
ctx.Data["WorktimeByMilestones"] = true
|
||||
} else if worktimeBy == "members" {
|
||||
case "members":
|
||||
worktimeSumResult, err = organization.GetWorktimeByMembers(ctx.Org.Organization, unixFrom, unixTo)
|
||||
ctx.Data["WorktimeByMembers"] = true
|
||||
} else /* by repos */ {
|
||||
default: /* by repos */
|
||||
worktimeSumResult, err = organization.GetWorktimeByRepos(ctx.Org.Organization, unixFrom, unixTo)
|
||||
ctx.Data["WorktimeByRepos"] = true
|
||||
}
|
||||
|
@@ -938,9 +938,10 @@ func ExcerptBlob(ctx *context.Context) {
|
||||
RightHunkSize: rightHunkSize,
|
||||
},
|
||||
}
|
||||
if direction == "up" {
|
||||
switch direction {
|
||||
case "up":
|
||||
section.Lines = append([]*gitdiff.DiffLine{lineSection}, section.Lines...)
|
||||
} else if direction == "down" {
|
||||
case "down":
|
||||
section.Lines = append(section.Lines, lineSection)
|
||||
}
|
||||
}
|
||||
|
@@ -157,15 +157,16 @@ func GetContentHistoryDetail(ctx *context.Context) {
|
||||
diffHTMLBuf := bytes.Buffer{}
|
||||
diffHTMLBuf.WriteString("<pre class='chroma'>")
|
||||
for _, it := range diff {
|
||||
if it.Type == diffmatchpatch.DiffInsert {
|
||||
switch it.Type {
|
||||
case diffmatchpatch.DiffInsert:
|
||||
diffHTMLBuf.WriteString("<span class='gi'>")
|
||||
diffHTMLBuf.WriteString(html.EscapeString(it.Text))
|
||||
diffHTMLBuf.WriteString("</span>")
|
||||
} else if it.Type == diffmatchpatch.DiffDelete {
|
||||
case diffmatchpatch.DiffDelete:
|
||||
diffHTMLBuf.WriteString("<span class='gd'>")
|
||||
diffHTMLBuf.WriteString(html.EscapeString(it.Text))
|
||||
diffHTMLBuf.WriteString("</span>")
|
||||
} else {
|
||||
default:
|
||||
diffHTMLBuf.WriteString(html.EscapeString(it.Text))
|
||||
}
|
||||
}
|
||||
|
@@ -696,9 +696,10 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
|
||||
return 0
|
||||
}
|
||||
reviewTyp := issues_model.ReviewTypeApprove
|
||||
if typ == "reject" {
|
||||
switch typ {
|
||||
case "reject":
|
||||
reviewTyp = issues_model.ReviewTypeReject
|
||||
} else if typ == "waiting" {
|
||||
case "waiting":
|
||||
reviewTyp = issues_model.ReviewTypeRequest
|
||||
}
|
||||
for _, count := range counts {
|
||||
|
@@ -209,11 +209,12 @@ func renderConversation(ctx *context.Context, comment *issues_model.Comment, ori
|
||||
return user_service.CanBlockUser(ctx, ctx.Doer, blocker, blockee)
|
||||
}
|
||||
|
||||
if origin == "diff" {
|
||||
switch origin {
|
||||
case "diff":
|
||||
ctx.HTML(http.StatusOK, tplDiffConversation)
|
||||
} else if origin == "timeline" {
|
||||
case "timeline":
|
||||
ctx.HTML(http.StatusOK, tplTimelineConversation)
|
||||
} else {
|
||||
default:
|
||||
ctx.HTTPError(http.StatusBadRequest, "Unknown origin: "+origin)
|
||||
}
|
||||
}
|
||||
|
@@ -617,9 +617,10 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
|
||||
return 0
|
||||
}
|
||||
reviewTyp := issues_model.ReviewTypeApprove
|
||||
if typ == "reject" {
|
||||
switch typ {
|
||||
case "reject":
|
||||
reviewTyp = issues_model.ReviewTypeReject
|
||||
} else if typ == "waiting" {
|
||||
case "waiting":
|
||||
reviewTyp = issues_model.ReviewTypeRequest
|
||||
}
|
||||
for _, count := range counts {
|
||||
|
@@ -308,9 +308,10 @@ func NotificationSubscriptions(ctx *context.Context) {
|
||||
return 0
|
||||
}
|
||||
reviewTyp := issues_model.ReviewTypeApprove
|
||||
if typ == "reject" {
|
||||
switch typ {
|
||||
case "reject":
|
||||
reviewTyp = issues_model.ReviewTypeReject
|
||||
} else if typ == "waiting" {
|
||||
case "waiting":
|
||||
reviewTyp = issues_model.ReviewTypeRequest
|
||||
}
|
||||
for _, count := range counts {
|
||||
|
@@ -854,13 +854,13 @@ func registerRoutes(m *web.Router) {
|
||||
individualPermsChecker := func(ctx *context.Context) {
|
||||
// org permissions have been checked in context.OrgAssignment(), but individual permissions haven't been checked.
|
||||
if ctx.ContextUser.IsIndividual() {
|
||||
switch {
|
||||
case ctx.ContextUser.Visibility == structs.VisibleTypePrivate:
|
||||
switch ctx.ContextUser.Visibility {
|
||||
case structs.VisibleTypePrivate:
|
||||
if ctx.Doer == nil || (ctx.ContextUser.ID != ctx.Doer.ID && !ctx.Doer.IsAdmin) {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
}
|
||||
case ctx.ContextUser.Visibility == structs.VisibleTypeLimited:
|
||||
case structs.VisibleTypeLimited:
|
||||
if ctx.Doer == nil {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
|
Reference in New Issue
Block a user