Browse Source

Refactor editorconfig middleware

Andrey Nering 3 years ago
parent
commit
bd898a10f8
5 changed files with 8 additions and 27 deletions
  1. 7 6
      cmd/web.go
  2. 0 5
      routers/repo/commit.go
  3. 1 1
      routers/repo/middlewares.go
  4. 0 10
      routers/repo/pull.go
  5. 0 5
      routers/repo/view.go

+ 7 - 6
cmd/web.go

@@ -520,7 +520,8 @@ func runWeb(ctx *cli.Context) error {
520 520
 			ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
521 521
 		})
522 522
 
523
-		m.Combo("/compare/*", repo.MustAllowPulls).Get(repo.CompareAndPullRequest).
523
+		m.Combo("/compare/*", repo.MustAllowPulls, repo.SetEditorconfigIfExists).
524
+			Get(repo.CompareAndPullRequest).
524 525
 			Post(bindIgnErr(auth.CreateIssueForm{}), repo.CompareAndPullRequestPost)
525 526
 
526 527
 		m.Group("", func() {
@@ -579,15 +580,15 @@ func runWeb(ctx *cli.Context) error {
579 580
 
580 581
 		m.Group("/pulls/:index", func() {
581 582
 			m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
582
-			m.Get("/files", context.RepoRef(), repo.ViewPullFiles)
583
+			m.Get("/files", context.RepoRef(), repo.SetEditorconfigIfExists, repo.ViewPullFiles)
583 584
 			m.Post("/merge", reqRepoWriter, repo.MergePullRequest)
584 585
 		}, repo.MustAllowPulls)
585 586
 
586 587
 		m.Group("", func() {
587
-			m.Get("/src/*", repo.Home)
588
+			m.Get("/src/*", repo.SetEditorconfigIfExists, repo.Home)
588 589
 			m.Get("/raw/*", repo.SingleDownload)
589 590
 			m.Get("/commits/*", repo.RefCommits)
590
-			m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.Diff)
591
+			m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.SetEditorconfigIfExists, repo.Diff)
591 592
 			m.Get("/forks", repo.Forks)
592 593
 		}, context.RepoRef())
593 594
 		m.Get("/commit/:sha([a-f0-9]{7,40})\\.:ext(patch|diff)", repo.RawDiff)
@@ -601,8 +602,8 @@ func runWeb(ctx *cli.Context) error {
601 602
 
602 603
 	m.Group("/:username", func() {
603 604
 		m.Group("/:reponame", func() {
604
-			m.Get("", repo.Home)
605
-			m.Get("\\.git$", repo.Home)
605
+			m.Get("", repo.SetEditorconfigIfExists, repo.Home)
606
+			m.Get("\\.git$", repo.SetEditorconfigIfExists, repo.Home)
606 607
 		}, ignSignIn, context.RepoAssignment(true), context.RepoRef())
607 608
 
608 609
 		m.Group("/:reponame", func() {

+ 0 - 5
routers/repo/commit.go

@@ -179,11 +179,6 @@ func Diff(ctx *context.Context) {
179 179
 		}
180 180
 	}
181 181
 
182
-	setEditorconfigIfExists(ctx)
183
-	if ctx.Written() {
184
-		return
185
-	}
186
-
187 182
 	ctx.Data["CommitID"] = commitID
188 183
 	ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
189 184
 	ctx.Data["Username"] = userName

+ 1 - 1
routers/repo/middlewares.go

@@ -8,7 +8,7 @@ import (
8 8
 	"github.com/gogits/git-module"
9 9
 )
10 10
 
11
-func setEditorconfigIfExists(ctx *context.Context) {
11
+func SetEditorconfigIfExists(ctx *context.Context) {
12 12
 	ec, err := ctx.Repo.GetEditorconfig()
13 13
 
14 14
 	if err != nil && !git.IsErrNotExist(err) {

+ 0 - 10
routers/repo/pull.go

@@ -368,11 +368,6 @@ func ViewPullFiles(ctx *context.Context) {
368 368
 		return
369 369
 	}
370 370
 
371
-	setEditorconfigIfExists(ctx)
372
-	if ctx.Written() {
373
-		return
374
-	}
375
-
376 371
 	headTarget := path.Join(pull.HeadUserName, pull.HeadRepo.Name)
377 372
 	ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
378 373
 	ctx.Data["Username"] = pull.HeadUserName
@@ -625,11 +620,6 @@ func CompareAndPullRequest(ctx *context.Context) {
625 620
 		}
626 621
 	}
627 622
 
628
-	setEditorconfigIfExists(ctx)
629
-	if ctx.Written() {
630
-		return
631
-	}
632
-
633 623
 	ctx.HTML(200, COMPARE_PULL)
634 624
 }
635 625
 

+ 0 - 5
routers/repo/view.go

@@ -245,11 +245,6 @@ func Home(ctx *context.Context) {
245 245
 		return
246 246
 	}
247 247
 
248
-	setEditorconfigIfExists(ctx)
249
-	if ctx.Written() {
250
-		return
251
-	}
252
-
253 248
 	var treeNames []string
254 249
 	paths := make([]string, 0, 5)
255 250
 	if len(ctx.Repo.TreePath) > 0 {