grim/youtrack-import

Parents 12f2eb3a309e
Children 21e09c165b0a
Correctly show statechanges (logs) with comments. Fixes YI-13
--- a/bitbucket/converter.go Wed Jan 15 07:24:06 2020 -0600
+++ b/bitbucket/converter.go Wed Jan 15 07:36:50 2020 -0600
@@ -2,6 +2,7 @@
import (
"fmt"
+ "strings"
"hg.sr.ht/~grim/youtrack-import/youtrack"
)
@@ -91,51 +92,39 @@
continue
}
- var ytComment *youtrack.Comment
-
- if comment.Content == "" {
- // if we don't have a content we need to build it from the log
- // entries
- for _, log := range a.Logs {
- if log.Comment == comment.ID {
- author := "admin"
- if user, found := userMap[log.User.AccountID]; found {
- author = user.Login
- }
-
- content := ""
- if log.Field == "content" {
- content = "edited description"
- } else {
- content = fmt.Sprintf(
- "%s: %s ⟶ %s",
- log.Field,
- log.ChangedFrom,
- log.ChangedTo,
- )
- }
-
- ytComment = &youtrack.Comment{
- Author: author,
- Created: log.CreatedOn,
- Text: content,
- Markdown: true,
- }
+ // check if there were any stage changes with this comment
+ stateChanges := []string{}
+ for _, log := range a.Logs {
+ if log.Comment == comment.ID {
+ if log.Field == "content" {
+ stateChanges = append(stateChanges, "* edited description")
+ } else {
+ change := fmt.Sprintf(
+ "* %s: %s ⟶ %s",
+ log.Field,
+ log.ChangedFrom,
+ log.ChangedTo,
+ )
+ stateChanges = append(stateChanges, change)
}
}
- } else {
- author := "admin"
- if user, found := userMap[comment.User.AccountID]; found {
- author = user.Login
- }
+ }
+
+ if logContent := strings.Join(stateChanges, "\n"); logContent != "" {
+ comment.Content = logContent + "\n\n" + comment.Content
+ }
- ytComment = &youtrack.Comment{
- Author: author,
- Text: replaceKeywords(userMap, projectID, repository, comment.Content),
- Created: comment.CreatedOn,
- Updated: comment.UpdatedOn,
- Markdown: true,
- }
+ author := "admin"
+ if user, found := userMap[comment.User.AccountID]; found {
+ author = user.Login
+ }
+
+ ytComment := &youtrack.Comment{
+ Author: author,
+ Text: replaceKeywords(userMap, projectID, repository, comment.Content),
+ Created: comment.CreatedOn,
+ Updated: comment.UpdatedOn,
+ Markdown: true,
}
comments = append(comments, ytComment)