Skip to content

Commit a4797b4

Browse files
committed
Merge remote-tracking branch 'giteaoffical/main'
* giteaoffical/main: fix: PR status layout on mobile (go-gitea#21547) Make rss/atom identifier globally unique (go-gitea#21550) Fix UI column width, button overflow Fomantic's grid (go-gitea#21559) Localize time units on activity heatmap (go-gitea#21570) Use right syntax for symbolic-ref command (go-gitea#21577) Update JS dependencies and misc tweaks (go-gitea#21583) Add index for hook_task table (go-gitea#21545) Revert: auto generate INTERNAL_TOKEN (go-gitea#21608)
2 parents 60a456d + cd5c067 commit a4797b4

32 files changed

+1016
-852
lines changed

.drone.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ steps:
561561

562562
# TODO: We should probably build all dependencies into a test image
563563
- name: test-e2e
564-
image: mcr.microsoft.com/playwright:v1.27.0-focal
564+
image: mcr.microsoft.com/playwright:v1.27.1-focal
565565
commands:
566566
- curl -sLO https://go.dev/dl/go1.19.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.19.linux-amd64.tar.gz
567567
- groupadd --gid 1001 gitea && useradd -m --gid 1001 --uid 1001 gitea

.eslintrc.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ rules:
254254
no-irregular-whitespace: [2]
255255
no-iterator: [2]
256256
no-label-var: [2]
257-
no-labels: [2]
257+
no-labels: [0]
258258
no-lone-blocks: [2]
259259
no-lonely-if: [0]
260260
no-loop-func: [0]
@@ -333,7 +333,7 @@ rules:
333333
no-void: [2]
334334
no-warning-comments: [0]
335335
no-whitespace-before-property: [2]
336-
no-with: [2]
336+
no-with: [0]
337337
nonblock-statement-body-position: [2]
338338
object-curly-newline: [0]
339339
object-curly-spacing: [2, never]
@@ -378,11 +378,11 @@ rules:
378378
sonarjs/no-duplicated-branches: [0]
379379
sonarjs/no-element-overwrite: [2]
380380
sonarjs/no-empty-collection: [2]
381-
sonarjs/no-extra-arguments: [0]
381+
sonarjs/no-extra-arguments: [2]
382382
sonarjs/no-gratuitous-expressions: [2]
383383
sonarjs/no-identical-conditions: [2]
384-
sonarjs/no-identical-expressions: [0]
385-
sonarjs/no-identical-functions: [0]
384+
sonarjs/no-identical-expressions: [2]
385+
sonarjs/no-identical-functions: [2, 5]
386386
sonarjs/no-ignored-return: [2]
387387
sonarjs/no-inverted-boolean-check: [2]
388388
sonarjs/no-nested-switch: [0]
@@ -394,7 +394,7 @@ rules:
394394
sonarjs/no-small-switch: [0]
395395
sonarjs/no-unused-collection: [2]
396396
sonarjs/no-use-of-empty-return-value: [2]
397-
sonarjs/no-useless-catch: [0]
397+
sonarjs/no-useless-catch: [2]
398398
sonarjs/non-existent-operator: [2]
399399
sonarjs/prefer-immediate-return: [0]
400400
sonarjs/prefer-object-literal: [0]

.stylelintrc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ rules:
1616
declaration-empty-line-before: null
1717
function-no-unknown: null
1818
hue-degree-notation: null
19+
import-notation: string
1920
indentation: 2
2021
max-line-length: null
2122
no-descending-specificity: null

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ var migrations = []Migration{
423423
NewMigration("Update counts of all open milestones", updateOpenMilestoneCounts),
424424
// v230 -> v231
425425
NewMigration("Add ConfidentialClient column (default true) to OAuth2Application table", addConfidentialClientColumnToOAuth2ApplicationTable),
426+
// v231 -> v232
427+
NewMigration("Add index for hook_task", addIndexForHookTask),
426428
}
427429

428430
// GetCurrentDBVersion returns the current db version

models/migrations/v231.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"xorm.io/xorm"
9+
)
10+
11+
func addIndexForHookTask(x *xorm.Engine) error {
12+
type HookTask struct {
13+
ID int64 `xorm:"pk autoincr"`
14+
HookID int64 `xorm:"index"`
15+
UUID string `xorm:"unique"`
16+
}
17+
18+
return x.Sync(new(HookTask))
19+
}

models/webhook/hooktask.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ type HookResponse struct {
103103

104104
// HookTask represents a hook task.
105105
type HookTask struct {
106-
ID int64 `xorm:"pk autoincr"`
107-
HookID int64
108-
UUID string
106+
ID int64 `xorm:"pk autoincr"`
107+
HookID int64 `xorm:"index"`
108+
UUID string `xorm:"unique"`
109109
api.Payloader `xorm:"-"`
110110
PayloadContent string `xorm:"LONGTEXT"`
111111
EventType HookEventType
@@ -270,7 +270,7 @@ func CleanupHookTaskTable(ctx context.Context, cleanupType HookTaskCleanupType,
270270
return db.ErrCancelledf("Before deleting hook_task records for hook id %d", hookID)
271271
default:
272272
}
273-
if err = deleteDeliveredHookTasksByWebhook(hookID, numberToKeep); err != nil {
273+
if err = deleteDeliveredHookTasksByWebhook(ctx, hookID, numberToKeep); err != nil {
274274
return err
275275
}
276276
}
@@ -279,10 +279,10 @@ func CleanupHookTaskTable(ctx context.Context, cleanupType HookTaskCleanupType,
279279
return nil
280280
}
281281

282-
func deleteDeliveredHookTasksByWebhook(hookID int64, numberDeliveriesToKeep int) error {
282+
func deleteDeliveredHookTasksByWebhook(ctx context.Context, hookID int64, numberDeliveriesToKeep int) error {
283283
log.Trace("Deleting hook_task rows for webhook %d, keeping the most recent %d deliveries", hookID, numberDeliveriesToKeep)
284284
deliveryDates := make([]int64, 0, 10)
285-
err := db.GetEngine(db.DefaultContext).Table("hook_task").
285+
err := db.GetEngine(ctx).Table("hook_task").
286286
Where("hook_task.hook_id = ? AND hook_task.is_delivered = ? AND hook_task.delivered is not null", hookID, true).
287287
Cols("hook_task.delivered").
288288
Join("INNER", "webhook", "hook_task.hook_id = webhook.id").
@@ -294,7 +294,7 @@ func deleteDeliveredHookTasksByWebhook(hookID int64, numberDeliveriesToKeep int)
294294
}
295295

296296
if len(deliveryDates) > 0 {
297-
deletes, err := db.GetEngine(db.DefaultContext).
297+
deletes, err := db.GetEngine(ctx).
298298
Where("hook_id = ? and is_delivered = ? and delivered <= ?", hookID, true, deliveryDates[0]).
299299
Delete(new(HookTask))
300300
if err != nil {

modules/doctor/heads.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func synchronizeRepoHeads(ctx context.Context, logger log.Logger, autofix bool)
4949
}
5050

5151
// otherwise, let's try fixing HEAD
52-
err := git.NewCommand(ctx, "symbolic-ref").AddDashesAndList("HEAD", repo.DefaultBranch).Run(runOpts)
52+
err := git.NewCommand(ctx, "symbolic-ref").AddDashesAndList("HEAD", git.BranchPrefix+repo.DefaultBranch).Run(runOpts)
5353
if err != nil {
5454
logger.Warn("Failed to fix HEAD for %s/%s: %v", repo.OwnerName, repo.Name, err)
5555
return nil

modules/setting/setting.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
"code.gitea.io/gitea/modules/container"
25+
"code.gitea.io/gitea/modules/generate"
2526
"code.gitea.io/gitea/modules/json"
2627
"code.gitea.io/gitea/modules/log"
2728
"code.gitea.io/gitea/modules/user"
@@ -962,6 +963,11 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
962963
SuccessfulTokensCacheSize = sec.Key("SUCCESSFUL_TOKENS_CACHE_SIZE").MustInt(20)
963964

964965
InternalToken = loadSecret(sec, "INTERNAL_TOKEN_URI", "INTERNAL_TOKEN")
966+
if InstallLock && InternalToken == "" {
967+
// if Gitea has been installed but the InternalToken hasn't been generated (upgrade from an old release), we should generate
968+
// some users do cluster deployment, they still depend on this auto-generating behavior.
969+
generateSaveInternalToken()
970+
}
965971

966972
cfgdata := sec.Key("PASSWORD_COMPLEXITY").Strings(",")
967973
if len(cfgdata) == 0 {
@@ -1182,6 +1188,19 @@ func loadSecret(sec *ini.Section, uriKey, verbatimKey string) string {
11821188
}
11831189
}
11841190

1191+
// generateSaveInternalToken generates and saves the internal token to app.ini
1192+
func generateSaveInternalToken() {
1193+
token, err := generate.NewInternalToken()
1194+
if err != nil {
1195+
log.Fatal("Error generate internal token: %v", err)
1196+
}
1197+
1198+
InternalToken = token
1199+
CreateOrAppendToCustomConf("security.INTERNAL_TOKEN", func(cfg *ini.File) {
1200+
cfg.Section("security").Key("INTERNAL_TOKEN").SetValue(token)
1201+
})
1202+
}
1203+
11851204
// MakeAbsoluteAssetURL returns the absolute asset url prefix without a trailing slash
11861205
func MakeAbsoluteAssetURL(appURL, staticURLPrefix string) string {
11871206
parsedPrefix, err := url.Parse(strings.TrimSuffix(staticURLPrefix, "/"))

0 commit comments

Comments
 (0)