-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
179 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
exporter/src/main/scala/com/nulabinc/backlog/j2b/exporter/ChangeLogIssueLinkConverter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.nulabinc.backlog.j2b.exporter | ||
|
||
import com.nulabinc.backlog.migration.common.domain.BacklogIssue | ||
import com.nulabinc.jira.client.domain.changeLog._ | ||
|
||
object ChangeLogIssueLinkConverter { | ||
|
||
def convert(changeLogs: Seq[ChangeLog], backlogIssue: BacklogIssue): Seq[ChangeLog] = { | ||
val displayStrings = changeLogs.flatMap { changeLog => | ||
changeLog.items | ||
.filter { item => item.field == DefaultField("link_issue") } | ||
.flatMap { _.toDisplayString } | ||
} | ||
|
||
val linkedIssueChangeLogItems = if (displayStrings.nonEmpty) { | ||
val lastDescription = changeLogs.reverse.flatMap { changeLog => | ||
changeLog.items.reverse.find(_.field == DescriptionChangeLogItemField) | ||
}.headOption.flatMap(_.toDisplayString) | ||
|
||
Seq( | ||
ChangeLog( | ||
id = 0, // TODO: Check | ||
author = changeLogs.last.author, | ||
createdAt = changeLogs.last.createdAt, | ||
items = Seq( | ||
ChangeLogItem( | ||
field = DescriptionChangeLogItemField, | ||
fieldType = ChangeLogItem.FieldType.JIRA, | ||
fieldId = Some(DescriptionFieldId), | ||
from = None, | ||
fromDisplayString = lastDescription, | ||
to = None, | ||
toDisplayString = Some(lastDescription.getOrElse("") + backlogIssue.description + "\n\n" + displayStrings.mkString("\n")) | ||
) | ||
) | ||
) | ||
) | ||
} else { | ||
Seq.empty[ChangeLog] | ||
} | ||
|
||
changeLogs ++ linkedIssueChangeLogItems | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...er/src/main/scala/com/nulabinc/backlog/j2b/exporter/console/RemainingTimeCalculator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.nulabinc.backlog.j2b.exporter.console | ||
|
||
import java.util.Date | ||
|
||
import com.nulabinc.backlog.migration.common.utils.{ConsoleOut, DateUtil, Logging, ProgressBar} | ||
import com.osinka.i18n.Messages | ||
import org.fusesource.jansi.Ansi | ||
import org.fusesource.jansi.Ansi.ansi | ||
|
||
class RemainingTimeCalculator(totalSize: Long) extends Logging { | ||
|
||
private var failed = 0 | ||
private var date = "" | ||
|
||
private case class RemainingTime(totalSize: Long, lastTime: Long = System.currentTimeMillis(), totalElapsedTime: Long = 0, count: Long = 0) { | ||
|
||
def action(): RemainingTime = { | ||
val elapsedTime: Long = System.currentTimeMillis() - this.lastTime | ||
this.copy( | ||
lastTime = System.currentTimeMillis(), | ||
totalElapsedTime = totalElapsedTime + elapsedTime, | ||
count = count + 1 | ||
) | ||
} | ||
|
||
def average: Float = totalElapsedTime.toFloat / count.toFloat | ||
|
||
def remaining: Long = totalSize - count | ||
|
||
def remainingTime: Long = (remaining * average).toLong | ||
} | ||
|
||
private var remainingTime = RemainingTime(totalSize) | ||
|
||
private[this] var newLine = false | ||
private[this] var isMessageMode = false | ||
|
||
def progress(indexOfDate: Int, totalOfDate: Int, summary: String): Unit = { | ||
newLine = indexOfDate == 1 | ||
clear() | ||
remainingTime = remainingTime.action() | ||
val message = remaining() | ||
ConsoleOut.outStream.println(message) | ||
isMessageMode = false | ||
} | ||
|
||
private def clear(): Unit = { | ||
if (newLine && !isMessageMode) { | ||
ConsoleOut.outStream.println() | ||
} | ||
(0 until 3).foreach { _ => | ||
ConsoleOut.outStream.print(ansi.cursorLeft(999).cursorUp(1).eraseLine(Ansi.Erase.ALL)) | ||
} | ||
ConsoleOut.outStream.flush() | ||
newLine = false | ||
} | ||
|
||
private def remaining(): String = { | ||
val progressBar = ProgressBar.progressBar(remainingTime.count.toInt, remainingTime.totalSize.toInt) | ||
val time = Messages("export.remaining_time", DateUtil.timeFormat(new Date(remainingTime.remainingTime))) | ||
s"$progressBar $time" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters