Skip to content

Commit a822bba

Browse files
authored
Add default values for settings (#455)
* add default values for settings * more default values * more default settings and labels resource * mv locale to options
1 parent ec1fe11 commit a822bba

File tree

6 files changed

+154
-24
lines changed

6 files changed

+154
-24
lines changed

models/repo.go

+2
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,8 @@ func getRepoInitFile(tp, name string) ([]byte, error) {
843843
return options.Gitignore(cleanedName)
844844
case "license":
845845
return options.License(cleanedName)
846+
case "label":
847+
return options.Labels(cleanedName)
846848
default:
847849
return []byte{}, fmt.Errorf("Invalid init file type")
848850
}

modules/options/dynamic.go

+5
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ func License(name string) ([]byte, error) {
7676
return fileFromDir(path.Join("license", name))
7777
}
7878

79+
// Labels eads the content of a specific labels from static or custom path.
80+
func Labels(name string) ([]byte, error) {
81+
return fileFromDir(path.Join("label", name))
82+
}
83+
7984
// fileFromDir is a helper to read files from static or custom path.
8085
func fileFromDir(name string) ([]byte, error) {
8186
customPath := path.Join(setting.CustomPath, "options", name)

modules/options/static.go

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ func License(name string) ([]byte, error) {
7272
return fileFromDir(path.Join("license", name))
7373
}
7474

75+
// Labels eads the content of a specific labels from static or custom path.
76+
func Labels(name string) ([]byte, error) {
77+
return fileFromDir(path.Join("label", name))
78+
}
79+
7580
// fileFromDir is a helper to read files from bindata or custom path.
7681
func fileFromDir(name string) ([]byte, error) {
7782
customPath := path.Join(setting.CustomPath, "options", name)

modules/setting/defaults.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package setting
2+
3+
import (
4+
"strings"
5+
)
6+
7+
var (
8+
defaultLangs = strings.Split("en-US,zh-CN,zh-HK,zh-TW,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,ja-JP,es-ES,pt-BR,pl-PL,bg-BG,it-IT,fi-FI,tr-TR,cs-CZ,sr-SP,sv-SE,ko-KR", ",")
9+
defaultLangNames = strings.Split("English,简体中文,繁體中文(香港),繁體中文(台湾),Deutsch,Français,Nederlands,Latviešu,Русский,日本語,Español,Português do Brasil,Polski,български,Italiano,Suomalainen,Türkçe,čeština,Српски,Svenska,한국어", ",")
10+
)

modules/setting/setting.go

+132-24
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,21 @@ var (
104104
UseTiDB bool
105105

106106
// Webhook settings
107-
Webhook struct {
107+
Webhook = struct {
108108
QueueLength int
109109
DeliverTimeout int
110110
SkipTLSVerify bool
111111
Types []string
112112
PagingNum int
113+
}{
114+
QueueLength: 1000,
115+
DeliverTimeout: 5,
116+
SkipTLSVerify: false,
117+
PagingNum: 10,
113118
}
114119

115120
// Repository settings
116-
Repository struct {
121+
Repository = struct {
117122
AnsiCharset string
118123
ForcePrivate bool
119124
MaxCreationLimit int
@@ -136,12 +141,44 @@ var (
136141
FileMaxSize int64
137142
MaxFiles int
138143
} `ini:"-"`
144+
}{
145+
AnsiCharset: "",
146+
ForcePrivate: false,
147+
MaxCreationLimit: -1,
148+
MirrorQueueLength: 1000,
149+
PullRequestQueueLength: 1000,
150+
PreferredLicenses: []string{"Apache License 2.0,MIT License"},
151+
DisableHTTPGit: false,
152+
153+
// Repository editor settings
154+
Editor: struct {
155+
LineWrapExtensions []string
156+
PreviewableFileModes []string
157+
}{
158+
LineWrapExtensions: strings.Split(".txt,.md,.markdown,.mdown,.mkd,", ","),
159+
PreviewableFileModes: []string{"markdown"},
160+
},
161+
162+
// Repository upload settings
163+
Upload: struct {
164+
Enabled bool
165+
TempPath string
166+
AllowedTypes []string `delim:"|"`
167+
FileMaxSize int64
168+
MaxFiles int
169+
}{
170+
Enabled: true,
171+
TempPath: "data/tmp/uploads",
172+
AllowedTypes: []string{},
173+
FileMaxSize: 3,
174+
MaxFiles: 5,
175+
},
139176
}
140177
RepoRootPath string
141-
ScriptType string
178+
ScriptType = "bash"
142179

143180
// UI settings
144-
UI struct {
181+
UI = struct {
145182
ExplorePagingNum int
146183
IssuePagingNum int
147184
FeedMaxCommitNum int
@@ -157,13 +194,38 @@ var (
157194
User struct {
158195
RepoPagingNum int
159196
} `ini:"ui.user"`
197+
}{
198+
ExplorePagingNum: 20,
199+
IssuePagingNum: 10,
200+
FeedMaxCommitNum: 5,
201+
ThemeColorMetaTag: `#6cc644`,
202+
MaxDisplayFileSize: 8388608,
203+
Admin: struct {
204+
UserPagingNum int
205+
RepoPagingNum int
206+
NoticePagingNum int
207+
OrgPagingNum int
208+
}{
209+
UserPagingNum: 50,
210+
RepoPagingNum: 50,
211+
NoticePagingNum: 25,
212+
OrgPagingNum: 50,
213+
},
214+
User: struct {
215+
RepoPagingNum int
216+
}{
217+
RepoPagingNum: 15,
218+
},
160219
}
161220

162221
// Markdown sttings
163-
Markdown struct {
222+
Markdown = struct {
164223
EnableHardLineBreak bool
165224
CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"`
166225
FileExtensions []string
226+
}{
227+
EnableHardLineBreak: false,
228+
FileExtensions: strings.Split(".md,.markdown,.mdown,.mkd", ","),
167229
}
168230

169231
// Picture settings
@@ -198,7 +260,7 @@ var (
198260
CSRFCookieName = "_csrf"
199261

200262
// Cron tasks
201-
Cron struct {
263+
Cron = struct {
202264
UpdateMirror struct {
203265
Enabled bool
204266
RunAtStart bool
@@ -216,10 +278,37 @@ var (
216278
RunAtStart bool
217279
Schedule string
218280
} `ini:"cron.check_repo_stats"`
281+
}{
282+
UpdateMirror: struct {
283+
Enabled bool
284+
RunAtStart bool
285+
Schedule string
286+
}{
287+
Schedule: "@every 10m",
288+
},
289+
RepoHealthCheck: struct {
290+
Enabled bool
291+
RunAtStart bool
292+
Schedule string
293+
Timeout time.Duration
294+
Args []string `delim:" "`
295+
}{
296+
Schedule: "@every 24h",
297+
Timeout: 60 * time.Second,
298+
Args: []string{},
299+
},
300+
CheckRepoStats: struct {
301+
Enabled bool
302+
RunAtStart bool
303+
Schedule string
304+
}{
305+
RunAtStart: true,
306+
Schedule: "@every 24h",
307+
},
219308
}
220309

221310
// Git settings
222-
Git struct {
311+
Git = struct {
223312
DisableDiffHighlight bool
224313
MaxGitDiffLines int
225314
MaxGitDiffLineCharacters int
@@ -232,16 +321,39 @@ var (
232321
Pull int
233322
GC int `ini:"GC"`
234323
} `ini:"git.timeout"`
324+
}{
325+
DisableDiffHighlight: false,
326+
MaxGitDiffLines: 1000,
327+
MaxGitDiffLineCharacters: 500,
328+
MaxGitDiffFiles: 100,
329+
GCArgs: []string{},
330+
Timeout: struct {
331+
Migrate int
332+
Mirror int
333+
Clone int
334+
Pull int
335+
GC int `ini:"GC"`
336+
}{
337+
Migrate: 600,
338+
Mirror: 300,
339+
Clone: 300,
340+
Pull: 300,
341+
GC: 60,
342+
},
235343
}
236344

237345
// Mirror settings
238-
Mirror struct {
346+
Mirror = struct {
239347
DefaultInterval int
348+
}{
349+
DefaultInterval: 8,
240350
}
241351

242352
// API settings
243-
API struct {
353+
API = struct {
244354
MaxResponseItems int
355+
}{
356+
MaxResponseItems: 50,
245357
}
246358

247359
// I18n settings
@@ -470,11 +582,11 @@ please consider changing to GITEA_CUSTOM`)
470582
}
471583

472584
sec = Cfg.Section("security")
473-
InstallLock = sec.Key("INSTALL_LOCK").MustBool()
474-
SecretKey = sec.Key("SECRET_KEY").String()
475-
LogInRememberDays = sec.Key("LOGIN_REMEMBER_DAYS").MustInt()
476-
CookieUserName = sec.Key("COOKIE_USERNAME").String()
477-
CookieRememberName = sec.Key("COOKIE_REMEMBER_NAME").String()
585+
InstallLock = sec.Key("INSTALL_LOCK").MustBool(false)
586+
SecretKey = sec.Key("SECRET_KEY").MustString("!#@FDEWREWR&*(")
587+
LogInRememberDays = sec.Key("LOGIN_REMEMBER_DAYS").MustInt(7)
588+
CookieUserName = sec.Key("COOKIE_USERNAME").MustString("gitea_awesome")
589+
CookieRememberName = sec.Key("COOKIE_REMEMBER_NAME").MustString("gitea_incredible")
478590
ReverseProxyAuthUser = sec.Key("REVERSE_PROXY_AUTHENTICATION_USER").MustString("X-WEBAUTH-USER")
479591

480592
sec = Cfg.Section("attachment")
@@ -597,21 +709,17 @@ please consider changing to GITEA_CUSTOM`)
597709

598710
Langs = Cfg.Section("i18n").Key("LANGS").Strings(",")
599711
if len(Langs) == 0 {
600-
Langs = []string{
601-
"en-US",
602-
}
712+
Langs = defaultLangs
603713
}
604714
Names = Cfg.Section("i18n").Key("NAMES").Strings(",")
605715
if len(Names) == 0 {
606-
Names = []string{
607-
"English",
608-
}
716+
Names = defaultLangNames
609717
}
610718
dateLangs = Cfg.Section("i18n.datelang").KeysHash()
611719

612-
ShowFooterBranding = Cfg.Section("other").Key("SHOW_FOOTER_BRANDING").MustBool()
613-
ShowFooterVersion = Cfg.Section("other").Key("SHOW_FOOTER_VERSION").MustBool()
614-
ShowFooterTemplateLoadTime = Cfg.Section("other").Key("SHOW_FOOTER_TEMPLATE_LOAD_TIME").MustBool()
720+
ShowFooterBranding = Cfg.Section("other").Key("SHOW_FOOTER_BRANDING").MustBool(false)
721+
ShowFooterVersion = Cfg.Section("other").Key("SHOW_FOOTER_VERSION").MustBool(true)
722+
ShowFooterTemplateLoadTime = Cfg.Section("other").Key("SHOW_FOOTER_TEMPLATE_LOAD_TIME").MustBool(true)
615723

616724
HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt"))
617725
}
@@ -738,7 +846,7 @@ func newSessionService() {
738846
SessionConfig.ProviderConfig = strings.Trim(Cfg.Section("session").Key("PROVIDER_CONFIG").String(), "\" ")
739847
SessionConfig.CookieName = Cfg.Section("session").Key("COOKIE_NAME").MustString("i_like_gogits")
740848
SessionConfig.CookiePath = AppSubURL
741-
SessionConfig.Secure = Cfg.Section("session").Key("COOKIE_SECURE").MustBool()
849+
SessionConfig.Secure = Cfg.Section("session").Key("COOKIE_SECURE").MustBool(false)
742850
SessionConfig.Gclifetime = Cfg.Section("session").Key("GC_INTERVAL_TIME").MustInt64(86400)
743851
SessionConfig.Maxlifetime = Cfg.Section("session").Key("SESSION_LIFE_TIME").MustInt64(86400)
744852

File renamed without changes.

0 commit comments

Comments
 (0)