grim/youtrack-import

Parents d591598025d7
Children a4f0271587eb
Add support for linking to the new youtrack issues. Fixes YI-8
--- a/bitbucket/cmd.go Wed Jan 15 06:11:24 2020 -0600
+++ b/bitbucket/cmd.go Wed Jan 15 06:35:33 2020 -0600
@@ -22,7 +22,7 @@
return err
}
- project, err := archive.convert(usersMap)
+ project, err := archive.convert(g.ProjectID, usersMap)
if err != nil {
return err
}
--- a/bitbucket/converter.go Wed Jan 15 06:11:24 2020 -0600
+++ b/bitbucket/converter.go Wed Jan 15 06:35:33 2020 -0600
@@ -34,7 +34,7 @@
}
)
-func (a *Archive) convertIssue(bb Issue, userMap map[string]*youtrack.User) *youtrack.Issue {
+func (a *Archive) convertIssue(projectID string, bb Issue, userMap map[string]*youtrack.User) *youtrack.Issue {
reporter := "admin"
if user, found := userMap[bb.Reporter.AccountID]; found {
reporter = user.Login
@@ -48,7 +48,7 @@
yt := &youtrack.Issue{
Number: bb.ID,
Summary: bb.Title,
- Description: replaceKeywords(userMap, bb.Content),
+ Description: replaceKeywords(userMap, projectID, bb.Content),
Created: bb.CreatedOn,
Updated: bb.UpdatedOn,
Reporter: reporter,
@@ -80,13 +80,13 @@
}
// add the comments and attachments
- yt.Comments = a.convertComments(userMap, bb.ID)
+ yt.Comments = a.convertComments(projectID, userMap, bb.ID)
yt.Attachments = a.convertAttachments(userMap, bb)
return yt
}
-func (a *Archive) convertComments(userMap map[string]*youtrack.User, id int) []*youtrack.Comment {
+func (a *Archive) convertComments(projectID string, userMap map[string]*youtrack.User, id int) []*youtrack.Comment {
comments := []*youtrack.Comment{}
for _, comment := range a.Comments {
@@ -134,7 +134,7 @@
ytComment = &youtrack.Comment{
Author: author,
- Text: replaceKeywords(userMap, comment.Content),
+ Text: replaceKeywords(userMap, projectID, comment.Content),
Created: comment.CreatedOn,
Updated: comment.UpdatedOn,
Markdown: true,
@@ -175,7 +175,7 @@
return attachments
}
-func (a *Archive) convert(usersMap *UsersMap) (*youtrack.Project, error) {
+func (a *Archive) convert(projectID string, usersMap *UsersMap) (*youtrack.Project, error) {
users, err := a.ExtractUsers(usersMap)
if err != nil {
return nil, err
@@ -204,7 +204,7 @@
// convert all of the issues
issues := make([]*youtrack.Issue, len(a.Issues))
for i := 0; i < len(a.Issues); i++ {
- issues[i] = a.convertIssue(a.Issues[i], users)
+ issues[i] = a.convertIssue(projectID, a.Issues[i], users)
}
project := &youtrack.Project{
--- a/bitbucket/keywords.go Wed Jan 15 06:11:24 2020 -0600
+++ b/bitbucket/keywords.go Wed Jan 15 06:35:33 2020 -0600
@@ -9,6 +9,7 @@
var (
mentionRegex = regexp.MustCompile(`@\{(.+?)\}`)
+ issueRegex = regexp.MustCompile(`#(\d+)`)
)
func replaceMentions(m map[string]*youtrack.User, message string) string {
@@ -27,10 +28,25 @@
return output
}
-func replaceKeywords(m map[string]*youtrack.User, message string) string {
+func replaceIssues(projectID, message string) string {
+ output := message
+
+ matches := issueRegex.FindAllStringSubmatch(message, -1)
+ for _, match := range matches {
+ old := match[0]
+ id := match[1]
+
+ output = strings.Replace(output, old, projectID+"-"+id, 1)
+ }
+
+ return output
+}
+
+func replaceKeywords(m map[string]*youtrack.User, projectID string, message string) string {
output := message
output = replaceMentions(m, output)
+ output = replaceIssues(projectID, output)
return output
}