grim/youtrack-import

5e6c52f18f2b
Parents 40147089502f
Children 05e3584f22bf
Remove the `Replying to` bits from comments. Fixes YI-29
  • +19 -12
    trac/tickets.go
  • --- a/trac/tickets.go Tue Jul 28 01:07:24 2020 -0500
    +++ b/trac/tickets.go Tue Jul 28 21:40:48 2020 -0500
    @@ -92,8 +92,26 @@
    // things, so we just use the same regex to figure out the extension for
    // attachments.
    attachmentRegex = regexp.MustCompile(`\.[A-Za-z0-9]+$`)
    +
    + // trac comments that are replies specify usernames which we can't/don't
    + // want to put in our resulting comments.
    + commentReplyingRegex = regexp.MustCompile(`^(?:(?:\> )*Replying to (?:[^]]+)\]:\r\n)+`)
    )
    +func (tc *ticketChange) cleanNewValue() string {
    + if tc.Field == "comment" {
    + if strings.Contains(convertString(tc.OldValue), ".") {
    + str := convertString(tc.NewValue)
    + loc := commentReplyingRegex.FindIndex([]byte(str))
    + if loc != nil {
    + return str[loc[1]:]
    + }
    + }
    + }
    +
    + return tc.NewValue.String
    +}
    +
    func (t *ticket) toYoutrack(users map[string]*youtrack.User, unknownUser string) (*youtrack.Issue, error) {
    convertUsername := func(sqluser sql.NullString) string {
    username := convertString(sqluser)
    @@ -176,18 +194,7 @@
    text := ""
    switch change.Field {
    case "comment":
    - description = convertString(change.NewValue)
    -
    - // if the comment is a reply, we strip off the first line as there's
    - // now way to replicated this properly in youtrack. Note trac uses
    - // `\r` like a bunch of weirdos...
    - if strings.Contains(convertString(change.OldValue), ".") {
    - newLine := strings.Index(description, "\r")
    - if newLine != -1 {
    - description = description[newLine+1:]
    - }
    - }
    -
    + description = change.cleanNewValue()
    continue
    case "description":
    issue.UpdatedBy = convertUsername(change.Author)