Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept punctuation after simple+cross repository issue references #10091

Merged
merged 7 commits into from
Feb 1, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions modules/references/references.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ var (
// mentionPattern matches all mentions in the form of "@user"
mentionPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(@[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|^|\(|\[)([#!][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
// e.g. gogits/gogs#12345
crossReferenceIssueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-zA-Z-_\.]+/[0-9a-zA-Z-_\.]+[#!][0-9]+)(?:\s|$|\)|\]|\.(\s|$))`)
crossReferenceIssueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-zA-Z-_\.]+/[0-9a-zA-Z-_\.]+[#!][0-9]+)(?:\s|$|\)|\]|[:;,.]\s|[:;,.]$)`)

issueCloseKeywordsPat, issueReopenKeywordsPat *regexp.Regexp
issueKeywordsOnce sync.Once
Expand Down Expand Up @@ -301,6 +301,10 @@ func findAllIssueReferencesBytes(content []byte, links []string) []*rawReference
}

func getCrossReference(content []byte, start, end int, fromLink bool, prOnly bool) *rawReference {
// Drop last character if it's a space to avoid skipping consecutive content
if content[end-1] == ' ' {
end--
}
refid := string(content[start:end])
sep := strings.IndexAny(refid, "#!")
if sep < 0 {
Expand Down
31 changes: 31 additions & 0 deletions modules/references/references_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,37 @@ func TestFindAllIssueReferences(t *testing.T) {
{1235, "", "", "1235", false, XRefActionNone, &RefSpan{Start: 8, End: 13}, nil},
},
},
{
"For [!123] yes",
[]testResult{
{123, "", "", "123", true, XRefActionNone, &RefSpan{Start: 5, End: 9}, nil},
},
},
{
"For (#345) yes",
[]testResult{
{345, "", "", "345", false, XRefActionNone, &RefSpan{Start: 5, End: 9}, nil},
},
},
{
"For #22,#23 no, neither #28:#29 or !30!31#32;33 should",
[]testResult{},
},
{
"For #24, and #25. yes; also #26; and #27: should",
[]testResult{
{24, "", "", "24", false, XRefActionNone, &RefSpan{Start: 4, End: 7}, nil},
{25, "", "", "25", false, XRefActionNone, &RefSpan{Start: 13, End: 16}, nil},
{26, "", "", "26", false, XRefActionNone, &RefSpan{Start: 28, End: 31}, nil},
{27, "", "", "27", false, XRefActionNone, &RefSpan{Start: 37, End: 40}, nil},
},
},
{
"This user3/repo4#200, yes.",
[]testResult{
{200, "user3", "repo4", "200", false, XRefActionNone, &RefSpan{Start: 5, End: 20}, nil},
},
},
{
"Which abc. #9434 same as above",
[]testResult{
Expand Down