Skip to content

Commit 092c46d

Browse files
committed
Merge remote-tracking branch 'origin/main' into zzc/dev/sidebar_board_option
2 parents 64701bd + dd2aaad commit 092c46d

File tree

132 files changed

+244
-297
lines changed

Some content is hidden

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

132 files changed

+244
-297
lines changed

.eslintrc.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ rules:
310310
jquery/no-merge: [2]
311311
jquery/no-param: [2]
312312
jquery/no-parent: [0]
313-
jquery/no-parents: [0]
313+
jquery/no-parents: [2]
314314
jquery/no-parse-html: [2]
315315
jquery/no-prop: [2]
316316
jquery/no-proxy: [2]
@@ -319,8 +319,8 @@ rules:
319319
jquery/no-show: [2]
320320
jquery/no-size: [2]
321321
jquery/no-sizzle: [2]
322-
jquery/no-slide: [0]
323-
jquery/no-submit: [0]
322+
jquery/no-slide: [2]
323+
jquery/no-submit: [2]
324324
jquery/no-text: [0]
325325
jquery/no-toggle: [2]
326326
jquery/no-trigger: [0]
@@ -458,7 +458,7 @@ rules:
458458
no-jquery/no-other-utils: [2]
459459
no-jquery/no-param: [2]
460460
no-jquery/no-parent: [0]
461-
no-jquery/no-parents: [0]
461+
no-jquery/no-parents: [2]
462462
no-jquery/no-parse-html-literal: [0]
463463
no-jquery/no-parse-html: [2]
464464
no-jquery/no-parse-json: [2]

.golangci.yml

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
linters:
2+
enable-all: false
3+
disable-all: true
4+
fast: false
25
enable:
36
- bidichk
4-
# - deadcode # deprecated - https://github.com/golangci/golangci-lint/issues/1841
57
- depguard
68
- dupl
79
- errcheck
810
- forbidigo
911
- gocritic
10-
# - gocyclo # The cyclomatic complexety of a lot of functions is too high, we should refactor those another time.
1112
- gofmt
1213
- gofumpt
1314
- gosimple
@@ -17,20 +18,18 @@ linters:
1718
- nolintlint
1819
- revive
1920
- staticcheck
20-
# - structcheck # deprecated - https://github.com/golangci/golangci-lint/issues/1841
2121
- stylecheck
2222
- typecheck
2323
- unconvert
2424
- unused
25-
# - varcheck # deprecated - https://github.com/golangci/golangci-lint/issues/1841
2625
- wastedassign
27-
enable-all: false
28-
disable-all: true
29-
fast: false
3026

3127
run:
3228
timeout: 10m
3329

30+
output:
31+
sort-results: true
32+
3433
linters-settings:
3534
stylecheck:
3635
checks: ["all", "-ST1005", "-ST1003"]
@@ -47,27 +46,37 @@ linters-settings:
4746
errorCode: 1
4847
warningCode: 1
4948
rules:
49+
- name: atomic
50+
- name: bare-return
5051
- name: blank-imports
52+
- name: constant-logical-expr
5153
- name: context-as-argument
5254
- name: context-keys-type
5355
- name: dot-imports
56+
- name: duplicated-imports
57+
- name: empty-lines
58+
- name: error-naming
5459
- name: error-return
5560
- name: error-strings
56-
- name: error-naming
61+
- name: errorf
5762
- name: exported
63+
- name: identical-branches
5864
- name: if-return
5965
- name: increment-decrement
60-
- name: var-naming
61-
- name: var-declaration
66+
- name: indent-error-flow
67+
- name: modifies-value-receiver
6268
- name: package-comments
6369
- name: range
6470
- name: receiver-naming
71+
- name: redefines-builtin-id
72+
- name: string-of-int
73+
- name: superfluous-else
6574
- name: time-naming
75+
- name: unconditional-recursion
6676
- name: unexported-return
67-
- name: indent-error-flow
68-
- name: errorf
69-
- name: duplicated-imports
70-
- name: modifies-value-receiver
77+
- name: unreachable-code
78+
- name: var-declaration
79+
- name: var-naming
7180
gofumpt:
7281
extra-rules: true
7382
depguard:
@@ -93,8 +102,8 @@ issues:
93102
max-issues-per-linter: 0
94103
max-same-issues: 0
95104
exclude-dirs: [node_modules, public, web_src]
105+
exclude-case-sensitive: true
96106
exclude-rules:
97-
# Exclude some linters from running on tests files.
98107
- path: _test\.go
99108
linters:
100109
- gocyclo
@@ -112,19 +121,19 @@ issues:
112121
- path: cmd
113122
linters:
114123
- forbidigo
115-
- linters:
124+
- text: "webhook"
125+
linters:
116126
- dupl
117-
text: "webhook"
118-
- linters:
127+
- text: "`ID' should not be capitalized"
128+
linters:
119129
- gocritic
120-
text: "`ID' should not be capitalized"
121-
- linters:
130+
- text: "swagger"
131+
linters:
122132
- unused
123133
- deadcode
124-
text: "swagger"
125-
- linters:
134+
- text: "argument x is overwritten before first use"
135+
linters:
126136
- staticcheck
127-
text: "argument x is overwritten before first use"
128137
- text: "commentFormatting: put a space between `//` and comment text"
129138
linters:
130139
- gocritic

cmd/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ func hookPrintResult(output, isCreate bool, branch, url string) {
465465
fmt.Fprintf(os.Stderr, " %s\n", url)
466466
}
467467
fmt.Fprintln(os.Stderr, "")
468-
os.Stderr.Sync()
468+
_ = os.Stderr.Sync()
469469
}
470470

471471
func pushOptions() map[string]string {

models/actions/runner.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func CountRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
270270
// Only affect action runners were a owner ID is set, as actions runners
271271
// could also be created on a repository.
272272
return db.GetEngine(ctx).Table("action_runner").
273-
Join("LEFT", "user", "`action_runner`.owner_id = `user`.id").
273+
Join("LEFT", "`user`", "`action_runner`.owner_id = `user`.id").
274274
Where("`action_runner`.owner_id != ?", 0).
275275
And(builder.IsNull{"`user`.id"}).
276276
Count(new(ActionRunner))
@@ -279,7 +279,7 @@ func CountRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
279279
func FixRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
280280
subQuery := builder.Select("`action_runner`.id").
281281
From("`action_runner`").
282-
Join("LEFT", "user", "`action_runner`.owner_id = `user`.id").
282+
Join("LEFT", "`user`", "`action_runner`.owner_id = `user`.id").
283283
Where(builder.Neq{"`action_runner`.owner_id": 0}).
284284
And(builder.IsNull{"`user`.id"})
285285
b := builder.Delete(builder.In("id", subQuery)).From("`action_runner`")
@@ -289,3 +289,25 @@ func FixRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
289289
}
290290
return res.RowsAffected()
291291
}
292+
293+
func CountRunnersWithoutBelongingRepo(ctx context.Context) (int64, error) {
294+
return db.GetEngine(ctx).Table("action_runner").
295+
Join("LEFT", "`repository`", "`action_runner`.repo_id = `repository`.id").
296+
Where("`action_runner`.repo_id != ?", 0).
297+
And(builder.IsNull{"`repository`.id"}).
298+
Count(new(ActionRunner))
299+
}
300+
301+
func FixRunnersWithoutBelongingRepo(ctx context.Context) (int64, error) {
302+
subQuery := builder.Select("`action_runner`.id").
303+
From("`action_runner`").
304+
Join("LEFT", "`repository`", "`action_runner`.repo_id = `repository`.id").
305+
Where(builder.Neq{"`action_runner`.repo_id": 0}).
306+
And(builder.IsNull{"`repository`.id"})
307+
b := builder.Delete(builder.In("id", subQuery)).From("`action_runner`")
308+
res, err := db.GetEngine(ctx).Exec(b)
309+
if err != nil {
310+
return 0, err
311+
}
312+
return res.RowsAffected()
313+
}

models/asymkey/gpg_key_commit_verification.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ func ParseCommitWithSignature(ctx context.Context, c *git.Commit) *CommitVerific
110110
Reason: "gpg.error.no_committer_account",
111111
}
112112
}
113-
114113
}
115114
}
116115

models/auth/oauth2_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
"github.com/stretchr/testify/assert"
1414
)
1515

16-
//////////////////// Application
17-
1816
func TestOAuth2Application_GenerateClientSecret(t *testing.T) {
1917
assert.NoError(t, unittest.PrepareTestDatabase())
2018
app := unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: 1})

models/db/engine.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ func NamesToBean(names ...string) ([]any, error) {
227227
// Need to map provided names to beans...
228228
beanMap := make(map[string]any)
229229
for _, bean := range tables {
230-
231230
beanMap[strings.ToLower(reflect.Indirect(reflect.ValueOf(bean)).Type().Name())] = bean
232231
beanMap[strings.ToLower(x.TableName(bean))] = bean
233232
beanMap[strings.ToLower(x.TableName(bean, true))] = bean

models/issues/review.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,9 @@ func CreateReview(ctx context.Context, opts CreateReviewOptions) (*Review, error
345345
return nil, err
346346
}
347347
}
348-
349348
} else if opts.ReviewerTeam != nil {
350349
review.Type = ReviewTypeRequest
351350
review.ReviewerTeamID = opts.ReviewerTeam.ID
352-
353351
} else {
354352
return nil, fmt.Errorf("provide either reviewer or reviewer team")
355353
}

models/migrations/base/db.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ func RecreateTable(sess *xorm.Session, bean any) error {
177177
log.Error("Unable to recreate uniques on table %s. Error: %v", tableName, err)
178178
return err
179179
}
180-
181180
case setting.Database.Type.IsMySQL():
182181
// MySQL will drop all the constraints on the old table
183182
if _, err := sess.Exec(fmt.Sprintf("DROP TABLE `%s`", tableName)); err != nil {
@@ -228,7 +227,6 @@ func RecreateTable(sess *xorm.Session, bean any) error {
228227
return err
229228
}
230229
sequenceMap[sequence] = sequenceData
231-
232230
}
233231

234232
// CASCADE causes postgres to drop all the constraints on the old table
@@ -293,9 +291,7 @@ func RecreateTable(sess *xorm.Session, bean any) error {
293291
return err
294292
}
295293
}
296-
297294
}
298-
299295
case setting.Database.Type.IsMSSQL():
300296
// MSSQL will drop all the constraints on the old table
301297
if _, err := sess.Exec(fmt.Sprintf("DROP TABLE `%s`", tableName)); err != nil {
@@ -308,7 +304,6 @@ func RecreateTable(sess *xorm.Session, bean any) error {
308304
log.Error("Unable to rename %s to %s. Error: %v", tempTableName, tableName, err)
309305
return err
310306
}
311-
312307
default:
313308
log.Fatal("Unrecognized DB")
314309
}

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ var migrations = []Migration{
584584
NewMigration("Add missing field of commit status summary table", v1_23.AddCommitStatusSummary2),
585585
// v297 -> v298
586586
NewMigration("Add everyone_access_mode for repo_unit", v1_23.AddRepoUnitEveryoneAccessMode),
587+
// v298 -> v299
588+
NewMigration("Drop wrongly created table o_auth2_application", v1_23.DropWronglyCreatedTable),
587589
}
588590

589591
// GetCurrentDBVersion returns the current db version

models/migrations/v1_11/v111.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ func AddBranchProtectionCanPushAndEnableWhitelist(x *xorm.Engine) error {
262262
for _, u := range units {
263263
var found bool
264264
for _, team := range teams {
265-
266265
var teamU []*TeamUnit
267266
var unitEnabled bool
268267
err = sess.Where("team_id = ?", team.ID).Find(&teamU)
@@ -331,7 +330,6 @@ func AddBranchProtectionCanPushAndEnableWhitelist(x *xorm.Engine) error {
331330
}
332331

333332
if !protectedBranch.EnableApprovalsWhitelist {
334-
335333
perm, err := getUserRepoPermission(sess, baseRepo, reviewer)
336334
if err != nil {
337335
return false, err

models/migrations/v1_18/v230.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99

1010
// AddConfidentialColumnToOAuth2ApplicationTable: add ConfidentialClient column, setting existing rows to true
1111
func AddConfidentialClientColumnToOAuth2ApplicationTable(x *xorm.Engine) error {
12-
type OAuth2Application struct {
12+
type oauth2Application struct {
13+
ID int64
1314
ConfidentialClient bool `xorm:"NOT NULL DEFAULT TRUE"`
1415
}
15-
16-
return x.Sync(new(OAuth2Application))
16+
return x.Sync(new(oauth2Application))
1717
}

models/migrations/v1_18/v230_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import (
1313

1414
func Test_AddConfidentialClientColumnToOAuth2ApplicationTable(t *testing.T) {
1515
// premigration
16-
type OAuth2Application struct {
16+
type oauth2Application struct {
1717
ID int64
1818
}
1919

2020
// Prepare and load the testing database
21-
x, deferable := base.PrepareTestEnv(t, 0, new(OAuth2Application))
21+
x, deferable := base.PrepareTestEnv(t, 0, new(oauth2Application))
2222
defer deferable()
2323
if x == nil || t.Failed() {
2424
return
@@ -36,7 +36,7 @@ func Test_AddConfidentialClientColumnToOAuth2ApplicationTable(t *testing.T) {
3636
}
3737

3838
got := []ExpectedOAuth2Application{}
39-
if err := x.Table("o_auth2_application").Select("id, confidential_client").Find(&got); !assert.NoError(t, err) {
39+
if err := x.Table("oauth2_application").Select("id, confidential_client").Find(&got); !assert.NoError(t, err) {
4040
return
4141
}
4242

models/migrations/v1_20/v250.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func ChangeContainerMetadataMultiArch(x *xorm.Engine) error {
104104

105105
// Convert to new metadata format
106106

107-
new := &MetadataNew{
107+
newMetadata := &MetadataNew{
108108
Type: old.Type,
109109
IsTagged: old.IsTagged,
110110
Platform: old.Platform,
@@ -119,7 +119,7 @@ func ChangeContainerMetadataMultiArch(x *xorm.Engine) error {
119119
Manifests: manifests,
120120
}
121121

122-
metadataJSON, err := json.Marshal(new)
122+
metadataJSON, err := json.Marshal(newMetadata)
123123
if err != nil {
124124
return err
125125
}

models/migrations/v1_23/v298.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_23 //nolint
5+
6+
import "xorm.io/xorm"
7+
8+
func DropWronglyCreatedTable(x *xorm.Engine) error {
9+
return x.DropTables("o_auth2_application")
10+
}

models/migrations/v1_6/v71.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ func AddScratchHash(x *xorm.Engine) error {
6161
if _, err := sess.ID(tfa.ID).Cols("scratch_salt, scratch_hash").Update(tfa); err != nil {
6262
return fmt.Errorf("couldn't add in scratch_hash and scratch_salt: %w", err)
6363
}
64-
6564
}
6665
}
6766

models/migrations/v1_9/v85.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ func HashAppToken(x *xorm.Engine) error {
8181
if _, err := sess.ID(token.ID).Cols("token_hash, token_salt, token_last_eight, sha1").Update(token); err != nil {
8282
return fmt.Errorf("couldn't add in sha1, token_hash, token_salt and token_last_eight: %w", err)
8383
}
84-
8584
}
8685
}
8786

models/organization/team.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,8 @@ func GetTeamIDsByNames(ctx context.Context, orgID int64, names []string, ignoreN
226226
if err != nil {
227227
if ignoreNonExistent {
228228
continue
229-
} else {
230-
return nil, err
231229
}
230+
return nil, err
232231
}
233232
ids = append(ids, u.ID)
234233
}

0 commit comments

Comments
 (0)