From d731520f4df0f2285e76d5f4f8701d27d1614899 Mon Sep 17 00:00:00 2001 From: "j. mccann" Date: Thu, 7 Mar 2019 21:55:32 -0500 Subject: [PATCH 1/5] Improve issue autolinks Update autolinks to match what github does here: Issue in same repo: #1 Issue in different repo: org/repo#1 Fixes #6264 --- modules/markup/html.go | 29 +++++++++++++++++++++--- modules/markup/html_internal_test.go | 6 +++-- modules/markup/markdown/markdown_test.go | 2 +- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index e016b67d0cf39..0379741568f6a 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -540,9 +540,32 @@ func fullIssuePatternProcessor(ctx *postProcessCtx, node *html.Node) { } link := node.Data[m[0]:m[1]] id := "#" + node.Data[m[2]:m[3]] - // TODO if m[4]:m[5] is not nil, then link is to a comment, - // and we should indicate that in the text somehow - replaceContent(node, m[0], m[1], createLink(link, id)) + + // extract repo and org name from matched link like + // http://localhost:3000/gituser/myrepo/issues/1 + linkParts := strings.Split(path.Clean(link), "/") + matchOrg := linkParts[len(linkParts)-4] + matchRepo := linkParts[len(linkParts)-3] + + // extract the current org and repo from ctx URL like + // http://localhost:3000/gituser/myrepo/ + urlParts := strings.Split(path.Clean(ctx.urlPrefix), "/") + + if urlParts[len(urlParts)-1] == "wiki" { + urlParts = urlParts[:len(urlParts)-1] + } + currentOrg := urlParts[len(urlParts)-2] + currentRepo := urlParts[len(urlParts)-1] + + if matchOrg == currentOrg && matchRepo == currentRepo { + // TODO if m[4]:m[5] is not nil, then link is to a comment, + // and we should indicate that in the text somehow + replaceContent(node, m[0], m[1], createLink(link, id)) + + } else { + orgRepoID := matchOrg + "/" + matchRepo + id + replaceContent(node, m[0], m[1], createLink(link, orgRepoID)) + } } func issueIndexPatternProcessor(ctx *postProcessCtx, node *html.Node) { diff --git a/modules/markup/html_internal_test.go b/modules/markup/html_internal_test.go index ff07bab9134c0..7e60b8ab34137 100644 --- a/modules/markup/html_internal_test.go +++ b/modules/markup/html_internal_test.go @@ -218,9 +218,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 #4`) + `Look here person/repo#4`) test("http://localhost:3000/person/repo/issues/4#issuecomment-1234", - `#4`) + `person/repo#4`) + test("http://localhost:3000/gogits/gogs/issues/4", + `#4`) } func TestRegExp_issueNumericPattern(t *testing.T) { diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index 5aa9c3d7d27b0..f80d46f45b7aa 100644 --- a/modules/markup/markdown/markdown_test.go +++ b/modules/markup/markdown/markdown_test.go @@ -100,7 +100,7 @@ func testAnswers(baseURLContent, baseURLImages string) []string {

Ideas and codes