Skip to content

Commit 8845c23

Browse files
authored
Merge branch 'master' into lunny/downloader_gogs
2 parents 0dda8a9 + 6eee9f0 commit 8845c23

File tree

19 files changed

+165
-155
lines changed

19 files changed

+165
-155
lines changed

cmd/serv.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func setup(logPath string, debug bool) {
5858
}
5959
setting.NewContext()
6060
if debug {
61-
setting.ProdMode = false
61+
setting.RunMode = "dev"
6262
}
6363
}
6464

@@ -76,7 +76,7 @@ func fail(userMessage, logMessage string, args ...interface{}) {
7676
fmt.Fprintln(os.Stderr, "Gitea:", userMessage)
7777

7878
if len(logMessage) > 0 {
79-
if !setting.ProdMode {
79+
if !setting.IsProd() {
8080
fmt.Fprintf(os.Stderr, logMessage+"\n", args...)
8181
}
8282
}

models/models.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ func NewTestEngine() (err error) {
175175
}
176176

177177
x.SetMapper(names.GonicMapper{})
178-
x.SetLogger(NewXORMLogger(!setting.ProdMode))
179-
x.ShowSQL(!setting.ProdMode)
178+
x.SetLogger(NewXORMLogger(!setting.IsProd()))
179+
x.ShowSQL(!setting.IsProd())
180180
return x.StoreEngine("InnoDB").Sync2(tables...)
181181
}
182182

models/webhook.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -400,20 +400,6 @@ func GetWebhooksByOrgID(orgID int64, listOptions ListOptions) ([]*Webhook, error
400400
return ws, sess.Find(&ws, &Webhook{OrgID: orgID})
401401
}
402402

403-
// GetDefaultWebhook returns admin-default webhook by given ID.
404-
func GetDefaultWebhook(id int64) (*Webhook, error) {
405-
webhook := &Webhook{ID: id}
406-
has, err := x.
407-
Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, false).
408-
Get(webhook)
409-
if err != nil {
410-
return nil, err
411-
} else if !has {
412-
return nil, ErrWebhookNotExist{id}
413-
}
414-
return webhook, nil
415-
}
416-
417403
// GetDefaultWebhooks returns all admin-default webhooks.
418404
func GetDefaultWebhooks() ([]*Webhook, error) {
419405
return getDefaultWebhooks(x)
@@ -426,11 +412,11 @@ func getDefaultWebhooks(e Engine) ([]*Webhook, error) {
426412
Find(&webhooks)
427413
}
428414

429-
// GetSystemWebhook returns admin system webhook by given ID.
430-
func GetSystemWebhook(id int64) (*Webhook, error) {
415+
// GetSystemOrDefaultWebhook returns admin system or default webhook by given ID.
416+
func GetSystemOrDefaultWebhook(id int64) (*Webhook, error) {
431417
webhook := &Webhook{ID: id}
432418
has, err := x.
433-
Where("repo_id=? AND org_id=? AND is_system_webhook=?", 0, 0, true).
419+
Where("repo_id=? AND org_id=?", 0, 0).
434420
Get(webhook)
435421
if err != nil {
436422
return nil, err

modules/auth/sso/sspi_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (s *SSPI) Init() error {
5656
Funcs: templates.NewFuncMap(),
5757
Asset: templates.GetAsset,
5858
AssetNames: templates.GetAssetNames,
59-
IsDevelopment: setting.RunMode != "prod",
59+
IsDevelopment: !setting.IsProd(),
6060
})
6161
return nil
6262
}

modules/httpcache/httpcache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
// GetCacheControl returns a suitable "Cache-Control" header value
1919
func GetCacheControl() string {
20-
if setting.RunMode == "dev" {
20+
if !setting.IsProd() {
2121
return "no-store"
2222
}
2323
return "private, max-age=" + strconv.FormatInt(int64(setting.StaticCacheTime.Seconds()), 10)

modules/setting/setting.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ var (
376376
CustomConf string
377377
PIDFile = "/run/gitea.pid"
378378
WritePIDFile bool
379-
ProdMode bool
380379
RunMode string
381380
RunUser string
382381
IsWindows bool
@@ -388,6 +387,11 @@ var (
388387
UILocation = time.Local
389388
)
390389

390+
// IsProd if it's a production mode
391+
func IsProd() bool {
392+
return strings.EqualFold(RunMode, "prod")
393+
}
394+
391395
func getAppPath() (string, error) {
392396
var appPath string
393397
var err error

options/locale/locale_en-US.ini

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,8 +2002,7 @@ dashboard = Dashboard
20022002
users = User Accounts
20032003
organizations = Organizations
20042004
repositories = Repositories
2005-
hooks = Default Webhooks
2006-
systemhooks = System Webhooks
2005+
hooks = Webhooks
20072006
authentication = Authentication Sources
20082007
emails = User Emails
20092008
config = Configuration
@@ -2153,11 +2152,13 @@ repos.forks = Forks
21532152
repos.issues = Issues
21542153
repos.size = Size
21552154

2156-
hooks.desc = Webhooks automatically make HTTP POST requests to a server when certain Gitea events trigger. Webhooks defined here are defaults and will be copied into all new repositories. Read more in the <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">webhooks guide</a>.
2157-
hooks.add_webhook = Add Default Webhook
2158-
hooks.update_webhook = Update Default Webhook
2155+
defaulthooks = Default Webhooks
2156+
defaulthooks.desc = Webhooks automatically make HTTP POST requests to a server when certain Gitea events trigger. Webhooks defined here are defaults and will be copied into all new repositories. Read more in the <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">webhooks guide</a>.
2157+
defaulthooks.add_webhook = Add Default Webhook
2158+
defaulthooks.update_webhook = Update Default Webhook
21592159

2160-
systemhooks.desc = Webhooks automatically make HTTP POST requests to a server when certain Gitea events trigger. Webhooks defined will act on all repositories on the system, so please consider any performance implications this may have. Read more in the <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">webhooks guide</a>.
2160+
systemhooks = System Webhooks
2161+
systemhooks.desc = Webhooks automatically make HTTP POST requests to a server when certain Gitea events trigger. Webhooks defined here will act on all repositories on the system, so please consider any performance implications this may have. Read more in the <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">webhooks guide</a>.
21612162
systemhooks.add_webhook = Add System Webhook
21622163
systemhooks.update_webhook = Update System Webhook
21632164

routers/admin/hooks.go

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,41 @@ const (
1818

1919
// DefaultOrSystemWebhooks renders both admin default and system webhook list pages
2020
func DefaultOrSystemWebhooks(ctx *context.Context) {
21-
var ws []*models.Webhook
2221
var err error
2322

24-
// Are we looking at default webhooks?
25-
if ctx.Params(":configType") == "hooks" {
26-
ctx.Data["Title"] = ctx.Tr("admin.hooks")
27-
ctx.Data["Description"] = ctx.Tr("admin.hooks.desc")
28-
ctx.Data["PageIsAdminHooks"] = true
29-
ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/hooks"
30-
ws, err = models.GetDefaultWebhooks()
31-
} else {
32-
ctx.Data["Title"] = ctx.Tr("admin.systemhooks")
33-
ctx.Data["Description"] = ctx.Tr("admin.systemhooks.desc")
34-
ctx.Data["PageIsAdminSystemHooks"] = true
35-
ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/system-hooks"
36-
ws, err = models.GetSystemWebhooks()
23+
ctx.Data["PageIsAdminSystemHooks"] = true
24+
ctx.Data["PageIsAdminDefaultHooks"] = true
25+
26+
def := make(map[string]interface{}, len(ctx.Data))
27+
sys := make(map[string]interface{}, len(ctx.Data))
28+
for k, v := range ctx.Data {
29+
def[k] = v
30+
sys[k] = v
31+
}
32+
33+
sys["Title"] = ctx.Tr("admin.systemhooks")
34+
sys["Description"] = ctx.Tr("admin.systemhooks.desc")
35+
sys["Webhooks"], err = models.GetSystemWebhooks()
36+
sys["BaseLink"] = setting.AppSubURL + "/admin/hooks"
37+
sys["BaseLinkNew"] = setting.AppSubURL + "/admin/system-hooks"
38+
if err != nil {
39+
ctx.ServerError("GetWebhooksAdmin", err)
40+
return
3741
}
3842

43+
def["Title"] = ctx.Tr("admin.defaulthooks")
44+
def["Description"] = ctx.Tr("admin.defaulthooks.desc")
45+
def["Webhooks"], err = models.GetDefaultWebhooks()
46+
def["BaseLink"] = setting.AppSubURL + "/admin/hooks"
47+
def["BaseLinkNew"] = setting.AppSubURL + "/admin/default-hooks"
3948
if err != nil {
4049
ctx.ServerError("GetWebhooksAdmin", err)
4150
return
4251
}
4352

44-
ctx.Data["Webhooks"] = ws
53+
ctx.Data["DefaultWebhooks"] = def
54+
ctx.Data["SystemWebhooks"] = sys
55+
4556
ctx.HTML(200, tplAdminHooks)
4657
}
4758

@@ -53,14 +64,7 @@ func DeleteDefaultOrSystemWebhook(ctx *context.Context) {
5364
ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
5465
}
5566

56-
// Are we looking at default webhooks?
57-
if ctx.Params(":configType") == "hooks" {
58-
ctx.JSON(200, map[string]interface{}{
59-
"redirect": setting.AppSubURL + "/admin/hooks",
60-
})
61-
} else {
62-
ctx.JSON(200, map[string]interface{}{
63-
"redirect": setting.AppSubURL + "/admin/system-hooks",
64-
})
65-
}
67+
ctx.JSON(200, map[string]interface{}{
68+
"redirect": setting.AppSubURL + "/admin/hooks",
69+
})
6670
}

routers/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func checkRunMode() {
5050
default:
5151
macaron.Env = macaron.PROD
5252
macaron.ColorLog = false
53-
setting.ProdMode = true
53+
git.Debug = false
5454
}
5555
log.Info("Run Mode: %s", strings.Title(macaron.Env))
5656
}

routers/org/setting.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ func Webhooks(ctx *context.Context) {
173173
ctx.Data["Title"] = ctx.Tr("org.settings")
174174
ctx.Data["PageIsSettingsHooks"] = true
175175
ctx.Data["BaseLink"] = ctx.Org.OrgLink + "/settings/hooks"
176+
ctx.Data["BaseLinkNew"] = ctx.Org.OrgLink + "/settings/hooks"
176177
ctx.Data["Description"] = ctx.Tr("org.settings.hooks_desc")
177178

178179
ws, err := models.GetWebhooksByOrgID(ctx.Org.Organization.ID, models.ListOptions{})

0 commit comments

Comments
 (0)