iterate PR

This commit is contained in:
Michael Telatynski 2020-04-04 11:58:38 +01:00
parent 9f6217d159
commit 6ffa32a236
2 changed files with 7 additions and 3 deletions

View file

@ -120,11 +120,13 @@ type submitResponse struct {
ReportURL string `json:"report_url,omitempty"`
}
// regex to catch and substitute ambiguous issue references with explicit ones to the actual repo they are in
var ambiguousIssueRegex = regexp.MustCompile(`(^|[([{\s])(#\d+)([^\w]|$)`)
// regex to match and substitute ambiguous issue references in the rageshake body text
// matches a hash followed by digits optionally surrounded by whitespace or some punctuation
// also matches if the input starts with digits where the hash becomes optional
var ambiguousIssueRegex = regexp.MustCompile(`(^|[([{\s])(?:^|#)(\d+)([^\w]|$)`)
func replaceAmbiguousIssueReferences(ownerRepo, text string) string {
t := ambiguousIssueRegex.ReplaceAllString(text, fmt.Sprintf("${1}%s$2$3", ownerRepo))
t := ambiguousIssueRegex.ReplaceAllString(text, fmt.Sprintf("${1}%s#$2$3", ownerRepo))
return t
}

View file

@ -492,6 +492,8 @@ func TestAutocompleteIssueReferences(t *testing.T) {
"test (#123) bar": "test (owner/repo#123) bar", // brackets
"Start #123. Now": "Start owner/repo#123. Now", // followed by punctuation
"#123foo": "#123foo", // ignore
"foo/#123": "foo/#123", // ignore
"123": "owner/repo#123", // special case for entire body being a number
}
for text, expect := range tests {