Skip to content

Commit 3792896

Browse files
authored
split setting.go to multiple files (#6154)
* split setting.go to multiple files * fix lint
1 parent faf446b commit 3792896

File tree

5 files changed

+433
-348
lines changed

5 files changed

+433
-348
lines changed

modules/setting/cron.go

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Copyright 2019 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 setting
6+
7+
import (
8+
"time"
9+
10+
"code.gitea.io/gitea/modules/log"
11+
)
12+
13+
var (
14+
15+
// Cron tasks
16+
Cron = struct {
17+
UpdateMirror struct {
18+
Enabled bool
19+
RunAtStart bool
20+
Schedule string
21+
} `ini:"cron.update_mirrors"`
22+
RepoHealthCheck struct {
23+
Enabled bool
24+
RunAtStart bool
25+
Schedule string
26+
Timeout time.Duration
27+
Args []string `delim:" "`
28+
} `ini:"cron.repo_health_check"`
29+
CheckRepoStats struct {
30+
Enabled bool
31+
RunAtStart bool
32+
Schedule string
33+
} `ini:"cron.check_repo_stats"`
34+
ArchiveCleanup struct {
35+
Enabled bool
36+
RunAtStart bool
37+
Schedule string
38+
OlderThan time.Duration
39+
} `ini:"cron.archive_cleanup"`
40+
SyncExternalUsers struct {
41+
Enabled bool
42+
RunAtStart bool
43+
Schedule string
44+
UpdateExisting bool
45+
} `ini:"cron.sync_external_users"`
46+
DeletedBranchesCleanup struct {
47+
Enabled bool
48+
RunAtStart bool
49+
Schedule string
50+
OlderThan time.Duration
51+
} `ini:"cron.deleted_branches_cleanup"`
52+
}{
53+
UpdateMirror: struct {
54+
Enabled bool
55+
RunAtStart bool
56+
Schedule string
57+
}{
58+
Enabled: true,
59+
RunAtStart: false,
60+
Schedule: "@every 10m",
61+
},
62+
RepoHealthCheck: struct {
63+
Enabled bool
64+
RunAtStart bool
65+
Schedule string
66+
Timeout time.Duration
67+
Args []string `delim:" "`
68+
}{
69+
Enabled: true,
70+
RunAtStart: false,
71+
Schedule: "@every 24h",
72+
Timeout: 60 * time.Second,
73+
Args: []string{},
74+
},
75+
CheckRepoStats: struct {
76+
Enabled bool
77+
RunAtStart bool
78+
Schedule string
79+
}{
80+
Enabled: true,
81+
RunAtStart: true,
82+
Schedule: "@every 24h",
83+
},
84+
ArchiveCleanup: struct {
85+
Enabled bool
86+
RunAtStart bool
87+
Schedule string
88+
OlderThan time.Duration
89+
}{
90+
Enabled: true,
91+
RunAtStart: true,
92+
Schedule: "@every 24h",
93+
OlderThan: 24 * time.Hour,
94+
},
95+
SyncExternalUsers: struct {
96+
Enabled bool
97+
RunAtStart bool
98+
Schedule string
99+
UpdateExisting bool
100+
}{
101+
Enabled: true,
102+
RunAtStart: false,
103+
Schedule: "@every 24h",
104+
UpdateExisting: true,
105+
},
106+
DeletedBranchesCleanup: struct {
107+
Enabled bool
108+
RunAtStart bool
109+
Schedule string
110+
OlderThan time.Duration
111+
}{
112+
Enabled: true,
113+
RunAtStart: true,
114+
Schedule: "@every 24h",
115+
OlderThan: 24 * time.Hour,
116+
},
117+
}
118+
)
119+
120+
func newCron() {
121+
if err := Cfg.Section("cron").MapTo(&Cron); err != nil {
122+
log.Fatal(4, "Failed to map Cron settings: %v", err)
123+
}
124+
}

modules/setting/git.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2019 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 setting
6+
7+
import (
8+
"time"
9+
10+
"code.gitea.io/git"
11+
"code.gitea.io/gitea/modules/log"
12+
version "github.com/mcuadros/go-version"
13+
)
14+
15+
var (
16+
// Git settings
17+
Git = struct {
18+
Version string `ini:"-"`
19+
DisableDiffHighlight bool
20+
MaxGitDiffLines int
21+
MaxGitDiffLineCharacters int
22+
MaxGitDiffFiles int
23+
GCArgs []string `delim:" "`
24+
Timeout struct {
25+
Default int
26+
Migrate int
27+
Mirror int
28+
Clone int
29+
Pull int
30+
GC int `ini:"GC"`
31+
} `ini:"git.timeout"`
32+
}{
33+
DisableDiffHighlight: false,
34+
MaxGitDiffLines: 1000,
35+
MaxGitDiffLineCharacters: 5000,
36+
MaxGitDiffFiles: 100,
37+
GCArgs: []string{},
38+
Timeout: struct {
39+
Default int
40+
Migrate int
41+
Mirror int
42+
Clone int
43+
Pull int
44+
GC int `ini:"GC"`
45+
}{
46+
Default: int(git.DefaultCommandExecutionTimeout / time.Second),
47+
Migrate: 600,
48+
Mirror: 300,
49+
Clone: 300,
50+
Pull: 300,
51+
GC: 60,
52+
},
53+
}
54+
)
55+
56+
func newGit() {
57+
if err := Cfg.Section("git").MapTo(&Git); err != nil {
58+
log.Fatal(4, "Failed to map Git settings: %v", err)
59+
}
60+
git.DefaultCommandExecutionTimeout = time.Duration(Git.Timeout.Default) * time.Second
61+
62+
binVersion, err := git.BinVersion()
63+
if err != nil {
64+
log.Fatal(4, "Error retrieving git version: %v", err)
65+
}
66+
67+
if version.Compare(binVersion, "2.9", ">=") {
68+
// Explicitly disable credential helper, otherwise Git credentials might leak
69+
git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "credential.helper=")
70+
}
71+
}

modules/setting/markup.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2019 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 setting
6+
7+
import (
8+
"regexp"
9+
"strings"
10+
11+
"code.gitea.io/gitea/modules/log"
12+
)
13+
14+
// ExternalMarkupParsers represents the external markup parsers
15+
var (
16+
ExternalMarkupParsers []MarkupParser
17+
)
18+
19+
// MarkupParser defines the external parser configured in ini
20+
type MarkupParser struct {
21+
Enabled bool
22+
MarkupName string
23+
Command string
24+
FileExtensions []string
25+
IsInputFile bool
26+
}
27+
28+
func newMarkup() {
29+
extensionReg := regexp.MustCompile(`\.\w`)
30+
for _, sec := range Cfg.Section("markup").ChildSections() {
31+
name := strings.TrimPrefix(sec.Name(), "markup.")
32+
if name == "" {
33+
log.Warn("name is empty, markup " + sec.Name() + "ignored")
34+
continue
35+
}
36+
37+
extensions := sec.Key("FILE_EXTENSIONS").Strings(",")
38+
var exts = make([]string, 0, len(extensions))
39+
for _, extension := range extensions {
40+
if !extensionReg.MatchString(extension) {
41+
log.Warn(sec.Name() + " file extension " + extension + " is invalid. Extension ignored")
42+
} else {
43+
exts = append(exts, extension)
44+
}
45+
}
46+
47+
if len(exts) == 0 {
48+
log.Warn(sec.Name() + " file extension is empty, markup " + name + " ignored")
49+
continue
50+
}
51+
52+
command := sec.Key("RENDER_COMMAND").MustString("")
53+
if command == "" {
54+
log.Warn(" RENDER_COMMAND is empty, markup " + name + " ignored")
55+
continue
56+
}
57+
58+
ExternalMarkupParsers = append(ExternalMarkupParsers, MarkupParser{
59+
Enabled: sec.Key("ENABLED").MustBool(false),
60+
MarkupName: name,
61+
FileExtensions: exts,
62+
Command: command,
63+
IsInputFile: sec.Key("IS_INPUT_FILE").MustBool(false),
64+
})
65+
}
66+
}

0 commit comments

Comments
 (0)