From 97997354200b309b16bc7d3aee15950b5dd83109 Mon Sep 17 00:00:00 2001 From: Istvan Meszaros Date: Mon, 12 Jun 2017 06:52:49 +0200 Subject: [PATCH] Eliminate manual emtpy to none conversion. This may close #1396 --- .../core/controller/PrioritiesController.scala | 4 ++-- .../gitbucket/core/service/PrioritiesService.scala | 8 ++++---- .../core/service/RepositoryCreationService.scala | 10 +++++----- src/main/scala/gitbucket/core/util/StringUtil.scala | 2 -- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/scala/gitbucket/core/controller/PrioritiesController.scala b/src/main/scala/gitbucket/core/controller/PrioritiesController.scala index ab24b59f7..e0e010a3e 100644 --- a/src/main/scala/gitbucket/core/controller/PrioritiesController.scala +++ b/src/main/scala/gitbucket/core/controller/PrioritiesController.scala @@ -16,11 +16,11 @@ trait PrioritiesControllerBase extends ControllerBase { self: PrioritiesService with IssuesService with RepositoryService with ReferrerAuthenticator with WritableUsersAuthenticator => - case class PriorityForm(priorityName: String, description: String, color: String) + case class PriorityForm(priorityName: String, description: Option[String], color: String) val priorityForm = mapping( "priorityName" -> trim(label("Priority name", text(required, priorityName, uniquePriorityName, maxlength(100)))), - "description" -> trim(label("Description", text(maxlength(255)))), + "description" -> trim(label("Description", optional(text(maxlength(255))))), "priorityColor" -> trim(label("Color", text(required, color))) )(PriorityForm.apply) diff --git a/src/main/scala/gitbucket/core/service/PrioritiesService.scala b/src/main/scala/gitbucket/core/service/PrioritiesService.scala index fa4e4059a..cafff4b15 100644 --- a/src/main/scala/gitbucket/core/service/PrioritiesService.scala +++ b/src/main/scala/gitbucket/core/service/PrioritiesService.scala @@ -16,7 +16,7 @@ trait PrioritiesService { def getPriority(owner: String, repository: String, priorityName: String)(implicit s: Session): Option[Priority] = Priorities.filter(_.byPriority(owner, repository, priorityName)).firstOption - def createPriority(owner: String, repository: String, priorityName: String, description: String, color: String)(implicit s: Session): Int = { + def createPriority(owner: String, repository: String, priorityName: String, description: Option[String], color: String)(implicit s: Session): Int = { val ordering = Priorities.filter(_.byRepository(owner, repository)) .list .map(p => p.ordering) @@ -28,18 +28,18 @@ trait PrioritiesService { userName = owner, repositoryName = repository, priorityName = priorityName, - description = StringUtil.emptyToNone(description), + description = description, isDefault = false, ordering = ordering, color = color ) } - def updatePriority(owner: String, repository: String, priorityId: Int, priorityName: String, description: String, color: String) + def updatePriority(owner: String, repository: String, priorityId: Int, priorityName: String, description: Option[String], color: String) (implicit s: Session): Unit = Priorities.filter(_.byPrimaryKey(owner, repository, priorityId)) .map(t => (t.priorityName, t.description.?, t.color)) - .update(priorityName, StringUtil.emptyToNone(description), color) + .update(priorityName, description, color) def reorderPriorities(owner: String, repository: String, order: Map[Int, Int]) (implicit s: Session): Unit = { diff --git a/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala b/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala index 97df82d49..2aa419649 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala @@ -78,11 +78,11 @@ trait RepositoryCreationService { } def insertDefaultPriorities(userName: String, repositoryName: String)(implicit s: Session): Unit = { - createPriority(userName, repositoryName, "highest", "All defects at this priority must be fixed before any public product is delivered.", "fc2929") - createPriority(userName, repositoryName, "very high", "Issues must be addressed before a final product is delivered.", "fc5629") - createPriority(userName, repositoryName, "high", "Issues should be addressed before a final product is delivered. If the issue cannot be resolved before delivery, it should be prioritized for the next release.", "fc9629") - createPriority(userName, repositoryName, "important", "Issues can be shipped with a final product, but should be reviewed before the next release.", "fccd29") - createPriority(userName, repositoryName, "default", "Default.", "acacac") + createPriority(userName, repositoryName, "highest", Some("All defects at this priority must be fixed before any public product is delivered."), "fc2929") + createPriority(userName, repositoryName, "very high", Some("Issues must be addressed before a final product is delivered."), "fc5629") + createPriority(userName, repositoryName, "high", Some("Issues should be addressed before a final product is delivered. If the issue cannot be resolved before delivery, it should be prioritized for the next release."), "fc9629") + createPriority(userName, repositoryName, "important", Some("Issues can be shipped with a final product, but should be reviewed before the next release."), "fccd29") + createPriority(userName, repositoryName, "default", Some("Default."), "acacac") setDefaultPriority(userName, repositoryName, getPriority(userName, repositoryName, "default").map(_.priorityId)) } diff --git a/src/main/scala/gitbucket/core/util/StringUtil.scala b/src/main/scala/gitbucket/core/util/StringUtil.scala index 2b0bb6c9d..908fd2586 100644 --- a/src/main/scala/gitbucket/core/util/StringUtil.scala +++ b/src/main/scala/gitbucket/core/util/StringUtil.scala @@ -136,6 +136,4 @@ object StringUtil { // } // b.toString // } - - def emptyToNone(str: String): Option[String] = Option(str).map(_.trim).flatMap(s => if (s.isEmpty) None else Some(s)); }