From 528c075ad668da4fbe9193e477c783cc76321503 Mon Sep 17 00:00:00 2001 From: dennis-smurf Date: Fri, 5 Dec 2014 11:02:52 +0100 Subject: Added issue link rendering in commit messages --- routers/repo/commit.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'routers/repo/commit.go') diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 1174e626..82be6881 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -5,12 +5,14 @@ package repo import ( + "container/list" "path" "github.com/Unknwon/com" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/setting" ) @@ -72,6 +74,7 @@ func Commits(ctx *middleware.Context) { ctx.Handle(500, "CommitsByRange", err) return } + commits = RenderIssueLinks(commits, ctx.Repo.RepoLink) commits = models.ValidateCommitsWithEmails(commits) ctx.Data["Commits"] = commits @@ -83,6 +86,16 @@ func Commits(ctx *middleware.Context) { ctx.HTML(200, COMMITS) } +func RenderIssueLinks(oldCommits *list.List, repoLink string) *list.List { + newCommits := list.New() + for e := oldCommits.Front(); e != nil; e = e.Next() { + c := e.Value.(*git.Commit) + c.CommitMessage = string(base.RenderissueIndexPattern([]byte(c.CommitMessage), repoLink)) + newCommits.PushBack(c) + } + return newCommits +} + func SearchCommits(ctx *middleware.Context) { ctx.Data["IsSearchPage"] = true ctx.Data["IsRepoToolbarCommits"] = true @@ -110,6 +123,7 @@ func SearchCommits(ctx *middleware.Context) { ctx.Handle(500, "SearchCommits", err) return } + commits = RenderIssueLinks(commits, ctx.Repo.RepoLink) commits = models.ValidateCommitsWithEmails(commits) ctx.Data["Keyword"] = keyword @@ -171,6 +185,7 @@ func FileHistory(ctx *middleware.Context) { ctx.Handle(500, "repo.FileHistory(CommitsByRange)", err) return } + commits = RenderIssueLinks(commits, ctx.Repo.RepoLink) commits = models.ValidateCommitsWithEmails(commits) ctx.Data["Commits"] = commits @@ -191,7 +206,7 @@ func Diff(ctx *middleware.Context) { commitId := ctx.Repo.CommitId commit := ctx.Repo.Commit - + commit.CommitMessage = string(base.RenderissueIndexPattern([]byte(commit.CommitMessage), ctx.Repo.RepoLink)) diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName), commitId, setting.MaxGitDiffLines) if err != nil { -- cgit v1.2.3