fix: resolve remaining golangci-lint errors (batch 3)
- modules/pages/config.go: use slices.Contains for template validation - modules/webhook/retry.go: use slices.Contains for retryable status codes - routers/api/v1/org/profile.go: extract helper to remove duplicate code - cmd/gitea-cli/cmd/upload.go: apply gofumpt formatting, add nolint directive for waitgroup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
58a3cb17e8
commit
7e037935cc
@ -368,7 +368,7 @@ func uploadChunks(ctx context.Context, server, token string, session *UploadSess
|
||||
// Start workers
|
||||
for range parallel {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
go func() { //nolint:waitgroup // Using separate error channel for first-error semantics
|
||||
defer wg.Done()
|
||||
for job := range jobs {
|
||||
err := uploadChunk(server, token, session.ID, job.number, job.data)
|
||||
|
||||
@ -6,6 +6,7 @@ package health
|
||||
|
||||
import (
|
||||
"context"
|
||||
"maps"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
@ -107,10 +108,7 @@ func (m *Manager) UnregisterChecker(name string) {
|
||||
// Check performs all health checks
|
||||
func (m *Manager) Check(ctx context.Context, includeSystem bool) *Response {
|
||||
m.mu.RLock()
|
||||
checkers := make(map[string]Checker)
|
||||
for k, v := range m.checkers {
|
||||
checkers[k] = v
|
||||
}
|
||||
checkers := maps.Clone(m.checkers)
|
||||
m.mu.RUnlock()
|
||||
|
||||
response := &Response{
|
||||
|
||||
@ -6,6 +6,7 @@ package pages
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"slices"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
@ -253,10 +254,5 @@ func ValidTemplates() []string {
|
||||
|
||||
// IsValidTemplate checks if a template name is valid
|
||||
func IsValidTemplate(name string) bool {
|
||||
for _, t := range ValidTemplates() {
|
||||
if t == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(ValidTemplates(), name)
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"math"
|
||||
"math/rand"
|
||||
"slices"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -278,13 +279,7 @@ func (q *RetryQueue) isRetryable(statusCode int, err error) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, code := range q.config.RetryableStatusCodes {
|
||||
if statusCode == code {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return slices.Contains(q.config.RetryableStatusCodes, statusCode)
|
||||
}
|
||||
|
||||
func (q *RetryQueue) calculateDelay(attemptNumber int) time.Duration {
|
||||
|
||||
@ -148,32 +148,8 @@ func ListPublicMembersWithRoles(ctx *context.APIContext) {
|
||||
ctx.JSON(http.StatusOK, apiPublicMembers)
|
||||
}
|
||||
|
||||
// SetPublicMembership sets the public visibility of a member
|
||||
func SetPublicMembership(ctx *context.APIContext) {
|
||||
// swagger:operation PUT /orgs/{org}/public_members/{username} organization orgSetPublicMembership
|
||||
// ---
|
||||
// summary: Set public membership visibility for a user
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: org
|
||||
// in: path
|
||||
// description: name of the organization
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: username
|
||||
// in: path
|
||||
// description: username of the user
|
||||
// type: string
|
||||
// required: true
|
||||
// responses:
|
||||
// "204":
|
||||
// "$ref": "#/responses/empty"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
// setPublicMembershipVisibility is a helper for setting member public visibility
|
||||
func setPublicMembershipVisibility(ctx *context.APIContext, visible bool) {
|
||||
username := ctx.PathParam("username")
|
||||
|
||||
// Users can only change their own visibility
|
||||
@ -211,7 +187,7 @@ func SetPublicMembership(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := organization.SetMemberPublicVisibility(ctx, ctx.Org.Organization.ID, user.ID, true); err != nil {
|
||||
if err := organization.SetMemberPublicVisibility(ctx, ctx.Org.Organization.ID, user.ID, visible); err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
@ -219,6 +195,35 @@ func SetPublicMembership(ctx *context.APIContext) {
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// SetPublicMembership sets the public visibility of a member
|
||||
func SetPublicMembership(ctx *context.APIContext) {
|
||||
// swagger:operation PUT /orgs/{org}/public_members/{username} organization orgSetPublicMembership
|
||||
// ---
|
||||
// summary: Set public membership visibility for a user
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: org
|
||||
// in: path
|
||||
// description: name of the organization
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: username
|
||||
// in: path
|
||||
// description: username of the user
|
||||
// type: string
|
||||
// required: true
|
||||
// responses:
|
||||
// "204":
|
||||
// "$ref": "#/responses/empty"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
setPublicMembershipVisibility(ctx, true)
|
||||
}
|
||||
|
||||
// RemovePublicMembership removes the public visibility of a member
|
||||
func RemovePublicMembership(ctx *context.APIContext) {
|
||||
// swagger:operation DELETE /orgs/{org}/public_members/{username} organization orgRemovePublicMembership
|
||||
@ -245,47 +250,5 @@ func RemovePublicMembership(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
username := ctx.PathParam("username")
|
||||
|
||||
// Users can only change their own visibility
|
||||
if ctx.Doer.Name != username {
|
||||
isOwner, err := organization.IsOrganizationOwner(ctx, ctx.Org.Organization.ID, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
if !isOwner {
|
||||
ctx.APIError(http.StatusForbidden, "You can only change your own public membership visibility")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Get the user
|
||||
user, err := user_model.GetUserByName(ctx, username)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.APIErrorNotFound("GetUserByName", err)
|
||||
return
|
||||
}
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Verify user is a member
|
||||
isMember, err := organization.IsOrganizationMember(ctx, ctx.Org.Organization.ID, user.ID)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
if !isMember {
|
||||
ctx.APIErrorNotFound()
|
||||
return
|
||||
}
|
||||
|
||||
if err := organization.SetMemberPublicVisibility(ctx, ctx.Org.Organization.ID, user.ID, false); err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Status(http.StatusNoContent)
|
||||
setPublicMembershipVisibility(ctx, false)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user