grim/youtrack-import

d591598025d7
Parents 367046eff7da
Children 4865c397f3ac
Replace mentions with the youtrack login name. Fixes YI-7
--- a/bitbucket/converter.go Wed Jan 15 04:55:15 2020 -0600
+++ b/bitbucket/converter.go Wed Jan 15 06:11:24 2020 -0600
@@ -48,7 +48,7 @@
yt := &youtrack.Issue{
Number: bb.ID,
Summary: bb.Title,
- Description: bb.Content,
+ Description: replaceKeywords(userMap, bb.Content),
Created: bb.CreatedOn,
Updated: bb.UpdatedOn,
Reporter: reporter,
@@ -134,7 +134,7 @@
ytComment = &youtrack.Comment{
Author: author,
- Text: comment.Content,
+ Text: replaceKeywords(userMap, comment.Content),
Created: comment.CreatedOn,
Updated: comment.UpdatedOn,
Markdown: true,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bitbucket/keywords.go Wed Jan 15 06:11:24 2020 -0600
@@ -0,0 +1,36 @@
+package bitbucket
+
+import (
+ "regexp"
+ "strings"
+
+ "hg.sr.ht/~grim/youtrack-import/youtrack"
+)
+
+var (
+ mentionRegex = regexp.MustCompile(`@\{(.+?)\}`)
+)
+
+func replaceMentions(m map[string]*youtrack.User, message string) string {
+ output := message
+
+ matches := mentionRegex.FindAllStringSubmatch(message, -1)
+ for _, match := range matches {
+ old := match[0]
+ id := match[1]
+
+ if user, found := m[id]; found {
+ output = strings.Replace(output, old, "@"+user.Login, 1)
+ }
+ }
+
+ return output
+}
+
+func replaceKeywords(m map[string]*youtrack.User, message string) string {
+ output := message
+
+ output = replaceMentions(m, output)
+
+ return output
+}