mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-15 18:56:59 +00:00
Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367)
Co-authored-by: Renovate Bot <forgejo-renovate-action@forgejo.org> Co-committed-by: Renovate Bot <forgejo-renovate-action@forgejo.org>
This commit is contained in:
parent
51ff4970ec
commit
fed2d81c44
427 changed files with 2043 additions and 2046 deletions
|
@ -166,8 +166,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)
|
||||
}
|
||||
|
||||
|
|
|
@ -48,13 +48,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.Error(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.Error(http.StatusInternalServerError, "HasScope", err.Error())
|
||||
|
|
|
@ -147,7 +147,7 @@ func getSignVersion(req *http.Request) (string, error) {
|
|||
version := m[1]
|
||||
|
||||
m = algorithmPattern.FindStringSubmatch(hdr)
|
||||
if len(m) == 2 && m[1] != "sha1" && !(m[1] == "sha256" && version == "1.3") {
|
||||
if len(m) == 2 && m[1] != "sha1" && (m[1] != "sha256" || version != "1.3") {
|
||||
return "", util.NewInvalidArgumentErrorf("unsupported algorithm")
|
||||
}
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ func EnumeratePackages(ctx *context.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
skip, _ := opts.Paginator.GetSkipTake()
|
||||
skip, _ := opts.GetSkipTake()
|
||||
|
||||
ctx.JSON(http.StatusOK, &Result{
|
||||
Start: skip,
|
||||
|
|
|
@ -25,7 +25,7 @@ func (a *Auth) Name() string {
|
|||
func (a *Auth) Verify(req *http.Request, w http.ResponseWriter, store auth.DataStore, sess auth.SessionStore) (*user_model.User, error) {
|
||||
token, err := auth_model.GetAccessTokenBySHA(req.Context(), req.Header.Get("X-NuGet-ApiKey"))
|
||||
if err != nil {
|
||||
if !(auth_model.IsErrAccessTokenNotExist(err) || auth_model.IsErrAccessTokenEmpty(err)) {
|
||||
if !auth_model.IsErrAccessTokenNotExist(err) && !auth_model.IsErrAccessTokenEmpty(err) {
|
||||
log.Error("GetAccessTokenBySHA: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -203,19 +203,19 @@ func repoAssignment() func(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
if task.IsForkPullRequest {
|
||||
ctx.Repo.Permission.AccessMode = perm.AccessModeRead
|
||||
ctx.Repo.AccessMode = perm.AccessModeRead
|
||||
} else {
|
||||
ctx.Repo.Permission.AccessMode = perm.AccessModeWrite
|
||||
ctx.Repo.AccessMode = perm.AccessModeWrite
|
||||
}
|
||||
|
||||
if err := ctx.Repo.Repository.LoadUnits(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadUnits", err)
|
||||
return
|
||||
}
|
||||
ctx.Repo.Permission.Units = ctx.Repo.Repository.Units
|
||||
ctx.Repo.Permission.UnitsMode = make(map[unit.Type]perm.AccessMode)
|
||||
ctx.Repo.Units = ctx.Repo.Repository.Units
|
||||
ctx.Repo.UnitsMode = make(map[unit.Type]perm.AccessMode)
|
||||
for _, u := range ctx.Repo.Repository.Units {
|
||||
ctx.Repo.Permission.UnitsMode[u.Type] = ctx.Repo.Permission.AccessMode
|
||||
ctx.Repo.UnitsMode[u.Type] = ctx.Repo.AccessMode
|
||||
}
|
||||
} else {
|
||||
ctx.Repo.Permission, err = access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
||||
|
@ -692,7 +692,7 @@ func mustEnableIssues(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
func mustAllowPulls(ctx *context.APIContext) {
|
||||
if !(ctx.Repo.Repository.CanEnablePulls() && ctx.Repo.CanRead(unit.TypePullRequests)) {
|
||||
if !ctx.Repo.Repository.CanEnablePulls() || !ctx.Repo.CanRead(unit.TypePullRequests) {
|
||||
if ctx.Repo.Repository.CanEnablePulls() && log.IsTrace() {
|
||||
if ctx.IsSigned {
|
||||
log.Trace("Permission Denied: User %-v cannot read %-v in Repo %-v\n"+
|
||||
|
@ -716,7 +716,7 @@ func mustAllowPulls(ctx *context.APIContext) {
|
|||
|
||||
func mustEnableIssuesOrPulls(ctx *context.APIContext) {
|
||||
if !ctx.Repo.CanRead(unit.TypeIssues) &&
|
||||
!(ctx.Repo.Repository.CanEnablePulls() && ctx.Repo.CanRead(unit.TypePullRequests)) {
|
||||
(!ctx.Repo.Repository.CanEnablePulls() || !ctx.Repo.CanRead(unit.TypePullRequests)) {
|
||||
if ctx.Repo.Repository.CanEnablePulls() && log.IsTrace() {
|
||||
if ctx.IsSigned {
|
||||
log.Trace("Permission Denied: User %-v cannot read %-v and %-v in Repo %-v\n"+
|
||||
|
@ -777,13 +777,13 @@ func bind[T any](_ T) any {
|
|||
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.NotFound("Visit Project", nil)
|
||||
return
|
||||
}
|
||||
case ctx.ContextUser.Visibility == api.VisibleTypeLimited:
|
||||
case api.VisibleTypeLimited:
|
||||
if ctx.Doer == nil {
|
||||
ctx.NotFound("Visit Project", nil)
|
||||
return
|
||||
|
|
|
@ -231,9 +231,9 @@ func CreateBranch(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
||||
return
|
||||
}
|
||||
} else if len(opt.OldBranchName) > 0 { //nolint
|
||||
if ctx.Repo.GitRepo.IsBranchExist(opt.OldBranchName) { //nolint
|
||||
oldCommit, err = ctx.Repo.GitRepo.GetBranchCommit(opt.OldBranchName) //nolint
|
||||
} else if len(opt.OldBranchName) > 0 { //nolint:staticcheck
|
||||
if ctx.Repo.GitRepo.IsBranchExist(opt.OldBranchName) { //nolint:staticcheck
|
||||
oldCommit, err = ctx.Repo.GitRepo.GetBranchCommit(opt.OldBranchName) //nolint:staticcheck
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetBranchCommit", err)
|
||||
return
|
||||
|
|
|
@ -437,7 +437,7 @@ func canWriteFiles(ctx *context.APIContext, branch string) bool {
|
|||
|
||||
// canReadFiles returns true if repository is readable and user has proper access level.
|
||||
func canReadFiles(r *context.Repository) bool {
|
||||
return r.Permission.CanRead(unit.TypeCode)
|
||||
return r.CanRead(unit.TypeCode)
|
||||
}
|
||||
|
||||
func base64Reader(s string) (io.ReadSeeker, error) {
|
||||
|
|
|
@ -25,7 +25,7 @@ func TestTestHook(t *testing.T) {
|
|||
defer ctx.Repo.GitRepo.Close()
|
||||
contexttest.LoadRepoCommit(t, ctx)
|
||||
TestHook(ctx)
|
||||
assert.EqualValues(t, http.StatusNoContent, ctx.Resp.Status())
|
||||
assert.Equal(t, http.StatusNoContent, ctx.Resp.Status())
|
||||
|
||||
unittest.AssertExistsAndLoadBean(t, &webhook.HookTask{
|
||||
HookID: 1,
|
||||
|
|
|
@ -72,7 +72,7 @@ func GetIssueDependencies(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// 1. We must be able to read this issue
|
||||
if !ctx.Repo.Permission.CanReadIssuesOrPulls(issue.IsPull) {
|
||||
if !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull) {
|
||||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ func GetIssueDependencies(ctx *context.APIContext) {
|
|||
limit = setting.API.MaxResponseItems
|
||||
}
|
||||
|
||||
canWrite := ctx.Repo.Permission.CanWriteIssuesOrPulls(issue.IsPull)
|
||||
canWrite := ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)
|
||||
|
||||
blockerIssues := make([]*issues_model.Issue, 0, limit)
|
||||
|
||||
|
@ -123,7 +123,7 @@ func GetIssueDependencies(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// check permission
|
||||
if !perm.CanReadIssuesOrPulls(blocker.Issue.IsPull) {
|
||||
if !perm.CanReadIssuesOrPulls(blocker.IsPull) {
|
||||
if !canWrite {
|
||||
hiddenBlocker := &issues_model.DependencyInfo{
|
||||
Issue: issues_model.Issue{
|
||||
|
@ -134,19 +134,19 @@ func GetIssueDependencies(ctx *context.APIContext) {
|
|||
} else {
|
||||
confidentialBlocker := &issues_model.DependencyInfo{
|
||||
Issue: issues_model.Issue{
|
||||
RepoID: blocker.Issue.RepoID,
|
||||
RepoID: blocker.RepoID,
|
||||
Index: blocker.Index,
|
||||
Title: blocker.Title,
|
||||
IsClosed: blocker.IsClosed,
|
||||
IsPull: blocker.IsPull,
|
||||
},
|
||||
Repository: repo_model.Repository{
|
||||
ID: blocker.Issue.Repo.ID,
|
||||
Name: blocker.Issue.Repo.Name,
|
||||
OwnerName: blocker.Issue.Repo.OwnerName,
|
||||
ID: blocker.Repo.ID,
|
||||
Name: blocker.Repo.Name,
|
||||
OwnerName: blocker.Repo.OwnerName,
|
||||
},
|
||||
}
|
||||
confidentialBlocker.Issue.Repo = &confidentialBlocker.Repository
|
||||
confidentialBlocker.Repo = &confidentialBlocker.Repository
|
||||
blocker = confidentialBlocker
|
||||
}
|
||||
}
|
||||
|
@ -323,7 +323,7 @@ func GetIssueBlocks(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if !ctx.Repo.Permission.CanReadIssuesOrPulls(issue.IsPull) {
|
||||
if !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull) {
|
||||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
|
@ -373,11 +373,11 @@ func GetIssueBlocks(ctx *context.APIContext) {
|
|||
repoPerms[depMeta.RepoID] = perm
|
||||
}
|
||||
|
||||
if !perm.CanReadIssuesOrPulls(depMeta.Issue.IsPull) {
|
||||
if !perm.CanReadIssuesOrPulls(depMeta.IsPull) {
|
||||
continue
|
||||
}
|
||||
|
||||
depMeta.Issue.Repo = &depMeta.Repository
|
||||
depMeta.Repo = &depMeta.Repository
|
||||
issues = append(issues, &depMeta.Issue)
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ func TestRepoEdit(t *testing.T) {
|
|||
web.SetForm(ctx, &opts)
|
||||
Edit(ctx)
|
||||
|
||||
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
||||
assert.Equal(t, http.StatusOK, ctx.Resp.Status())
|
||||
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{
|
||||
ID: 1,
|
||||
}, unittest.Cond("name = ? AND is_archived = 1", *opts.Name))
|
||||
|
@ -78,7 +78,7 @@ func TestRepoEditNameChange(t *testing.T) {
|
|||
|
||||
web.SetForm(ctx, &opts)
|
||||
Edit(ctx)
|
||||
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
||||
assert.Equal(t, http.StatusOK, ctx.Resp.Status())
|
||||
|
||||
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{
|
||||
ID: 1,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -155,7 +155,7 @@ func ListMyRepos(ctx *context.APIContext) {
|
|||
results[i] = convert.ToRepo(ctx, repo, permission)
|
||||
}
|
||||
|
||||
ctx.SetLinkHeader(int(count), opts.ListOptions.PageSize)
|
||||
ctx.SetLinkHeader(int(count), opts.PageSize)
|
||||
ctx.SetTotalCountHeader(count)
|
||||
ctx.JSON(http.StatusOK, &results)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue