Skip to content

Commit c9b8c12

Browse files
6543techknowlogick
authored andcommitted
feat: highlight issue references with : (#8101) (#8404)
* feat: highlight issue references with : e.g. #1287: my commit msg e.g. ABC-1234: my commit msg * ref: update model regex to consistent with issueNumericPattern * test: check highlight issue with : in commits messages
1 parent b0dcf41 commit c9b8c12

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

models/action.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var (
6565
)
6666

6767
const issueRefRegexpStr = `(?:([0-9a-zA-Z-_\.]+)/([0-9a-zA-Z-_\.]+))?(#[0-9]+)+`
68-
const issueRefRegexpStrNoKeyword = `(?:\s|^|\(|\[)(?:([0-9a-zA-Z-_\.]+)/([0-9a-zA-Z-_\.]+))?(#[0-9]+)(?:\s|$|\)|\]|\.(\s|$))`
68+
const issueRefRegexpStrNoKeyword = `(?:\s|^|\(|\[)(?:([0-9a-zA-Z-_\.]+)/([0-9a-zA-Z-_\.]+))?(#[0-9]+)(?:\s|$|\)|\]|:|\.(\s|$))`
6969

7070
func assembleKeywordsPattern(words []string) string {
7171
return fmt.Sprintf(`(?i)(?:%s)(?::?) %s`, strings.Join(words, "|"), issueRefRegexpStr)

models/action_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ func TestRegExp_issueReferenceKeywordsPat(t *testing.T) {
160160
"#2",
161161
"[#2]",
162162
"please see go-gitea/gitea#5",
163+
"#2:",
163164
}
164165
falseTestCases := []string{
165166
"kb#2",

modules/markup/html.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ var (
3838
mentionPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(@[0-9a-zA-Z-_\.]+)(?:\s|$|\)|\])`)
3939

4040
// issueNumericPattern matches string that references to a numeric issue, e.g. #1287
41-
issueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(#[0-9]+)(?:\s|$|\)|\]|\.(\s|$))`)
41+
issueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(#[0-9]+)(?:\s|$|\)|\]|:|\.(\s|$))`)
4242
// issueAlphanumericPattern matches string that references to an alphanumeric issue, e.g. ABC-1234
43-
issueAlphanumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([A-Z]{1,10}-[1-9][0-9]*)(?:\s|$|\)|\]|\.(\s|$))`)
43+
issueAlphanumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([A-Z]{1,10}-[1-9][0-9]*)(?:\s|$|\)|\]|:|\.(\s|$))`)
4444
// crossReferenceIssueNumericPattern matches string that references a numeric issue in a different repository
4545
// e.g. gogits/gogs#12345
4646
crossReferenceIssueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-zA-Z-_\.]+/[0-9a-zA-Z-_\.]+#[0-9]+)(?:\s|$|\)|\]|\.(\s|$))`)

modules/markup/html_internal_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ func TestRender_IssueIndexPattern2(t *testing.T) {
118118
test("wow (#54321 #1243)", "wow (%s %s)", 54321, 1243)
119119
test("(#4)(#5)", "(%s)(%s)", 4, 5)
120120
test("#1 (#4321) test", "%s (%s) test", 1, 4321)
121+
122+
// should render with :
123+
test("#1234: test", "%s: test", 1234)
124+
test("wow (#54321: test)", "wow (%s: test)", 54321)
121125
}
122126

123127
func TestRender_IssueIndexPattern3(t *testing.T) {
@@ -237,6 +241,8 @@ func TestRegExp_issueNumericPattern(t *testing.T) {
237241
"#0",
238242
"#1234567890987654321",
239243
" #12",
244+
"#12:",
245+
"ref: #12: msg",
240246
}
241247
falseTestCases := []string{
242248
"# 1234",
@@ -354,6 +360,7 @@ func TestRegExp_issueAlphanumericPattern(t *testing.T) {
354360
"ABC-123.",
355361
"(ABC-123)",
356362
"[ABC-123]",
363+
"ABC-123:",
357364
}
358365
falseTestCases := []string{
359366
"RC-08",

0 commit comments

Comments
 (0)