grim/youtrack-import

Parents 9491e9262532
Children 40147089502f
Add comments to issues when files are attached and mark all comments as markdown
--- a/trac/tickets.go Mon Jul 27 21:57:08 2020 -0500
+++ b/trac/tickets.go Mon Jul 27 22:58:56 2020 -0500
@@ -7,6 +7,7 @@
"os"
"path/filepath"
"regexp"
+ "sort"
"strings"
"keep.imfreedom.org/grim/youtrack-import/youtrack"
@@ -142,7 +143,7 @@
Author: convertUsername(change.Author),
Created: convertTime(change.Time),
Updated: convertTime(change.Time),
- Markdown: false,
+ Markdown: true,
}
// There's some oddness in our trac where we have a few changes where
@@ -202,8 +203,31 @@
issue.Attachments = make([]*youtrack.Attachment, len(t.Attachments))
for idx, attachment := range t.Attachments {
issue.Attachments[idx] = attachment.toYouTrack(t, users, unknownUser)
+
+ // create a comment for each attachment
+ description := fmt.Sprintf(
+ "Attachment: [%s](%s) added.\n\n%s",
+ attachment.Filename,
+ attachment.Filename,
+ convertString(attachment.Description),
+ )
+ newComment := &youtrack.Comment{
+ Author: mapUser(attachment.Author, unknownUser, users),
+ Created: convertTime(attachment.Time),
+ Updated: convertTime(attachment.Time),
+ Text: description,
+ Markdown: true,
+ }
+
+ issue.Comments = append(issue.Comments, newComment)
}
+ // sort comments by time so that all of the attachment comments appear in
+ // the correct order.
+ sort.Slice(issue.Comments, func(i, j int) bool {
+ return issue.Comments[i].Created.Before(issue.Comments[j].Created)
+ })
+
return issue, nil
}