grim/youtrack-import

Handle the cset keyword. Fixes YI-12

2020-01-15, Gary Kramlich
bfb598e00f0d
Parents a4f0271587eb
Children 12f2eb3a309e
Handle the cset keyword. Fixes YI-12
--- a/bitbucket/keywords.go Wed Jan 15 06:53:17 2020 -0600
+++ b/bitbucket/keywords.go Wed Jan 15 06:59:37 2020 -0600
@@ -11,6 +11,7 @@
var (
mentionRegex = regexp.MustCompile(`@\{(.+?)\}`)
prIssueRegex = regexp.MustCompile(`((PR)\s+)?#(\d+)`)
+ csetRegex = regexp.MustCompile(`→ <<cset (.+?)>>`)
)
func replaceMentions(m map[string]*youtrack.User, message string) string {
@@ -56,11 +57,32 @@
return output
}
+func replaceChangeSets(repository, message string) string {
+ output := message
+ matches := csetRegex.FindAllStringSubmatch(message, -1)
+ for _, match := range matches {
+ old := match[0]
+ id := match[1]
+
+ replacement := fmt.Sprintf(
+ "[r%s](https://bitbucket.org/%s/commits/%s)",
+ id,
+ repository,
+ id,
+ )
+
+ output = strings.Replace(output, old, replacement, 1)
+ }
+
+ return output
+}
+
func replaceKeywords(m map[string]*youtrack.User, projectID, repository, message string) string {
output := message
output = replaceMentions(m, output)
output = replacePullRequestsIssues(repository, projectID, output)
+ output = replaceChangeSets(repository, output)
return output
}