From 195cb4f77759d3f085a91dbed6fd7fca294f17cc Mon Sep 17 00:00:00 2001 From: Gary Kim Date: Sun, 28 Jul 2019 23:38:56 -0500 Subject: [PATCH 1/4] Provide links in commit summaries in commits table/view list Signed-off-by: Gary Kim --- templates/repo/commits_table.tmpl | 2 +- templates/repo/view_list.tmpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/commits_table.tmpl b/templates/repo/commits_table.tmpl index ebeb87b93c1b4..41ab0240bb36b 100644 --- a/templates/repo/commits_table.tmpl +++ b/templates/repo/commits_table.tmpl @@ -71,7 +71,7 @@ - {{.Summary}} + {{RenderCommitMessage .Message $.RepoLink $.Repository.ComposeMetas}} {{if IsMultilineCommitMessage .Message}} diff --git a/templates/repo/view_list.tmpl b/templates/repo/view_list.tmpl index 75269837cb86e..6cf1370266507 100644 --- a/templates/repo/view_list.tmpl +++ b/templates/repo/view_list.tmpl @@ -28,7 +28,7 @@ {{end}} {{template "repo/commit_status" .LatestCommitStatus}} - {{.LatestCommit.Summary}} + {{RenderCommitMessage .LatestCommit.Message $.RepoLink $.Repository.ComposeMetas}} {{if IsMultilineCommitMessage .LatestCommit.Message}} From a88564b8bc9872d4bf11062a4ebcb2f42b702200 Mon Sep 17 00:00:00 2001 From: Gary Kim Date: Wed, 31 Jul 2019 10:33:40 +0800 Subject: [PATCH 2/4] Check that hashes are commits before making them links Signed-off-by: Gary Kim --- models/repo.go | 5 +++-- modules/markup/html.go | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/models/repo.go b/models/repo.go index 501a2c91207f5..a30508b4956f3 100644 --- a/models/repo.go +++ b/models/repo.go @@ -508,8 +508,9 @@ func (repo *Repository) mustOwnerName(e Engine) string { func (repo *Repository) ComposeMetas() map[string]string { if repo.ExternalMetas == nil { repo.ExternalMetas = map[string]string{ - "user": repo.MustOwner().Name, - "repo": repo.Name, + "user": repo.MustOwner().Name, + "repo": repo.Name, + "repoPath": repo.RepoPath(), } unit, err := repo.GetUnit(UnitTypeExternalTracker) if err != nil { diff --git a/modules/markup/html.go b/modules/markup/html.go index 825a41dd1f6f3..a3db925f76275 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -13,6 +13,7 @@ import ( "strings" "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" @@ -657,6 +658,14 @@ func sha1CurrentPatternProcessor(ctx *postProcessCtx, node *html.Node) { // but that is not always the case. // Although unlikely, deadbeef and 1234567 are valid short forms of SHA1 hash // as used by git and github for linking and thus we have to do similar. + // Because of this, we check to make sure that a matched hash is actually + // a commit in the repository before making it a link. + if ctx.metas["repoPath"] != "" { + if _, err := git.NewCommand("log", "-1", hash).RunInDirBytes(ctx.metas["repoPath"]); err != nil { + return + } + } + replaceContent(node, m[2], m[3], createCodeLink(util.URLJoin(setting.AppURL, ctx.metas["user"], ctx.metas["repo"], "commit", hash), base.ShortSha(hash))) } From f21ec5e85422918988323813faef197eade546bf Mon Sep 17 00:00:00 2001 From: Gary Kim Date: Sat, 17 Aug 2019 00:01:24 +0800 Subject: [PATCH 3/4] Revert "Check that hashes are commits before making them links" This reverts commit a88564b8bc9872d4bf11062a4ebcb2f42b702200. --- models/repo.go | 5 ++--- modules/markup/html.go | 9 --------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/models/repo.go b/models/repo.go index a30508b4956f3..501a2c91207f5 100644 --- a/models/repo.go +++ b/models/repo.go @@ -508,9 +508,8 @@ func (repo *Repository) mustOwnerName(e Engine) string { func (repo *Repository) ComposeMetas() map[string]string { if repo.ExternalMetas == nil { repo.ExternalMetas = map[string]string{ - "user": repo.MustOwner().Name, - "repo": repo.Name, - "repoPath": repo.RepoPath(), + "user": repo.MustOwner().Name, + "repo": repo.Name, } unit, err := repo.GetUnit(UnitTypeExternalTracker) if err != nil { diff --git a/modules/markup/html.go b/modules/markup/html.go index a3db925f76275..825a41dd1f6f3 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -13,7 +13,6 @@ import ( "strings" "code.gitea.io/gitea/modules/base" - "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" @@ -658,14 +657,6 @@ func sha1CurrentPatternProcessor(ctx *postProcessCtx, node *html.Node) { // but that is not always the case. // Although unlikely, deadbeef and 1234567 are valid short forms of SHA1 hash // as used by git and github for linking and thus we have to do similar. - // Because of this, we check to make sure that a matched hash is actually - // a commit in the repository before making it a link. - if ctx.metas["repoPath"] != "" { - if _, err := git.NewCommand("log", "-1", hash).RunInDirBytes(ctx.metas["repoPath"]); err != nil { - return - } - } - replaceContent(node, m[2], m[3], createCodeLink(util.URLJoin(setting.AppURL, ctx.metas["user"], ctx.metas["repo"], "commit", hash), base.ShortSha(hash))) } From d5f64cf7b4f80fc03c2ea87aef32f3db028e7fe3 Mon Sep 17 00:00:00 2001 From: Gary Kim Date: Mon, 19 Aug 2019 21:43:21 +0800 Subject: [PATCH 4/4] Add Commit Message Links to Files List Signed-off-by: Gary Kim --- templates/repo/view_list.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/view_list.tmpl b/templates/repo/view_list.tmpl index 6cf1370266507..e634130458012 100644 --- a/templates/repo/view_list.tmpl +++ b/templates/repo/view_list.tmpl @@ -33,7 +33,7 @@ {{end}} - + {{if .LatestCommit.Author}}{{TimeSince .LatestCommit.Author.When $.Lang}}{{end}} @@ -83,7 +83,7 @@ {{end}} - {{$commit.Summary}} + {{RenderCommitMessageLink $commit.Message $.RepoLink (Printf "%s/commit/%s" $.RepoLink $commit.ID) $.Repository.ComposeMetas}} {{TimeSince $commit.Committer.When $.Lang}}