forked from forgejo/forgejo
Make link last commit massages in repository home page and commit tables (#8006)
* Make link last commit massages in repository home page and commit tables * Use RenderCommitMessageLink instead surround with a * deleted __debug_bin file * Exclude email to link from latest commit title * Exclude email processor from commit table Co-Authored-By: mrsdizzie <info@mrsdizzie.com> * Add class parameter to a html element creator functions. Make links underline dashed that are not commit * fix tests * Show dashed underline when also not hovered
This commit is contained in:
parent
7eacdcf39a
commit
7e17424c7e
7 changed files with 154 additions and 38 deletions
|
@ -20,18 +20,22 @@ const Repo = "gogits/gogs"
|
|||
const AppSubURL = AppURL + Repo + "/"
|
||||
|
||||
// alphanumLink an HTML link to an alphanumeric-style issue
|
||||
func alphanumIssueLink(baseURL string, name string) string {
|
||||
return link(util.URLJoin(baseURL, name), name)
|
||||
func alphanumIssueLink(baseURL, class, name string) string {
|
||||
return link(util.URLJoin(baseURL, name), class, name)
|
||||
}
|
||||
|
||||
// numericLink an HTML to a numeric-style issue
|
||||
func numericIssueLink(baseURL string, index int) string {
|
||||
return link(util.URLJoin(baseURL, strconv.Itoa(index)), fmt.Sprintf("#%d", index))
|
||||
func numericIssueLink(baseURL, class string, index int) string {
|
||||
return link(util.URLJoin(baseURL, strconv.Itoa(index)), class, fmt.Sprintf("#%d", index))
|
||||
}
|
||||
|
||||
// link an HTML link
|
||||
func link(href, contents string) string {
|
||||
return fmt.Sprintf("<a href=\"%s\">%s</a>", href, contents)
|
||||
func link(href, class, contents string) string {
|
||||
if class != "" {
|
||||
class = " class=\"" + class + "\""
|
||||
}
|
||||
|
||||
return fmt.Sprintf("<a href=\"%s\"%s>%s</a>", href, class, contents)
|
||||
}
|
||||
|
||||
var numericMetas = map[string]string{
|
||||
|
@ -89,13 +93,13 @@ func TestRender_IssueIndexPattern2(t *testing.T) {
|
|||
test := func(s, expectedFmt string, indices ...int) {
|
||||
links := make([]interface{}, len(indices))
|
||||
for i, index := range indices {
|
||||
links[i] = numericIssueLink(util.URLJoin(setting.AppSubURL, "issues"), index)
|
||||
links[i] = numericIssueLink(util.URLJoin(setting.AppSubURL, "issues"), "issue", index)
|
||||
}
|
||||
expectedNil := fmt.Sprintf(expectedFmt, links...)
|
||||
testRenderIssueIndexPattern(t, s, expectedNil, &postProcessCtx{metas: localMetas})
|
||||
|
||||
for i, index := range indices {
|
||||
links[i] = numericIssueLink("https://someurl.com/someUser/someRepo/", index)
|
||||
links[i] = numericIssueLink("https://someurl.com/someUser/someRepo/", "issue", index)
|
||||
}
|
||||
expectedNum := fmt.Sprintf(expectedFmt, links...)
|
||||
testRenderIssueIndexPattern(t, s, expectedNum, &postProcessCtx{metas: numericMetas})
|
||||
|
@ -158,7 +162,7 @@ func TestRender_IssueIndexPattern4(t *testing.T) {
|
|||
test := func(s, expectedFmt string, names ...string) {
|
||||
links := make([]interface{}, len(names))
|
||||
for i, name := range names {
|
||||
links[i] = alphanumIssueLink("https://someurl.com/someUser/someRepo/", name)
|
||||
links[i] = alphanumIssueLink("https://someurl.com/someUser/someRepo/", "issue", name)
|
||||
}
|
||||
expected := fmt.Sprintf(expectedFmt, links...)
|
||||
testRenderIssueIndexPattern(t, s, expected, &postProcessCtx{metas: alphanumericMetas})
|
||||
|
@ -197,17 +201,17 @@ func TestRender_AutoLink(t *testing.T) {
|
|||
|
||||
// render valid issue URLs
|
||||
test(util.URLJoin(setting.AppSubURL, "issues", "3333"),
|
||||
numericIssueLink(util.URLJoin(setting.AppSubURL, "issues"), 3333))
|
||||
numericIssueLink(util.URLJoin(setting.AppSubURL, "issues"), "issue", 3333))
|
||||
|
||||
// render valid commit URLs
|
||||
tmp := util.URLJoin(AppSubURL, "commit", "d8a994ef243349f321568f9e36d5c3f444b99cae")
|
||||
test(tmp, "<a href=\""+tmp+"\"><code class=\"nohighlight\">d8a994ef24</code></a>")
|
||||
test(tmp, "<a href=\""+tmp+"\" class=\"commit\"><code class=\"nohighlight\">d8a994ef24</code></a>")
|
||||
tmp += "#diff-2"
|
||||
test(tmp, "<a href=\""+tmp+"\"><code class=\"nohighlight\">d8a994ef24 (diff-2)</code></a>")
|
||||
test(tmp, "<a href=\""+tmp+"\" class=\"commit\"><code class=\"nohighlight\">d8a994ef24 (diff-2)</code></a>")
|
||||
|
||||
// render other commit URLs
|
||||
tmp = "https://external-link.gitea.io/go-gitea/gitea/commit/d8a994ef243349f321568f9e36d5c3f444b99cae#diff-2"
|
||||
test(tmp, "<a href=\""+tmp+"\"><code class=\"nohighlight\">d8a994ef24 (diff-2)</code></a>")
|
||||
test(tmp, "<a href=\""+tmp+"\" class=\"commit\"><code class=\"nohighlight\">d8a994ef24 (diff-2)</code></a>")
|
||||
}
|
||||
|
||||
func TestRender_FullIssueURLs(t *testing.T) {
|
||||
|
@ -228,11 +232,11 @@ func TestRender_FullIssueURLs(t *testing.T) {
|
|||
test("Here is a link https://git.osgeo.org/gogs/postgis/postgis/pulls/6",
|
||||
"Here is a link https://git.osgeo.org/gogs/postgis/postgis/pulls/6")
|
||||
test("Look here http://localhost:3000/person/repo/issues/4",
|
||||
`Look here <a href="http://localhost:3000/person/repo/issues/4">person/repo#4</a>`)
|
||||
`Look here <a href="http://localhost:3000/person/repo/issues/4" class="issue">person/repo#4</a>`)
|
||||
test("http://localhost:3000/person/repo/issues/4#issuecomment-1234",
|
||||
`<a href="http://localhost:3000/person/repo/issues/4#issuecomment-1234">person/repo#4</a>`)
|
||||
`<a href="http://localhost:3000/person/repo/issues/4#issuecomment-1234" class="issue">person/repo#4</a>`)
|
||||
test("http://localhost:3000/gogits/gogs/issues/4",
|
||||
`<a href="http://localhost:3000/gogits/gogs/issues/4">#4</a>`)
|
||||
`<a href="http://localhost:3000/gogits/gogs/issues/4" class="issue">#4</a>`)
|
||||
}
|
||||
|
||||
func TestRegExp_issueNumericPattern(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue