Skip to content

Commit

Permalink
Merge branch 'release/0.3.0b2'
Browse files Browse the repository at this point in the history
  • Loading branch information
shomatan committed Jun 12, 2018
2 parents 03cd17c + 7bef868 commit a3c66df
Show file tree
Hide file tree
Showing 21 changed files with 37 additions and 67 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Download

Please download the jar file from this link, and run from the command line as follows.

https://github.com/nulab/BacklogMigration-Jira/releases/download/0.3.0b1/backlog-migration-jira-0.3.0b1.jar
https://github.com/nulab/BacklogMigration-Jira/releases/download/0.3.0b2/backlog-migration-jira-0.3.0b2.jar

java -jar backlog-migration-jira-[latest version].jar

Expand Down Expand Up @@ -169,9 +169,6 @@ Single-byte **lowercase** character → Single-byte **uppercase** character
### About change logs
* Worklog is not supported. Scheduled for next release.

### About limitations in Backlog
* Importing users will be terminated if the number of users will exceed the limit in Backlog.

## Re-importing

When the project key in Backlog and JIRA matches, they will be considered as the same project and data will be imported as follows.
Expand Down Expand Up @@ -221,7 +218,7 @@ https://github.com/nulab/BacklogMigration-Jira/releases

こちらのリンクからjarファイルをダウンロードし、以下のようにコマンドラインから実行します。

https://github.com/nulab/BacklogMigration-Jira/releases/download/0.3.0b1/backlog-migration-jira-0.3.0b1.jar
https://github.com/nulab/BacklogMigration-Jira/releases/download/0.3.0b2/backlog-migration-jira-0.3.0b2.jar

java -jar backlog-migration-jira-[最新バージョン].jar

Expand Down Expand Up @@ -364,9 +361,6 @@ Backlogで **マックスプラン以上** のプランを契約している必
### Change logについて
* Worklogには対応していません。(次回リリースで対応予定)

### Backlog側の制限について
* Backlogで登録可能なユーザー数を超えた場合、インポートは中断されます。

## 再インポートの仕様

Backlog側にJIRAに対応するプロジェクトキーがある場合同一プロジェクトとみなし、以下の仕様でインポートされます。
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sbt.Keys._

scapegoatVersion in ThisBuild := "1.3.3"

lazy val projectVersion = "0.3.0b1"
lazy val projectVersion = "0.3.0b2"

lazy val commonSettings = Seq(
organization := "com.nulabinc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object AttachmentFilter {
fileNamePattern.findAllMatchIn(comment.body).map(m => m.group(1))
}

private [exporter] def findComment(fileName: String, comments: Seq[Comment]): Seq[Comment] =
private [exporter] def findComment(comments: Seq[Comment]): Seq[Comment] =
comments.filter { comment =>
fileNamePattern.findAllMatchIn(comment.body).nonEmpty
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@ import com.nulabinc.backlog.migration.common.conf.{BacklogConstantValue, Backlog
import com.nulabinc.backlog.migration.common.domain._
import com.nulabinc.backlog.migration.common.utils.{IOUtil, Logging}
import com.nulabinc.jira.client._
import com.nulabinc.jira.client.domain.Attachment
import com.nulabinc.jira.client.domain.changeLog._
import com.osinka.i18n.Messages

private [exporter] class ChangeLogReducer(issueDirPath: Path,
backlogPaths: BacklogPaths,
issue: BacklogIssue,
comments: Seq[BacklogComment],
attachments: Seq[Attachment],
issueService: IssueService)
extends Logging {

def reduce(targetComment: BacklogComment, changeLog: BacklogChangeLog): (Option[BacklogChangeLog], String) = {
def reduce(changeLog: BacklogChangeLog): (Option[BacklogChangeLog], String) = {
changeLog.field match {
case BacklogConstantValue.ChangeLog.ATTACHMENT => attachment(changeLog)
case "done_ratio" =>
Expand Down Expand Up @@ -60,7 +56,7 @@ private [exporter] class ChangeLogReducer(issueDirPath: Path,
val message = Messages("common.change_comment", Messages("common.sprint"), getValue(changeLog.optOriginalValue), getValue(changeLog.optNewValue))
(None, s"${message}\n")
case _ =>
(Some(changeLog.copy(optNewValue = ValueReducer.reduce(targetComment, changeLog))), "")
(Some(changeLog.copy(optNewValue = ValueReducer.reduce(changeLog))), "")
}
}

Expand Down Expand Up @@ -126,7 +122,7 @@ private [exporter] class ChangeLogReducer(issueDirPath: Path,
}

object ValueReducer {
def reduce(targetComment: BacklogComment, changeLog: BacklogChangeLog): Option[String] = {
def reduce(changeLog: BacklogChangeLog): Option[String] = {
changeLog.field match {
// case BacklogConstantValue.ChangeLog.VERSION | BacklogConstantValue.ChangeLog.MILESTONE =>
// findProperty(comments)(changeLog.field) match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@ class CommentFileWriter @Inject()(implicit val commentWrites: CommentWrites,
val backlogComments = backlogChangeLogsAsComment ++ backlogCommentsAsComment // TODO: sort?
val reducedComments = backlogComments.zipWithIndex.map {
case (comment, index) =>
exportComment(comment._1, backlogIssue, backlogComments.map(_._1), attachments, comment._2, index)
exportComment(comment._1, backlogIssue, comment._2, index)
}
Right(reducedComments)
}

private def exportComment(comment: BacklogComment,
issue: BacklogIssue,
comments: Seq[BacklogComment],
attachments: Seq[Attachment],
createdAt: Date,
index: Int) = {

import com.nulabinc.backlog.migration.common.domain.BacklogJsonProtocol._

val issueDirPath = backlogPaths.issueDirectoryPath("comment", issue.id, createdAt, index)
val changeLogReducer = new ChangeLogReducer(issueDirPath, backlogPaths, issue, comments, attachments, issueService)
val changeLogReducer = new ChangeLogReducer(issueDirPath, backlogPaths, issueService)
val commentReducer = new CommentReducer(issue.id, changeLogReducer)
val reduced = commentReducer.reduce(comment)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ private [exporter] class CommentReducer(issueId: Long, changeLogReducer: ChangeL
def reduce(comment: BacklogComment): BacklogComment = {
val changeLogContent = new StringBuilder()
val newChangeLogs = comment.changeLogs.flatMap { changeLog =>
val (optNewChangeLog, addingContent) = changeLogReducer.reduce(comment, changeLog)
val (optNewChangeLog, addingContent) = changeLogReducer.reduce(changeLog)
changeLogContent.append(addingContent)
optNewChangeLog
}
val optNewContent = comment.optContent match {
case Some(content) =>
val newContent = (s"${changeLogContent.result()}\n${content}").trim
val newContent = s"${changeLogContent.result()}\n$content".trim
StringUtil.notEmpty(newContent)
case None =>
StringUtil.notEmpty(changeLogContent.result().trim)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ class Exporter @Inject()(projectKey: JiraProjectKey,

commentWriter.write(initializedBacklogIssue, comments, changeLogs, issue.attachments)

// console(i + index.toInt, total.toInt)

calculator.progress(i + index.toInt, total.toInt, issue.summary)
calculator.progress(i + index.toInt)

val changeLogUsers = changeLogs.map(u => Some(u.author.name))
val changeLogItemUsers = changeLogs.flatMap { changeLog =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import javax.inject.Inject
import com.nulabinc.backlog.j2b.issue.writer.convert._
import com.nulabinc.backlog.j2b.jira.domain.export._
import com.nulabinc.backlog.j2b.jira.domain.mapping.MappingCollectDatabase
import com.nulabinc.backlog.j2b.jira.service.{IssueService, UserService}
import com.nulabinc.backlog.j2b.jira.service.UserService
import com.nulabinc.backlog.j2b.jira.utils._
import com.nulabinc.backlog.migration.common.convert.Convert
import com.nulabinc.backlog.migration.common.domain._
Expand All @@ -19,8 +19,7 @@ class IssueInitializer @Inject()(implicit val issueWrites: IssueWrites,
implicit val userWrites: UserWrites,
implicit val customFieldWrites: FieldWrites,
implicit val customFieldValueWrites: IssueFieldWrites,
userService: UserService,
issueService: IssueService)
userService: UserService)
extends Logging
with SecondToHourFormatter
with DatetimeToDateFormatter {
Expand All @@ -47,7 +46,6 @@ class IssueInitializer @Inject()(implicit val issueWrites: IssueWrites,
optEstimatedHours = estimatedHours(filteredIssue),
optIssueTypeName = issueTypeName(filteredIssue),
categoryNames = categoryNames(filteredIssue),
// milestoneNames = milestoneNames(filteredIssue, milestones),
milestoneNames = milestones.map(_.name),
versionNames = versionNames(filteredIssue),
priorityName = priorityName(filteredIssue),
Expand Down Expand Up @@ -109,9 +107,6 @@ class IssueInitializer @Inject()(implicit val issueWrites: IssueWrites,
private def versionNames(issue: Issue): Seq[String] =
ChangeLogsPlayer.reversePlay(FixVersion, issue.fixVersions.map(_.name), issue.changeLogs)

private def milestoneNames(issue: Issue, milestones: Seq[Milestone]): Seq[String] =
ChangeLogsPlayer.reversePlay(SprintChangeLogItemField, milestones.map(_.name), issue.changeLogs)

private def attachmentNames(issue: Issue): Seq[BacklogAttachment] = {
val histories = ChangeLogsPlayer.reversePlay(AttachmentChangeLogItemField, issue.attachments.map(_.fileName), issue.changeLogs)
histories.map { h =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ 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 = {
Expand All @@ -35,7 +32,7 @@ class RemainingTimeCalculator(totalSize: Long) extends Logging {
private[this] var newLine = false
private[this] var isMessageMode = false

def progress(indexOfDate: Int, totalOfDate: Int, summary: String): Unit = {
def progress(indexOfDate: Int): Unit = {
newLine = indexOfDate == 1
clear()
remainingTime = remainingTime.action()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@ package com.nulabinc.backlog.j2b.exporter.service

import better.files.{File => Path}
import javax.inject.Inject
import com.nulabinc.backlog.j2b.jira.conf.JiraApiConfiguration
import com.nulabinc.backlog.j2b.jira.domain.JiraProjectKey
import com.nulabinc.backlog.j2b.jira.service.IssueService
import com.nulabinc.backlog.migration.common.conf.BacklogPaths
import com.nulabinc.backlog.migration.common.utils.Logging
import com.nulabinc.jira.client.domain.changeLog.ChangeLog
import com.nulabinc.jira.client.{DownloadResult, JiraRestClient}
import com.nulabinc.jira.client.domain.issue.Issue

class JiraClientIssueService @Inject()(apiConfig: JiraApiConfiguration,
projectKey: JiraProjectKey,
jira: JiraRestClient,
backlogPaths: BacklogPaths)
class JiraClientIssueService @Inject()(projectKey: JiraProjectKey,
jira: JiraRestClient)
extends IssueService with Logging {

override def count(): Long = {
Expand All @@ -39,7 +35,7 @@ class JiraClientIssueService @Inject()(apiConfig: JiraApiConfiguration,
override def changeLogs(issue: Issue): Seq[ChangeLog] = {

def fetch(issue: Issue, startAt: Long, maxResults: Long, changeLogs: Seq[ChangeLog]): Seq[ChangeLog] =
jira.issueAPI.changeLogs(issue.id.toString, startAt, maxResults) match {
jira.issueAPI.changeLogs(issue.id.toString) match {
case Right(result) =>
val appendedChangeLogs = changeLogs ++ result.values
if (result.hasPage) fetch(issue, startAt + maxResults, maxResults, appendedChangeLogs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ class AttachmentFilterSpec extends Specification {
),
status = Status("1", "status"),
priority = Priority("priority"),
creator = User(Some("key"), "name", "display", "mail"),
creator = User(Some("key"), "name", "display", Some("mail")),
createdAt = new Date(),
updatedAt = new Date(),
changeLogs = Seq.empty[ChangeLog],
attachments = Seq(
Attachment(
id = 1,
fileName = "file1.txt",
author = User(Some("key1"), "user1", "user1", "mail1"),
author = User(Some("key1"), "user1", "user1", Some("mail1")),
createdAt = new Date(),
size = 100,
mimeType = "mine",
Expand All @@ -48,7 +48,7 @@ class AttachmentFilterSpec extends Specification {
Attachment(
id = 2,
fileName = "file2.txt",
author = User(Some("key2"), "user2", "user2", "mail2"),
author = User(Some("key2"), "user2", "user2", Some("mail2")),
createdAt = new Date(),
size = 200,
mimeType = "mine",
Expand All @@ -57,7 +57,7 @@ class AttachmentFilterSpec extends Specification {
Attachment(
id = 3,
fileName = "file3.txt",
author = User(Some("key3") ,"user3", "user3", "mail3"),
author = User(Some("key3") ,"user3", "user3", Some("mail3")),
createdAt = new Date(),
size = 300,
mimeType = "mine",
Expand All @@ -70,7 +70,7 @@ class AttachmentFilterSpec extends Specification {
Comment(
id = 1,
body = "test1 body [^file2.txt] ",
author = User(Some("aaa"), "aaa", "aaa", "mmm"),
author = User(Some("aaa"), "aaa", "aaa", Some("mmm")),
createdAt = new Date()
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class IssueRestClientImpl(httpClient: HttpClient) extends Pageable {
}
}

def changeLogs(issueIdOrKey: String, startAt: Long, maxResults: Long): Either[JiraRestClientError, ChangeLogResult] =
def changeLogs(issueIdOrKey: String): Either[JiraRestClientError, ChangeLogResult] =
httpClient.get(s"/issue/$issueIdOrKey/changelog") match {
case Right(json) => Right(JsonParser(json).convertTo[ChangeLogResult])
case Left(_: ApiNotFoundError) => Right(ChangeLogResult(0, true, Seq.empty[ChangeLog]))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.nulabinc.jira.client.domain

case class User(key: Option[String], name: String, displayName: String, emailAddress: String) {
case class User(key: Option[String], name: String, displayName: String, emailAddress: Option[String]) {

def identifyKey: String = key.getOrElse(name)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ trait MappingFile extends Logging {
// }

def errors: Seq[String] = {
val fileName = File(filePath).path.toAbsolutePath.getFileName.toString
val validator = new MappingValidator(jiras, backlogs, itemName, fileName)
val validator = new MappingValidator(jiras, backlogs, itemName)
validator.validate(unMarshal())
}

Expand All @@ -111,8 +110,7 @@ trait MappingFile extends Logging {

private class MappingValidator(jiraMappings: Seq[MappingItem],
backlogMappings: Seq[MappingItem],
itemName: String,
fileName: String) {
itemName: String) {

implicit val userLang = if (Locale.getDefault.equals(Locale.JAPAN)) Lang("ja") else Lang("en")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MappingCollectDatabaseInMemory extends MappingCollectDatabase {

override def add(optName: Option[String]) = optName match {
case Some(name) =>
val user = User(key = Some(name), name = name, displayName = name, emailAddress = "")
val user = User(key = Some(name), name = name, displayName = name, emailAddress = None)
userSet += user
Some(user)
case None => None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class MappingUserConverter @Inject()(implicit val userWrites: UserWrites)
case Some(mapping) if mapping.dst.nonEmpty => Mapping(None, mapping.dst, mapping.dst)
case _ => mappings.find(u => u.src.trim == userName.trim) match {
case Some(mapping) if mapping.dst.nonEmpty => Mapping(None, mapping.dst, mapping.dst)
case _ => mappingOfInfoName(mappingCollectDatabase, mappings, userName)
case _ => mappingOfInfoName(mappingCollectDatabase, userName)
}
}

private def mappingOfInfoName(mappingCollectDatabase: MappingCollectDatabase, mappings: Seq[Mapping], userName: String): Mapping = {
private def mappingOfInfoName(mappingCollectDatabase: MappingCollectDatabase, userName: String): Mapping = {
mappingCollectDatabase.findByName(Some(userName)) match {
case Some(user) => Mapping(None, user.name, user.name)
case _ => Mapping(None, userName, userName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import better.files.{File => Path}

import javax.inject.Inject
import com.nulabinc.jira.client.domain.{Priority => JiraPriority, Status => JiraStatus, User => JiraUser}
import com.nulabinc.backlog.j2b.jira.conf.JiraApiConfiguration
import com.nulabinc.backlog.j2b.jira.domain.mapping.MappingFile
import com.nulabinc.backlog.j2b.jira.service.MappingFileService
import com.nulabinc.backlog.migration.common.conf.BacklogApiConfiguration
Expand All @@ -13,8 +12,7 @@ import com.nulabinc.backlog.migration.common.utils.IOUtil
import com.nulabinc.backlog4j.{Priority => BacklogPriority, Status => BacklogStatus}
import spray.json._

class MappingFileServiceImpl @Inject()(jiraApiConfig: JiraApiConfiguration,
backlogApiConfig: BacklogApiConfiguration)
class MappingFileServiceImpl @Inject()(backlogApiConfig: BacklogApiConfiguration)
extends MappingFileService {

override def createUserMappingFile(jiraUsers: Set[JiraUser], backlogUsers: Seq[BacklogUser]): MappingFile =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UserWrites extends Writes[User, BacklogUser] {
optUserId = Some(user.identifyKey), // TODO: check impl. user.key?
optPassword = None,
name = user.name,
optMailAddress = Some(user.emailAddress),
optMailAddress = user.emailAddress,
roleType = BacklogConstantValue.USER_ROLE
)
}
2 changes: 1 addition & 1 deletion src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
application {
name = "Backlog Migration for Jira"
version = "0.3.0b1"
version = "0.3.0b2"
title = ${application.name} ${application.version} (c) nulab.inc
fileName = backlog-migration-jira-${application.version}.jar
product = "jira"
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/com/nulabinc/backlog/j2b/CompareSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CompareSpec extends FlatSpec
testIssueType(appConfig.backlogConfig)
testCategory(appConfig.jiraConfig, appConfig.backlogConfig)
testCustomFieldDefinitions(appConfig.backlogConfig)
testIssue(appConfig.jiraConfig, appConfig.backlogConfig)
testIssue(appConfig.backlogConfig)

def testProject(jiraConfig: JiraApiConfiguration, backlogConfig: BacklogApiConfiguration): Unit = {
"Project" should "match" in {
Expand Down Expand Up @@ -110,7 +110,7 @@ class CompareSpec extends FlatSpec
}
}

def testIssue(jiraConfig: JiraApiConfiguration, backlogConfig: BacklogApiConfiguration): Unit = {
def testIssue(backlogConfig: BacklogApiConfiguration): Unit = {

val backlogProject = backlogApi.getProject(backlogConfig.projectKey)
val params = new GetIssuesParams(List(Long.box(backlogProject.getId)).asJava)
Expand Down
Loading

0 comments on commit a3c66df

Please sign in to comment.