From 3181cb7b9ff2de2bcca497fc889ce2abdc2b262f Mon Sep 17 00:00:00 2001 From: JustusBunsi <61625851+justusbunsi@users.noreply.github.com> Date: Sun, 2 May 2021 13:36:37 +0200 Subject: [PATCH 1/2] Respect merge message structure for parsing item references Signed-off-by: JustusBunsi <61625851+justusbunsi@users.noreply.github.com> --- modules/references/references.go | 2 +- modules/references/references_test.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/references/references.go b/modules/references/references.go index 6c0db0cf4761a..f518092cb0a6d 100644 --- a/modules/references/references.go +++ b/modules/references/references.go @@ -29,7 +29,7 @@ var ( // mentionPattern matches all mentions in the form of "@user" or "@org/team" mentionPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(@[0-9a-zA-Z-_]+|@[0-9a-zA-Z-_]+\/?[0-9a-zA-Z-_]+|@[0-9a-zA-Z-_][0-9a-zA-Z-_.]+\/?[0-9a-zA-Z-_.]+[0-9a-zA-Z-_])(?:\s|[:,;.?!]\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|^|\(|\[|Merge pull request \')([#!][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|$))`) // crossReferenceIssueNumericPattern matches string that references a numeric issue in a different repository diff --git a/modules/references/references_test.go b/modules/references/references_test.go index d4f080490d1fa..293322a7142ee 100644 --- a/modules/references/references_test.go +++ b/modules/references/references_test.go @@ -197,6 +197,13 @@ func TestFindAllIssueReferences(t *testing.T) { {200, "user3", "repo4", "200", false, XRefActionNone, &RefSpan{Start: 5, End: 20}, nil, ""}, }, }, + { + "Merge pull request '#12345 My fix for a bug' (!1337) from feature-branch into main", + []testResult{ + {12345, "", "", "12345", false, XRefActionNone, &RefSpan{Start: 20, End: 26}, nil, ""}, + {1337, "", "", "1337", true, XRefActionNone, &RefSpan{Start: 46, End: 51}, nil, ""}, + }, + }, { "Which abc. #9434 same as above", []testResult{ From a4cf75681676d99616a7831283e4a1c73fab51db Mon Sep 17 00:00:00 2001 From: Steven <61625851+justusbunsi@users.noreply.github.com> Date: Fri, 7 May 2021 20:59:52 +0200 Subject: [PATCH 2/2] Simplify regex Co-authored-by: zeripath --- modules/references/references.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/references/references.go b/modules/references/references.go index f518092cb0a6d..106e66b47bb5c 100644 --- a/modules/references/references.go +++ b/modules/references/references.go @@ -29,7 +29,7 @@ var ( // mentionPattern matches all mentions in the form of "@user" or "@org/team" mentionPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(@[0-9a-zA-Z-_]+|@[0-9a-zA-Z-_]+\/?[0-9a-zA-Z-_]+|@[0-9a-zA-Z-_][0-9a-zA-Z-_.]+\/?[0-9a-zA-Z-_.]+[0-9a-zA-Z-_])(?:\s|[:,;.?!]\s|[:,;.?!]?$|\)|\])`) // issueNumericPattern matches string that references to a numeric issue, e.g. #1287 - issueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[|Merge pull request \')([#!][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|$))`) // crossReferenceIssueNumericPattern matches string that references a numeric issue in a different repository