--- a/bitbucket/converter.go Wed Jan 15 00:38:56 2020 -0600
+++ b/bitbucket/converter.go Wed Jan 15 04:41:04 2020 -0600
@@ -62,7 +62,7 @@
- Comments: []youtrack.Comment{},
+ Comments: []*youtrack.Comment{}, // TODO: check if state is resovled then set the Resolved field to the
@@ -86,15 +86,15 @@
-func (a *Archive) convertComments(userMap map[string]*youtrack.User, id int) []youtrack.Comment {
- comments := []youtrack.Comment{}
+func (a *Archive) convertComments(userMap map[string]*youtrack.User, id int) []*youtrack.Comment { + comments := []*youtrack.Comment{} for _, comment := range a.Comments {
- var ytComment youtrack.Comment
+ var ytComment *youtrack.Comment if comment.Content == "" {
// if we don't have a content we need to build it from the log
@@ -118,7 +118,7 @@
- ytComment = youtrack.Comment{
+ ytComment = &youtrack.Comment{ @@ -132,7 +132,7 @@
- ytComment = youtrack.Comment{
+ ytComment = &youtrack.Comment{ Created: comment.CreatedOn,
--- a/youtrack/attachment.go Wed Jan 15 00:38:56 2020 -0600
+++ b/youtrack/attachment.go Wed Jan 15 04:41:04 2020 -0600
@@ -9,6 +9,7 @@
@@ -164,3 +165,48 @@
+func extractAttachments(issue int, author, message string, created time.Time) (string, []*Attachment, error) { + pattern := `!\[(.*?)\]\((.+?)(\s+["'].*?["'])?\)` + regex := regexp.MustCompile(pattern) + attachments := []*Attachment{} + matches := regex.FindAllStringSubmatch(message, -1) + for _, match := range matches { + decoded, err := url.QueryUnescape(uri) + return "", attachments, err + filename = filepath.Base(decoded) + img := fmt.Sprintf("![](%s)", filename) + resp, err := http.Get(uri) + return "", attachments, err + if resp.StatusCode != http.StatusOK { + return "", attachments, fmt.Errorf("unexpected status code %d", resp.StatusCode) + attachment := NewAttachment(issue, author, created) + if err := attachment.AddFile(resp.Body, filename); err != nil { + return "", attachments, err + output = strings.Replace(output, old, img, 1) + attachments = append(attachments, attachment) + return output, attachments, nil --- a/youtrack/comments.go Wed Jan 15 00:38:56 2020 -0600
+++ b/youtrack/comments.go Wed Jan 15 04:41:04 2020 -0600
@@ -13,8 +13,31 @@
-func sortComments(comments []Comment) {
+func sortComments(comments []*Comment) { sort.Slice(comments, func(i, j int) bool {
return comments[i].Created.Before(comments[j].Created)
+func (c *Comment) extractAttachments(i *Issue) error { + modified, attachments, err := extractAttachments( + if len(attachments) > 0 { + i.Attachments = append(i.Attachments, attachments...) --- a/youtrack/issue.go Wed Jan 15 00:38:56 2020 -0600
+++ b/youtrack/issue.go Wed Jan 15 04:41:04 2020 -0600
@@ -29,10 +29,37 @@
State string `yt:"state"`
Attachments []*Attachment
+func (i *Issue) extractAttachments() error { + modified, attachments, err := extractAttachments( + if len(attachments) > 0 { + i.Description = modified + i.Attachments = append(i.Attachments, attachments...) + for _, comment := range i.Comments { + if err := comment.extractAttachments(i); err != nil { func (i *Issue) encode() xmlIssue {
@@ -104,6 +131,10 @@
issues.Issues = make([]xmlIssue, e-s)
+ if err := p.Issues[i].extractAttachments(); err != nil { issues.Issues[i-s] = p.Issues[i].encode()