diff --git a/app/uk/gov/hmrc/cataloguefrontend/connector/ConfigConnector.scala b/app/uk/gov/hmrc/cataloguefrontend/connector/ConfigConnector.scala index 2ed0cafb4..4833a7a2b 100644 --- a/app/uk/gov/hmrc/cataloguefrontend/connector/ConfigConnector.scala +++ b/app/uk/gov/hmrc/cataloguefrontend/connector/ConfigConnector.scala @@ -52,5 +52,8 @@ class ConfigConnector @Inject()( def configByKey(service: String)(implicit hc: HeaderCarrier) = http.GET[ConfigByKey](s"$serviceConfigsBaseUrl/config-by-key/$service") - def bobbyRules()(implicit hc: HeaderCarrier): Future[BobbyRuleSet] = http.GET[BobbyRuleSet](s"$serviceConfigsBaseUrl/bobby/rules") + def bobbyRules()(implicit hc: HeaderCarrier): Future[BobbyRuleSet] = { + implicit val brsr = BobbyRuleSet.reads + http.GET[BobbyRuleSet](s"$serviceConfigsBaseUrl/bobby/rules") + } } diff --git a/app/uk/gov/hmrc/cataloguefrontend/connector/model/BobbyRule.scala b/app/uk/gov/hmrc/cataloguefrontend/connector/model/BobbyRule.scala index 1d88c0ba1..ada6eeddf 100644 --- a/app/uk/gov/hmrc/cataloguefrontend/connector/model/BobbyRule.scala +++ b/app/uk/gov/hmrc/cataloguefrontend/connector/model/BobbyRule.scala @@ -28,14 +28,16 @@ case class BobbyRule(organisation: String, name: String, range: BobbyVersionRang } object BobbyRule { - implicit val reader: Reads[BobbyRule] = { - implicit val bvr = BobbyVersionRange.reads + val reads: Reads[BobbyRule] = { + implicit val bvrr = BobbyVersionRange.reads Json.reads[BobbyRule] } - } case class BobbyRuleSet(libraries: Seq[BobbyRule], plugins: Seq[BobbyRule]) object BobbyRuleSet { - implicit val reader: Reads[BobbyRuleSet] = Json.reads[BobbyRuleSet] + val reads: Reads[BobbyRuleSet] = { + implicit val brr = BobbyRule.reads + Json.reads[BobbyRuleSet] + } } \ No newline at end of file diff --git a/app/uk/gov/hmrc/cataloguefrontend/connector/model/Dependencies.scala b/app/uk/gov/hmrc/cataloguefrontend/connector/model/Dependencies.scala index 8b3aecb13..eb3a4ebc3 100644 --- a/app/uk/gov/hmrc/cataloguefrontend/connector/model/Dependencies.scala +++ b/app/uk/gov/hmrc/cataloguefrontend/connector/model/Dependencies.scala @@ -71,26 +71,20 @@ case class Dependencies( case class BobbyVersion(version: Version, inclusive: Boolean) -object BobbyVersion { - val reads: Reads[BobbyVersion] = { - implicit val bvf = Version.format - ( (__ \ "version" ).read[Version] - ~ (__ \ "inclusive").read[Boolean] - )(BobbyVersion.apply _) - } -} - case class BobbyVersionRange( lowerBound: Option[BobbyVersion] , upperBound: Option[BobbyVersion] , qualifier : Option[String] , range : String ) { - def description: String = { + + def rangeDescr: Option[(String, String)] = { def comp(v: BobbyVersion) = if (v.inclusive) " <= " else " < " - lowerBound.map(v => s"${v.version} ${comp(v)}").getOrElse("") + - "x" + - upperBound.map(v => s" ${comp(v)} ${v.version}").getOrElse("") + if (lowerBound.isDefined || upperBound.isDefined) { + Some(( lowerBound.map(v => s"${v.version} ${comp(v)}").getOrElse("") + , upperBound.map(v => s"${comp(v)} ${v.version}").getOrElse("") + )) + } else None } } diff --git a/app/views/BobbyExplorerPage.scala.html b/app/views/BobbyExplorerPage.scala.html index 8041f8c7d..25cfb81df 100644 --- a/app/views/BobbyExplorerPage.scala.html +++ b/app/views/BobbyExplorerPage.scala.html @@ -45,7 +45,7 @@

Bobby Rules

@artifactType - Banned Versions + Banned Versions Reason Active from @@ -61,7 +61,18 @@

Bobby Rules

@bobbyRuleRow(rule: BobbyRule) = { @rule.groupArtifactName - @rule.range.description + @defining(rule.range.rangeDescr) { rangeDescr => + @rangeDescr match { + case Some((lbDescr, upDescr)) => { + @lbDescr + x + @upDescr + } + case None => { + @rule.range.range + } + } + } @rule.reason @rule.from diff --git a/app/views/partials/DependenciesPartial.scala.html b/app/views/partials/DependenciesPartial.scala.html index 21f66b8a6..8e9dd62e2 100644 --- a/app/views/partials/DependenciesPartial.scala.html +++ b/app/views/partials/DependenciesPartial.scala.html @@ -36,9 +36,8 @@

Platform Dependencies

@if(dependencyDataAvailable()) {
  • - - - + +
  • @partials.dependency_section(mayBeDependencies.get.libraryDependencies) diff --git a/app/views/partials/DependenciesTeamPartial.scala.html b/app/views/partials/DependenciesTeamPartial.scala.html index 15321241c..f5a8166a8 100644 --- a/app/views/partials/DependenciesTeamPartial.scala.html +++ b/app/views/partials/DependenciesTeamPartial.scala.html @@ -40,9 +40,8 @@

    Out of Date Platform Dependencies for Team @teamName<

    @dependency.repositoryName

  • - - - + +
  • diff --git a/app/views/partials/dependency_section.scala.html b/app/views/partials/dependency_section.scala.html index f25fd3d9a..b173fb7db 100644 --- a/app/views/partials/dependency_section.scala.html +++ b/app/views/partials/dependency_section.scala.html @@ -30,10 +30,12 @@ @dependency.name } - @dependency.currentVersion.toString - - @dependency.latestVersion.map(_.toString).getOrElse("(not found)") - + @dependency.currentVersion.toString + + + @dependency.latestVersion.map(_.toString).getOrElse("(not found)") + + @if(dependency.versionState.fold(false)(v => List(VersionState.BobbyRuleViolated, VersionState.BobbyRulePending).contains(v))) { See rule } else { } diff --git a/test/uk/gov/hmrc/cataloguefrontend/connector/model/BobbyRuleFactory.scala b/test/uk/gov/hmrc/cataloguefrontend/connector/model/BobbyRuleFactory.scala index 76c42ac42..6f059ab0f 100644 --- a/test/uk/gov/hmrc/cataloguefrontend/connector/model/BobbyRuleFactory.scala +++ b/test/uk/gov/hmrc/cataloguefrontend/connector/model/BobbyRuleFactory.scala @@ -20,5 +20,5 @@ import java.time.LocalDate object BobbyRuleFactory { def aBobbyRule(organisation: String = "uk.gov.hmrc", name: String = "play-frontend", range: String = "[*-SNAPSHOT]", reason: String = "No snapshot dependencies permitted", from: LocalDate = LocalDate.of(2015, 3, 16)) = - BobbyRule(organisation, name, range, reason, from) + BobbyRule(organisation, name, BobbyVersionRange(range), reason, from) } diff --git a/test/uk/gov/hmrc/cataloguefrontend/connector/model/DependencySpec.scala b/test/uk/gov/hmrc/cataloguefrontend/connector/model/DependencySpec.scala index 7243ddc4b..8c5ec91e5 100644 --- a/test/uk/gov/hmrc/cataloguefrontend/connector/model/DependencySpec.scala +++ b/test/uk/gov/hmrc/cataloguefrontend/connector/model/DependencySpec.scala @@ -46,7 +46,7 @@ class DependencySpec extends FreeSpec with Matchers { "should return BobbyRuleViolated if dependency has any broken bobby rules" in { Dependency("library-abc", Version("1.2.3"), Some(Version("2.2.3")), - Seq(BobbyRuleViolation("banned library", "1.2.3", LocalDate.of(1,1,1)))).versionState shouldBe Some(VersionState.BobbyRuleViolated) + Seq(BobbyRuleViolation("banned library", BobbyVersionRange("1.2.3"), LocalDate.of(1,1,1)))).versionState shouldBe Some(VersionState.BobbyRuleViolated) } "should return BobbyRulePending if dependency will break future rules" in { @@ -54,7 +54,7 @@ class DependencySpec extends FreeSpec with Matchers { "library-abc" , Version("1.2.3") , Some(Version("2.2.3")) - , Seq(BobbyRuleViolation("banned library", "1.2.3", LocalDate.of(9999,1,1))(now = LocalDate.of(200,1,2))) + , Seq(BobbyRuleViolation("banned library", BobbyVersionRange("1.2.3"), LocalDate.of(9999,1,1))(now = LocalDate.of(200,1,2))) ) .versionState shouldBe Some(VersionState.BobbyRulePending) } @@ -64,8 +64,8 @@ class DependencySpec extends FreeSpec with Matchers { "library-abc" , Version("1.2.3") , Some(Version("2.2.3")) - , Seq( BobbyRuleViolation("banned library", "1.2.3", LocalDate.of(9999,1,1))(now = LocalDate.of(2000,1,2)) - , BobbyRuleViolation("banned library", "1.2.3", LocalDate.of(1,1,1))(now = LocalDate.of(2000,1,2)) + , Seq( BobbyRuleViolation("banned library", BobbyVersionRange("1.2.3"), LocalDate.of(9999,1,1))(now = LocalDate.of(2000,1,2)) + , BobbyRuleViolation("banned library", BobbyVersionRange("1.2.3"), LocalDate.of(1,1,1))(now = LocalDate.of(2000,1,2)) ) ).versionState shouldBe Some(VersionState.BobbyRuleViolated) } @@ -87,14 +87,14 @@ class DependencySpec extends FreeSpec with Matchers { "library-abc" , Version("1.2.3") , Some(Version("2.2.3")) - , Seq(BobbyRuleViolation("banned library", "1.2.3", LocalDate.of(1,1,1))(now = LocalDate.of(2000,1,2))) + , Seq(BobbyRuleViolation("banned library", BobbyVersionRange("1.2.3"), LocalDate.of(1,1,1))(now = LocalDate.of(2000,1,2))) ) val pendingDep = new Dependency( "library-xyz" , Version("1.2.3") , Some(Version("2.2.3")) - , Seq(BobbyRuleViolation("banned library", "1.2.3", LocalDate.of(9999,1,1))(now = LocalDate.of(2000,1,2))) + , Seq(BobbyRuleViolation("banned library", BobbyVersionRange("1.2.3"), LocalDate.of(9999,1,1))(now = LocalDate.of(2000,1,2))) ) val goodDep = Dependency("library-lol", Version("1.2.3"), Some(Version("2.2.3"))) @@ -115,14 +115,14 @@ class DependencySpec extends FreeSpec with Matchers { "library-abc" , Version("1.2.3") , Some(Version("2.2.3")) - , Seq(BobbyRuleViolation("banned library", "1.2.3", LocalDate.of(1,1,1))(now = LocalDate.of(2000,1,2))) + , Seq(BobbyRuleViolation("banned library", BobbyVersionRange("1.2.3"), LocalDate.of(1,1,1))(now = LocalDate.of(2000,1,2))) ) val pendingDep = new Dependency( "library-xyz" , Version("1.2.3") , Some(Version("2.2.3")) - , Seq(BobbyRuleViolation("banned library", "1.2.3", LocalDate.of(9999,1,1))(now = LocalDate.of(2000,1,2))) + , Seq(BobbyRuleViolation("banned library", BobbyVersionRange("1.2.3"), LocalDate.of(9999,1,1))(now = LocalDate.of(2000,1,2))) ) val goodDep = Dependency("library-lol", Version("1.2.3"), Some(Version("2.2.3"))) diff --git a/test/view/partials/DependencySectionSpec.scala b/test/view/partials/DependencySectionSpec.scala index 2addf7699..cd44d94e3 100644 --- a/test/view/partials/DependencySectionSpec.scala +++ b/test/view/partials/DependencySectionSpec.scala @@ -28,14 +28,20 @@ class DependencySectionSpec extends WordSpec with Matchers { "display the version suffix when present" in { val res = views.html.partials.dependency_section(Seq(dependency1)).body - res should include ("1.2.3-play-25") - res should include ("1.2.3-play-26") + res should include ("""1.2.3-play-25""") + res should include (""" + | + | 1.2.3-play-26 + | """.stripMargin) } "not display the version suffix when missing" in { val res = views.html.partials.dependency_section(Seq(dependency2)).body - res should include ("4.0.1") - res should include ("4.2.0") + res should include ("""4.0.1""") + res should include (""" + | + | 4.2.0 + | """.stripMargin) } }