Skip to content

Commit 536ce37

Browse files
authored
Merge branch 'main' into fix-scroll
2 parents 8e1e431 + 9f3906b commit 536ce37

File tree

29 files changed

+292
-145
lines changed

29 files changed

+292
-145
lines changed

docs/content/doc/advanced/signing.en-us.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ ideal UI and therefore subject to change.
100100
**Since 1.17**, Gitea runs git in its own home directory `[git].HOME_PATH` (default to `%(APP_DATA_PATH)/home`)
101101
and uses its own config `{[git].HOME_PATH}/.gitconfig`.
102102
If you have your own customized git config for Gitea, you should set these configs in system git config (aka `/etc/gitconfig`)
103-
or the Gitea internal git config `{[git].HOME_PATH}/.gitconfig`.
104-
Related home files for git command (like `.gnupg`) should also be put in Gitea's git home directory `[git].HOME_PATH`.
105-
103+
or the Gitea internal git config `{[git].HOME_PATH}/.gitconfig`.
104+
Related home files for git command (like `.gnupg`) should also be put in Gitea's git home directory `[git].HOME_PATH`.
105+
If you like to keep the `.gnupg` directory outside of `{[git].HOME_PATH}/`, consider setting the `$GNUPGHOME` environment variable to your preferred location.
106106

107107
### `INITIAL_COMMIT`
108108

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ require (
8787
github.com/urfave/cli v1.22.9
8888
github.com/xanzy/go-gitlab v0.64.0
8989
github.com/yohcop/openid-go v1.0.0
90-
github.com/yuin/goldmark v1.4.12
90+
github.com/yuin/goldmark v1.4.13
9191
github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594
9292
github.com/yuin/goldmark-meta v1.1.0
9393
go.jolheiser.com/hcaptcha v0.0.4

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,8 +1550,8 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
15501550
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
15511551
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
15521552
github.com/yuin/goldmark v1.4.5/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg=
1553-
github.com/yuin/goldmark v1.4.12 h1:6hffw6vALvEDqJ19dOJvJKOoAOKe4NDaTqvd2sktGN0=
1554-
github.com/yuin/goldmark v1.4.12/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
1553+
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
1554+
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
15551555
github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594 h1:yHfZyN55+5dp1wG7wDKv8HQ044moxkyGq12KFFMFDxg=
15561556
github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594/go.mod h1:U9ihbh+1ZN7fR5Se3daSPoz1CGF9IYtSvWwVQtnzGHU=
15571557
github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUeiOUc=

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ var migrations = []Migration{
396396
NewMigration("Alter hook_task table TEXT fields to LONGTEXT", alterHookTaskTextFieldsToLongText),
397397
// v218 -> v219
398398
NewMigration("Improve Action table indices v2", improveActionTableIndices),
399+
// v219 -> v220
400+
NewMigration("Add sync_on_commit column to push_mirror table", addSyncOnCommitColForPushMirror),
399401
}
400402

401403
// GetCurrentDBVersion returns the current db version

models/migrations/v219.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
"time"
9+
10+
"code.gitea.io/gitea/models/repo"
11+
"code.gitea.io/gitea/modules/timeutil"
12+
"xorm.io/xorm"
13+
)
14+
15+
func addSyncOnCommitColForPushMirror(x *xorm.Engine) error {
16+
type PushMirror struct {
17+
ID int64 `xorm:"pk autoincr"`
18+
RepoID int64 `xorm:"INDEX"`
19+
Repo *repo.Repository `xorm:"-"`
20+
RemoteName string
21+
22+
SyncOnCommit bool `xorm:"NOT NULL DEFAULT true"`
23+
Interval time.Duration
24+
CreatedUnix timeutil.TimeStamp `xorm:"created"`
25+
LastUpdateUnix timeutil.TimeStamp `xorm:"INDEX last_update"`
26+
LastError string `xorm:"text"`
27+
}
28+
29+
return x.Sync2(new(PushMirror))
30+
}

models/repo/pushmirror.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type PushMirror struct {
2323
Repo *Repository `xorm:"-"`
2424
RemoteName string
2525

26+
SyncOnCommit bool `xorm:"NOT NULL DEFAULT true"`
2627
Interval time.Duration
2728
CreatedUnix timeutil.TimeStamp `xorm:"created"`
2829
LastUpdateUnix timeutil.TimeStamp `xorm:"INDEX last_update"`
@@ -93,6 +94,14 @@ func GetPushMirrorsByRepoID(repoID int64) ([]*PushMirror, error) {
9394
return mirrors, db.GetEngine(db.DefaultContext).Where("repo_id=?", repoID).Find(&mirrors)
9495
}
9596

97+
// GetPushMirrorsSyncedOnCommit returns push-mirrors for this repo that should be updated by new commits
98+
func GetPushMirrorsSyncedOnCommit(repoID int64) ([]*PushMirror, error) {
99+
mirrors := make([]*PushMirror, 0, 10)
100+
return mirrors, db.GetEngine(db.DefaultContext).
101+
Where("repo_id=? AND sync_on_commit=?", repoID, true).
102+
Find(&mirrors)
103+
}
104+
96105
// PushMirrorsIterate iterates all push-mirror repositories.
97106
func PushMirrorsIterate(limit int, f func(idx int, bean interface{}) error) error {
98107
return db.GetEngine(db.DefaultContext).

modules/mirror/mirror.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 mirror
6+
7+
import (
8+
"code.gitea.io/gitea/modules/graceful"
9+
"code.gitea.io/gitea/modules/log"
10+
"code.gitea.io/gitea/modules/queue"
11+
"code.gitea.io/gitea/modules/setting"
12+
)
13+
14+
var mirrorQueue queue.UniqueQueue
15+
16+
// SyncType type of sync request
17+
type SyncType int
18+
19+
const (
20+
// PullMirrorType for pull mirrors
21+
PullMirrorType SyncType = iota
22+
// PushMirrorType for push mirrors
23+
PushMirrorType
24+
)
25+
26+
// SyncRequest for the mirror queue
27+
type SyncRequest struct {
28+
Type SyncType
29+
ReferenceID int64 // RepoID for pull mirror, MirrorID for push mirror
30+
}
31+
32+
// StartSyncMirrors starts a go routine to sync the mirrors
33+
func StartSyncMirrors(queueHandle func(data ...queue.Data) []queue.Data) {
34+
if !setting.Mirror.Enabled {
35+
return
36+
}
37+
mirrorQueue = queue.CreateUniqueQueue("mirror", queueHandle, new(SyncRequest))
38+
39+
go graceful.GetManager().RunWithShutdownFns(mirrorQueue.Run)
40+
}
41+
42+
// AddPullMirrorToQueue adds repoID to mirror queue
43+
func AddPullMirrorToQueue(repoID int64) {
44+
addMirrorToQueue(PullMirrorType, repoID)
45+
}
46+
47+
// AddPushMirrorToQueue adds the push mirror to the queue
48+
func AddPushMirrorToQueue(mirrorID int64) {
49+
addMirrorToQueue(PushMirrorType, mirrorID)
50+
}
51+
52+
func addMirrorToQueue(syncType SyncType, referenceID int64) {
53+
if !setting.Mirror.Enabled {
54+
return
55+
}
56+
go func() {
57+
if err := PushToQueue(syncType, referenceID); err != nil {
58+
log.Error("Unable to push sync request for to the queue for pull mirror repo[%d]. Error: %v", referenceID, err)
59+
}
60+
}()
61+
}
62+
63+
// PushToQueue adds the sync request to the queue
64+
func PushToQueue(mirrorType SyncType, referenceID int64) error {
65+
return mirrorQueue.Push(&SyncRequest{
66+
Type: mirrorType,
67+
ReferenceID: referenceID,
68+
})
69+
}

modules/notification/mirror/mirror.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 mirror
6+
7+
import (
8+
repo_model "code.gitea.io/gitea/models/repo"
9+
user_model "code.gitea.io/gitea/models/user"
10+
"code.gitea.io/gitea/modules/log"
11+
mirror_module "code.gitea.io/gitea/modules/mirror"
12+
"code.gitea.io/gitea/modules/notification/base"
13+
"code.gitea.io/gitea/modules/repository"
14+
)
15+
16+
type mirrorNotifier struct {
17+
base.NullNotifier
18+
}
19+
20+
var _ base.Notifier = &mirrorNotifier{}
21+
22+
// NewNotifier create a new mirrorNotifier notifier
23+
func NewNotifier() base.Notifier {
24+
return &mirrorNotifier{}
25+
}
26+
27+
func (m *mirrorNotifier) NotifyPushCommits(_ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) {
28+
syncPushMirrorWithSyncOnCommit(repo.ID)
29+
}
30+
31+
func (m *mirrorNotifier) NotifySyncPushCommits(_ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) {
32+
syncPushMirrorWithSyncOnCommit(repo.ID)
33+
}
34+
35+
func syncPushMirrorWithSyncOnCommit(repoID int64) {
36+
pushMirrors, err := repo_model.GetPushMirrorsSyncedOnCommit(repoID)
37+
if err != nil {
38+
log.Error("repo_model.GetPushMirrorsSyncedOnCommit failed: %v", err)
39+
return
40+
}
41+
42+
for _, mirror := range pushMirrors {
43+
mirror_module.AddPushMirrorToQueue(mirror.ID)
44+
}
45+
}

modules/notification/notification.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"code.gitea.io/gitea/modules/notification/base"
1515
"code.gitea.io/gitea/modules/notification/indexer"
1616
"code.gitea.io/gitea/modules/notification/mail"
17+
"code.gitea.io/gitea/modules/notification/mirror"
1718
"code.gitea.io/gitea/modules/notification/ui"
1819
"code.gitea.io/gitea/modules/notification/webhook"
1920
"code.gitea.io/gitea/modules/repository"
@@ -37,6 +38,7 @@ func NewContext() {
3738
RegisterNotifier(indexer.NewNotifier())
3839
RegisterNotifier(webhook.NewNotifier())
3940
RegisterNotifier(action.NewNotifier())
41+
RegisterNotifier(mirror.NewNotifier())
4042
}
4143

4244
// NotifyCreateIssueComment notifies issue comment related message to notifiers

modules/setting/setting.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -840,16 +840,17 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
840840
SSH.StartBuiltinServer = false
841841
}
842842

843-
trustedUserCaKeys := sec.Key("SSH_TRUSTED_USER_CA_KEYS").Strings(",")
844-
for _, caKey := range trustedUserCaKeys {
843+
SSH.TrustedUserCAKeysFile = sec.Key("SSH_TRUSTED_USER_CA_KEYS_FILENAME").MustString(filepath.Join(SSH.RootPath, "gitea-trusted-user-ca-keys.pem"))
844+
845+
for _, caKey := range SSH.TrustedUserCAKeys {
845846
pubKey, _, _, _, err := gossh.ParseAuthorizedKey([]byte(caKey))
846847
if err != nil {
847848
log.Fatal("Failed to parse TrustedUserCaKeys: %s %v", caKey, err)
848849
}
849850

850851
SSH.TrustedUserCAKeysParsed = append(SSH.TrustedUserCAKeysParsed, pubKey)
851852
}
852-
if len(trustedUserCaKeys) > 0 {
853+
if len(SSH.TrustedUserCAKeys) > 0 {
853854
// Set the default as email,username otherwise we can leave it empty
854855
sec.Key("SSH_AUTHORIZED_PRINCIPALS_ALLOW").MustString("username,email")
855856
} else {
@@ -858,22 +859,6 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
858859

859860
SSH.AuthorizedPrincipalsAllow, SSH.AuthorizedPrincipalsEnabled = parseAuthorizedPrincipalsAllow(sec.Key("SSH_AUTHORIZED_PRINCIPALS_ALLOW").Strings(","))
860861

861-
if !SSH.Disabled && !SSH.StartBuiltinServer {
862-
if err := os.MkdirAll(SSH.RootPath, 0o700); err != nil {
863-
log.Fatal("Failed to create '%s': %v", SSH.RootPath, err)
864-
} else if err = os.MkdirAll(SSH.KeyTestPath, 0o644); err != nil {
865-
log.Fatal("Failed to create '%s': %v", SSH.KeyTestPath, err)
866-
}
867-
868-
if len(trustedUserCaKeys) > 0 && SSH.AuthorizedPrincipalsEnabled {
869-
fname := sec.Key("SSH_TRUSTED_USER_CA_KEYS_FILENAME").MustString(filepath.Join(SSH.RootPath, "gitea-trusted-user-ca-keys.pem"))
870-
if err := os.WriteFile(fname,
871-
[]byte(strings.Join(trustedUserCaKeys, "\n")), 0o600); err != nil {
872-
log.Fatal("Failed to create '%s': %v", fname, err)
873-
}
874-
}
875-
}
876-
877862
SSH.MinimumKeySizeCheck = sec.Key("MINIMUM_KEY_SIZE_CHECK").MustBool(SSH.MinimumKeySizeCheck)
878863
minimumKeySizes := Cfg.Section("ssh.minimum_key_sizes").Keys()
879864
for _, key := range minimumKeySizes {

0 commit comments

Comments
 (0)