From 3f6a251cc099e030252faa083aadcfdda91f24ce Mon Sep 17 00:00:00 2001 From: grinat Date: Thu, 5 Sep 2019 15:15:49 +0300 Subject: [PATCH 1/3] feat: highlight issue references with : e.g. #1287: my commit msg e.g. ABC-1234: my commit msg --- modules/markup/html.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index 1ffb7da24c6f..ff5b1a76e694 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -40,9 +40,9 @@ var ( mentionPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(@[0-9a-zA-Z-_\.]+)(?:\s|$|\)|\])`) // issueNumericPattern matches string that references to a numeric issue, e.g. #1287 - issueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(#[0-9]+)(?:\s|$|\)|\]|\.(\s|$))`) + issueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(#[0-9]+)(?:\s|$|\)|\]|:|\.(\s|$))`) // issueAlphanumericPattern matches string that references to an alphanumeric issue, e.g. ABC-1234 - issueAlphanumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([A-Z]{1,10}-[1-9][0-9]*)(?:\s|$|\)|\]|\.(\s|$))`) + issueAlphanumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([A-Z]{1,10}-[1-9][0-9]*)(?:\s|$|\)|\]|:|\.(\s|$))`) // crossReferenceIssueNumericPattern matches string that references a numeric issue in a different repository // e.g. gogits/gogs#12345 crossReferenceIssueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-zA-Z-_\.]+/[0-9a-zA-Z-_\.]+#[0-9]+)(?:\s|$|\)|\]|\.(\s|$))`) From 8892cfefd3c970ef0819eb2d8adc96f5e9107c84 Mon Sep 17 00:00:00 2001 From: grinat Date: Thu, 5 Sep 2019 19:15:59 +0300 Subject: [PATCH 2/3] ref: update model regex to consistent with issueNumericPattern --- models/action.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/action.go b/models/action.go index d3b53f67381f..87088101f97f 100644 --- a/models/action.go +++ b/models/action.go @@ -65,7 +65,7 @@ var ( ) const issueRefRegexpStr = `(?:([0-9a-zA-Z-_\.]+)/([0-9a-zA-Z-_\.]+))?(#[0-9]+)+` -const issueRefRegexpStrNoKeyword = `(?:\s|^|\(|\[)(?:([0-9a-zA-Z-_\.]+)/([0-9a-zA-Z-_\.]+))?(#[0-9]+)(?:\s|$|\)|\]|\.(\s|$))` +const issueRefRegexpStrNoKeyword = `(?:\s|^|\(|\[)(?:([0-9a-zA-Z-_\.]+)/([0-9a-zA-Z-_\.]+))?(#[0-9]+)(?:\s|$|\)|\]|:|\.(\s|$))` func assembleKeywordsPattern(words []string) string { return fmt.Sprintf(`(?i)(?:%s)(?::?) %s`, strings.Join(words, "|"), issueRefRegexpStr) From 64ed52a9ef50c65d1bcd106c0f2a9aff834bcecc Mon Sep 17 00:00:00 2001 From: grinat Date: Thu, 5 Sep 2019 19:19:19 +0300 Subject: [PATCH 3/3] test: check highlight issue with : in commits messages --- models/action_test.go | 1 + modules/markup/html_internal_test.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/models/action_test.go b/models/action_test.go index e2546044d467..16fdc7adcc90 100644 --- a/models/action_test.go +++ b/models/action_test.go @@ -186,6 +186,7 @@ func TestRegExp_issueReferenceKeywordsPat(t *testing.T) { "#2", "[#2]", "please see go-gitea/gitea#5", + "#2:", } falseTestCases := []string{ "kb#2", diff --git a/modules/markup/html_internal_test.go b/modules/markup/html_internal_test.go index f0d894532b69..bb47ba3b2cab 100644 --- a/modules/markup/html_internal_test.go +++ b/modules/markup/html_internal_test.go @@ -118,6 +118,10 @@ func TestRender_IssueIndexPattern2(t *testing.T) { test("wow (#54321 #1243)", "wow (%s %s)", 54321, 1243) test("(#4)(#5)", "(%s)(%s)", 4, 5) test("#1 (#4321) test", "%s (%s) test", 1, 4321) + + // should render with : + test("#1234: test", "%s: test", 1234) + test("wow (#54321: test)", "wow (%s: test)", 54321) } func TestRender_IssueIndexPattern3(t *testing.T) { @@ -237,6 +241,8 @@ func TestRegExp_issueNumericPattern(t *testing.T) { "#0", "#1234567890987654321", " #12", + "#12:", + "ref: #12: msg", } falseTestCases := []string{ "# 1234", @@ -354,6 +360,7 @@ func TestRegExp_issueAlphanumericPattern(t *testing.T) { "ABC-123.", "(ABC-123)", "[ABC-123]", + "ABC-123:", } falseTestCases := []string{ "RC-08",