grim/youtrack-import

1108579b4005
Parents d740bff69232
Children 741af4ca4d62
Handle commit hashes similar to changesets. Fixes YI-25
--- a/bitbucket/keywords.go Thu Jan 16 02:32:47 2020 -0600
+++ b/bitbucket/keywords.go Fri Jan 17 23:06:39 2020 -0600
@@ -13,6 +13,7 @@
mentionRegex = regexp.MustCompile(`@\{(.+?)\}`)
prIssueRegex = regexp.MustCompile(`(([Pp][Rr])\s+)?(\\)?#(\d+)`)
csetRegex = regexp.MustCompile(`→ <<cset (.+?)>>`)
+ hashRegex = regexp.MustCompile(`\b([a-fA-F0-9]{40})\b`)
)
func replaceMentions(m map[string]*youtrack.User, message string) string {
@@ -68,7 +69,7 @@
id := match[1]
replacement := fmt.Sprintf(
- "* **commit**: %s@%s",
+ "* **commit**: %s@%s\n",
repository,
id,
)
@@ -79,12 +80,32 @@
return output
}
+func replaceCommitHashes(repository, message string) string {
+ output := message
+ matches := hashRegex.FindAllStringSubmatch(message, -1)
+ for _, match := range matches {
+ old := match[0]
+ hash := match[1]
+
+ replacement := fmt.Sprintf(
+ "%s@%s",
+ repository,
+ hash,
+ )
+
+ output = strings.Replace(output, old, replacement, 1)
+ }
+
+ return output
+}
+
func replaceKeywords(m map[string]*youtrack.User, nIssues int, projectID, repository, message string) string {
output := message
output = replaceMentions(m, output)
output = replacePullRequestsIssues(nIssues, repository, projectID, output)
output = replaceChangeSets(repository, output)
+ output = replaceCommitHashes(repository, output)
return output
}