Skip to content

Commit d0a71be

Browse files
authored
Merge branch 'master' into fix/system_webhooks_menu
2 parents 5775cc9 + 84b147c commit d0a71be

File tree

11 files changed

+26
-23
lines changed

11 files changed

+26
-23
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

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

routers/admin/users.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func prepareUserInfo(ctx *context.Context) *models.User {
188188
_, err = models.GetTwoFactorByUID(u.ID)
189189
if err != nil {
190190
if !models.IsErrTwoFactorNotEnrolled(err) {
191-
ctx.InternalServerError(err)
191+
ctx.ServerError("IsErrTwoFactorNotEnrolled", err)
192192
return nil
193193
}
194194
ctx.Data["TwoFactorEnabled"] = false
@@ -268,7 +268,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
268268
return
269269
}
270270
if err = u.SetPassword(form.Password); err != nil {
271-
ctx.InternalServerError(err)
271+
ctx.ServerError("SetPassword", err)
272272
return
273273
}
274274
}
@@ -285,12 +285,12 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
285285
if form.Reset2FA {
286286
tf, err := models.GetTwoFactorByUID(u.ID)
287287
if err != nil && !models.IsErrTwoFactorNotEnrolled(err) {
288-
ctx.InternalServerError(err)
288+
ctx.ServerError("GetTwoFactorByUID", err)
289289
return
290290
}
291291

292292
if err = models.DeleteTwoFactorByID(tf.ID, u.ID); err != nil {
293-
ctx.InternalServerError(err)
293+
ctx.ServerError("DeleteTwoFactorByID", err)
294294
return
295295
}
296296
}

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/repo/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ func ViewIssue(ctx *context.Context) {
11171117
iw.IssueID = issue.ID
11181118
iw.IsWatching, err = models.CheckIssueWatch(ctx.User, issue)
11191119
if err != nil {
1120-
ctx.InternalServerError(err)
1120+
ctx.ServerError("CheckIssueWatch", err)
11211121
return
11221122
}
11231123
}

routers/repo/projects.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func DeleteProjectBoard(ctx *context.Context) {
355355

356356
pb, err := models.GetProjectBoard(ctx.ParamsInt64(":boardID"))
357357
if err != nil {
358-
ctx.InternalServerError(err)
358+
ctx.ServerError("GetProjectBoard", err)
359359
return
360360
}
361361
if pb.ProjectID != ctx.ParamsInt64(":id") {
@@ -445,7 +445,7 @@ func EditProjectBoardTitle(ctx *context.Context, form auth.EditProjectBoardTitle
445445

446446
board, err := models.GetProjectBoard(ctx.ParamsInt64(":boardID"))
447447
if err != nil {
448-
ctx.InternalServerError(err)
448+
ctx.ServerError("GetProjectBoard", err)
449449
return
450450
}
451451
if board.ProjectID != ctx.ParamsInt64(":id") {

routers/repo/pull.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,11 +713,11 @@ func UpdatePullRequest(ctx *context.Context) {
713713
}
714714

715715
if err := issue.PullRequest.LoadBaseRepo(); err != nil {
716-
ctx.InternalServerError(err)
716+
ctx.ServerError("LoadBaseRepo", err)
717717
return
718718
}
719719
if err := issue.PullRequest.LoadHeadRepo(); err != nil {
720-
ctx.InternalServerError(err)
720+
ctx.ServerError("LoadHeadRepo", err)
721721
return
722722
}
723723

routers/routes/recovery.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@ func (d *dataStore) GetData() map[string]interface{} {
2929
// Although similar to macaron.Recovery() the main difference is that this error will be created
3030
// with the gitea 500 page.
3131
func Recovery() func(next http.Handler) http.Handler {
32-
var isDevelopment = setting.RunMode != "prod"
3332
return func(next http.Handler) http.Handler {
3433
rnd := render.New(render.Options{
3534
Extensions: []string{".tmpl"},
3635
Directory: "templates",
3736
Funcs: templates.NewFuncMap(),
3837
Asset: templates.GetAsset,
3938
AssetNames: templates.GetAssetNames,
40-
IsDevelopment: isDevelopment,
39+
IsDevelopment: !setting.IsProd(),
4140
})
4241

4342
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
@@ -50,10 +49,10 @@ func Recovery() func(next http.Handler) http.Handler {
5049
if err := recover(); err != nil {
5150
combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, string(log.Stack(2)))
5251
log.Error(combinedErr)
53-
if isDevelopment {
54-
http.Error(w, combinedErr, 500)
55-
} else {
52+
if setting.IsProd() {
5653
http.Error(w, http.StatusText(500), 500)
54+
} else {
55+
http.Error(w, combinedErr, 500)
5756
}
5857
}
5958
}()
@@ -94,7 +93,7 @@ func Recovery() func(next http.Handler) http.Handler {
9493

9594
w.Header().Set(`X-Frame-Options`, `SAMEORIGIN`)
9695

97-
if setting.RunMode != "prod" {
96+
if !setting.IsProd() {
9897
store.Data["ErrorMsg"] = combinedErr
9998
}
10099
err = rnd.HTML(w, 500, "status/500", templates.BaseVars().Merge(store.Data))

0 commit comments

Comments
 (0)