Skip to content

Commit a0e54c0

Browse files
authored
Merge pull request #84 from andreynering/gitea/fix-500-on-invalid-editorconfig
Refactor editorconfig middleware
2 parents 91b589f + bd898a1 commit a0e54c0

File tree

5 files changed

+8
-27
lines changed

5 files changed

+8
-27
lines changed

cmd/web.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,8 @@ func runWeb(ctx *cli.Context) error {
520520
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
521521
})
522522

523-
m.Combo("/compare/*", repo.MustAllowPulls).Get(repo.CompareAndPullRequest).
523+
m.Combo("/compare/*", repo.MustAllowPulls, repo.SetEditorconfigIfExists).
524+
Get(repo.CompareAndPullRequest).
524525
Post(bindIgnErr(auth.CreateIssueForm{}), repo.CompareAndPullRequestPost)
525526

526527
m.Group("", func() {
@@ -579,15 +580,15 @@ func runWeb(ctx *cli.Context) error {
579580

580581
m.Group("/pulls/:index", func() {
581582
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)
583584
m.Post("/merge", reqRepoWriter, repo.MergePullRequest)
584585
}, repo.MustAllowPulls)
585586

586587
m.Group("", func() {
587-
m.Get("/src/*", repo.Home)
588+
m.Get("/src/*", repo.SetEditorconfigIfExists, repo.Home)
588589
m.Get("/raw/*", repo.SingleDownload)
589590
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)
591592
m.Get("/forks", repo.Forks)
592593
}, context.RepoRef())
593594
m.Get("/commit/:sha([a-f0-9]{7,40})\\.:ext(patch|diff)", repo.RawDiff)
@@ -601,8 +602,8 @@ func runWeb(ctx *cli.Context) error {
601602

602603
m.Group("/:username", func() {
603604
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)
606607
}, ignSignIn, context.RepoAssignment(true), context.RepoRef())
607608

608609
m.Group("/:reponame", func() {

routers/repo/commit.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,6 @@ func Diff(ctx *context.Context) {
179179
}
180180
}
181181

182-
setEditorconfigIfExists(ctx)
183-
if ctx.Written() {
184-
return
185-
}
186-
187182
ctx.Data["CommitID"] = commitID
188183
ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
189184
ctx.Data["Username"] = userName

routers/repo/middlewares.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/gogits/git-module"
99
)
1010

11-
func setEditorconfigIfExists(ctx *context.Context) {
11+
func SetEditorconfigIfExists(ctx *context.Context) {
1212
ec, err := ctx.Repo.GetEditorconfig()
1313

1414
if err != nil && !git.IsErrNotExist(err) {

routers/repo/pull.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,6 @@ func ViewPullFiles(ctx *context.Context) {
368368
return
369369
}
370370

371-
setEditorconfigIfExists(ctx)
372-
if ctx.Written() {
373-
return
374-
}
375-
376371
headTarget := path.Join(pull.HeadUserName, pull.HeadRepo.Name)
377372
ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
378373
ctx.Data["Username"] = pull.HeadUserName
@@ -625,11 +620,6 @@ func CompareAndPullRequest(ctx *context.Context) {
625620
}
626621
}
627622

628-
setEditorconfigIfExists(ctx)
629-
if ctx.Written() {
630-
return
631-
}
632-
633623
ctx.HTML(200, COMPARE_PULL)
634624
}
635625

routers/repo/view.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,6 @@ func Home(ctx *context.Context) {
245245
return
246246
}
247247

248-
setEditorconfigIfExists(ctx)
249-
if ctx.Written() {
250-
return
251-
}
252-
253248
var treeNames []string
254249
paths := make([]string, 0, 5)
255250
if len(ctx.Repo.TreePath) > 0 {

0 commit comments

Comments
 (0)