Skip to content

Refactor editorconfig middleware #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,8 @@ func runWeb(ctx *cli.Context) error {
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
})

m.Combo("/compare/*", repo.MustAllowPulls).Get(repo.CompareAndPullRequest).
m.Combo("/compare/*", repo.MustAllowPulls, repo.SetEditorconfigIfExists).
Get(repo.CompareAndPullRequest).
Post(bindIgnErr(auth.CreateIssueForm{}), repo.CompareAndPullRequestPost)

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

m.Group("/pulls/:index", func() {
m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
m.Get("/files", context.RepoRef(), repo.ViewPullFiles)
m.Get("/files", context.RepoRef(), repo.SetEditorconfigIfExists, repo.ViewPullFiles)
m.Post("/merge", reqRepoWriter, repo.MergePullRequest)
}, repo.MustAllowPulls)

m.Group("", func() {
m.Get("/src/*", repo.Home)
m.Get("/src/*", repo.SetEditorconfigIfExists, repo.Home)
m.Get("/raw/*", repo.SingleDownload)
m.Get("/commits/*", repo.RefCommits)
m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.Diff)
m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.SetEditorconfigIfExists, repo.Diff)
m.Get("/forks", repo.Forks)
}, context.RepoRef())
m.Get("/commit/:sha([a-f0-9]{7,40})\\.:ext(patch|diff)", repo.RawDiff)
Expand All @@ -601,8 +602,8 @@ func runWeb(ctx *cli.Context) error {

m.Group("/:username", func() {
m.Group("/:reponame", func() {
m.Get("", repo.Home)
m.Get("\\.git$", repo.Home)
m.Get("", repo.SetEditorconfigIfExists, repo.Home)
m.Get("\\.git$", repo.SetEditorconfigIfExists, repo.Home)
}, ignSignIn, context.RepoAssignment(true), context.RepoRef())

m.Group("/:reponame", func() {
Expand Down
5 changes: 0 additions & 5 deletions routers/repo/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,6 @@ func Diff(ctx *context.Context) {
}
}

setEditorconfigIfExists(ctx)
if ctx.Written() {
return
}

ctx.Data["CommitID"] = commitID
ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
ctx.Data["Username"] = userName
Expand Down
2 changes: 1 addition & 1 deletion routers/repo/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/gogits/git-module"
)

func setEditorconfigIfExists(ctx *context.Context) {
func SetEditorconfigIfExists(ctx *context.Context) {
ec, err := ctx.Repo.GetEditorconfig()

if err != nil && !git.IsErrNotExist(err) {
Expand Down
10 changes: 0 additions & 10 deletions routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,6 @@ func ViewPullFiles(ctx *context.Context) {
return
}

setEditorconfigIfExists(ctx)
if ctx.Written() {
return
}

headTarget := path.Join(pull.HeadUserName, pull.HeadRepo.Name)
ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
ctx.Data["Username"] = pull.HeadUserName
Expand Down Expand Up @@ -625,11 +620,6 @@ func CompareAndPullRequest(ctx *context.Context) {
}
}

setEditorconfigIfExists(ctx)
if ctx.Written() {
return
}

ctx.HTML(200, COMPARE_PULL)
}

Expand Down
5 changes: 0 additions & 5 deletions routers/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,6 @@ func Home(ctx *context.Context) {
return
}

setEditorconfigIfExists(ctx)
if ctx.Written() {
return
}

var treeNames []string
paths := make([]string, 0, 5)
if len(ctx.Repo.TreePath) > 0 {
Expand Down