aboutsummaryrefslogtreecommitdiff
path: root/internal/markup
diff options
context:
space:
mode:
authorJeff <laojianzi1994@gmail.com>2020-09-29 23:07:16 +0800
committerGitHub <noreply@github.com>2020-09-29 23:07:16 +0800
commit23823e9698299a8046417152a385edfe4e48cd27 (patch)
tree0828cfbd5c6acf4698aed7cba546593f5b0a29fc /internal/markup
parent7bc3ee49aa317e48331cf6e39e1911ac89b2e325 (diff)
markup: render SHA links without branch prefix (#6350)
Co-authored-by: Zhukov Roman <zhukov.roman@gmail.com> Co-authored-by: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
Diffstat (limited to 'internal/markup')
-rw-r--r--internal/markup/markup.go5
-rw-r--r--internal/markup/markup_test.go38
2 files changed, 41 insertions, 2 deletions
diff --git a/internal/markup/markup.go b/internal/markup/markup.go
index 65b14865..ad9d7fa1 100644
--- a/internal/markup/markup.go
+++ b/internal/markup/markup.go
@@ -145,7 +145,8 @@ func RenderSha1CurrentPattern(rawBytes []byte, urlPrefix string) []byte {
if com.StrTo(m).MustInt() > 0 {
return m
}
- return fmt.Sprintf(`<a href="%s/commit/%s"><code>%s</code></a>`, urlPrefix, m, tool.ShortSHA1(string(m)))
+
+ return fmt.Sprintf(`<a href="%s/commit/%s"><code>%s</code></a>`, urlPrefix, m, tool.ShortSHA1(m))
}))
}
@@ -160,7 +161,7 @@ func RenderSpecialLink(rawBytes []byte, urlPrefix string, metas map[string]strin
rawBytes = RenderIssueIndexPattern(rawBytes, urlPrefix, metas)
rawBytes = RenderCrossReferenceIssueIndexPattern(rawBytes, urlPrefix, metas)
- rawBytes = RenderSha1CurrentPattern(rawBytes, urlPrefix)
+ rawBytes = RenderSha1CurrentPattern(rawBytes, metas["repoLink"])
return rawBytes
}
diff --git a/internal/markup/markup_test.go b/internal/markup/markup_test.go
index 911a597c..df6213e6 100644
--- a/internal/markup/markup_test.go
+++ b/internal/markup/markup_test.go
@@ -215,3 +215,41 @@ func Test_RenderIssueIndexPattern(t *testing.T) {
})
})
}
+
+func TestRenderSha1CurrentPattern(t *testing.T) {
+ metas := map[string]string{
+ "repoLink": "/someuser/somerepo",
+ }
+
+ tests := []struct {
+ desc string
+ input string
+ prefix string
+ expVal string
+ }{
+ {
+ desc: "Full SHA (40 symbols)",
+ input: "ad8ced4f57d9068cb2874557245be3c7f341149d",
+ prefix: metas["repoLink"],
+ expVal: `<a href="/someuser/somerepo/commit/ad8ced4f57d9068cb2874557245be3c7f341149d"><code>ad8ced4f57</code></a>`,
+ },
+ {
+ desc: "Short SHA (8 symbols)",
+ input: "ad8ced4f",
+ prefix: metas["repoLink"],
+ expVal: `<a href="/someuser/somerepo/commit/ad8ced4f"><code>ad8ced4f</code></a>`,
+ },
+ {
+ desc: "9 digits",
+ input: "123456789",
+ prefix: metas["repoLink"],
+ expVal: "123456789",
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.desc, func(t *testing.T) {
+ assert.Equal(t, test.expVal, string(RenderSha1CurrentPattern([]byte(test.input), test.prefix)))
+ })
+ }
+}