aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--routers/repo/commit.go6
-rw-r--r--routers/repo/middlewares.go23
-rw-r--r--routers/repo/pull.go12
-rw-r--r--routers/repo/view.go6
4 files changed, 31 insertions, 16 deletions
diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index b9ced49e..455f02cf 100644
--- a/routers/repo/commit.go
+++ b/routers/repo/commit.go
@@ -179,12 +179,10 @@ func Diff(ctx *context.Context) {
}
}
- ec, err := ctx.Repo.GetEditorconfig()
- if err != nil && !git.IsErrNotExist(err) {
- ctx.Handle(500, "ErrGettingEditorconfig", err)
+ setEditorconfigIfExists(ctx)
+ if ctx.Written() {
return
}
- ctx.Data["Editorconfig"] = ec
ctx.Data["CommitID"] = commitID
ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
diff --git a/routers/repo/middlewares.go b/routers/repo/middlewares.go
new file mode 100644
index 00000000..2c344420
--- /dev/null
+++ b/routers/repo/middlewares.go
@@ -0,0 +1,23 @@
+package repo
+
+import (
+ "fmt"
+
+ "github.com/gogits/git-module"
+ "github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/modules/context"
+)
+
+func setEditorconfigIfExists(ctx *context.Context) {
+ ec, err := ctx.Repo.GetEditorconfig()
+
+ if err != nil && !git.IsErrNotExist(err) {
+ description := fmt.Sprintf("Error while getting .editorconfig file: %v", err)
+ if err := models.CreateRepositoryNotice(description); err != nil {
+ ctx.Handle(500, "ErrCreatingReporitoryNotice", err)
+ }
+ return
+ }
+
+ ctx.Data["Editorconfig"] = ec
+}
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index fe606010..d649e3d7 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -357,12 +357,10 @@ func ViewPullFiles(ctx *context.Context) {
return
}
- ec, err := ctx.Repo.GetEditorconfig()
- if err != nil && !git.IsErrNotExist(err) {
- ctx.Handle(500, "ErrGettingEditorconfig", err)
+ setEditorconfigIfExists(ctx)
+ if ctx.Written() {
return
}
- ctx.Data["Editorconfig"] = ec
headTarget := path.Join(pull.HeadUserName, pull.HeadRepo.Name)
ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
@@ -616,12 +614,10 @@ func CompareAndPullRequest(ctx *context.Context) {
}
}
- ec, err := ctx.Repo.GetEditorconfig()
- if err != nil && !git.IsErrNotExist(err) {
- ctx.Handle(500, "ErrGettingEditorconfig", err)
+ setEditorconfigIfExists(ctx)
+ if ctx.Written() {
return
}
- ctx.Data["Editorconfig"] = ec
ctx.HTML(200, COMPARE_PULL)
}
diff --git a/routers/repo/view.go b/routers/repo/view.go
index c6bf4b90..7d9278e7 100644
--- a/routers/repo/view.go
+++ b/routers/repo/view.go
@@ -244,12 +244,10 @@ func Home(ctx *context.Context) {
return
}
- ec, err := ctx.Repo.GetEditorconfig()
- if err != nil && !git.IsErrNotExist(err) {
- ctx.Handle(500, "Repo.GetEditorconfig", err)
+ setEditorconfigIfExists(ctx)
+ if ctx.Written() {
return
}
- ctx.Data["Editorconfig"] = ec
var treeNames []string
paths := make([]string, 0, 5)