grim/youtrack-import

Parents 6ec0d80db3e0
Children faf8f5a4120f
Handle comments that end up with no text after processing. This typically happens if it was a reply with the body removed
  • +26 -23
    trac/tickets.go
  • --- a/trac/tickets.go Tue Aug 04 22:11:15 2020 -0500
    +++ b/trac/tickets.go Tue Aug 04 22:19:35 2020 -0500
    @@ -156,6 +156,27 @@
    return mapUser(username, unknownUser, users)
    }
    + addComment := func(issue *youtrack.Issue, description string, comment *youtrack.Comment) {
    + // Add the description at the end to make sure all the field changes
    + // are always listed before it.
    + if description != "" {
    + if comment.Text != "" {
    + comment.Text += "\n\n"
    + }
    + comment.Text += description
    + }
    +
    + // double check if there is no comment.text and if so dump in a
    + // *no description*.
    + if comment.Text == "" {
    + comment.Text = "*no description*"
    + }
    +
    + // our changes were loaded from the database ordered by timestamp,
    + // so if we hit a new time stamp, we're in a new change.
    + issue.Comments = append(issue.Comments, comment)
    + }
    +
    issue := &youtrack.Issue{
    Number: t.ID,
    Summary: t.Summary,
    @@ -197,20 +218,9 @@
    var description string
    for _, change := range t.Changes {
    if comment != nil && convertTime(change.Time) != comment.Created {
    - // Add the description at the end to make sure all the field changes
    - // are always listed before it.
    - if description != "" {
    - if comment.Text != "" {
    - comment.Text += "\n\n"
    - }
    - comment.Text += description
    - description = ""
    - }
    -
    - // our changes were loaded from the database ordered by timestamp,
    - // so if we hit a new time stamp, we're in a new change.
    - issue.Comments = append(issue.Comments, comment)
    + addComment(issue, description, comment)
    comment = nil
    + description = ""
    }
    if comment == nil {
    @@ -277,17 +287,10 @@
    comment.Text += text
    }
    - // Add the description at the end to make sure all the field changes are
    - // always listed before it.
    - if description != "" {
    - if comment.Text != "" {
    - comment.Text += "\n\n"
    - }
    - comment.Text += description
    - }
    -
    if comment != nil {
    - issue.Comments = append(issue.Comments, comment)
    + addComment(issue, description, comment)
    + comment = nil
    + description = ""
    }
    // add all of the attachments