Skip to content

Commit

Permalink
BDOG-183 adjust presentation of Bobby Rules range
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-lamed committed May 7, 2019
1 parent 48f683f commit 7f0f521
Showing 10 changed files with 59 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -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")
}
}
Original file line number Diff line number Diff line change
@@ -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]
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}

15 changes: 13 additions & 2 deletions app/views/BobbyExplorerPage.scala.html
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ <h1>Bobby Rules</h1>
<thead>
<tr>
<th>@artifactType</th>
<th>Banned Versions</th>
<th colspan="3">Banned Versions</th>
<th>Reason</th>
<th>Active from</th>
</tr>
@@ -61,7 +61,18 @@ <h1>Bobby Rules</h1>
@bobbyRuleRow(rule: BobbyRule) = {
<tr class="bobby-rule">
<td><a name="@rule.name">@rule.groupArtifactName</a></td>
<td data-toggle="tooltip" data-placement="top" title="@rule.range.range">@rule.range.description</td>
@defining(rule.range.rangeDescr) { rangeDescr =>
@rangeDescr match {
case Some((lbDescr, upDescr)) => {
<td data-toggle="tooltip" title="@rule.range.range" style="white-space: nowrap; padding-right: 0; text-align: right">@lbDescr</td>
<td data-toggle="tooltip" title="@rule.range.range">x</td>
<td data-toggle="tooltip" title="@rule.range.range" style="white-space: nowrap; padding-left: 0; text-align: left">@upDescr</td>
}
case None => {
<td colspan="3">@rule.range.range</td>
}
}
}
<td>@rule.reason</td>
<td>@rule.from</td>
</tr>
5 changes: 2 additions & 3 deletions app/views/partials/DependenciesPartial.scala.html
Original file line number Diff line number Diff line change
@@ -36,9 +36,8 @@ <h3 class="board__heading">Platform Dependencies</h3>
@if(dependencyDataAvailable()) {
<li>
<span class="col-xs-4"><label>Libraries</label></span>
<span class="col-xs-2"><label>Current Version</label></span>
<span class="col-xs-1"><label> </label></span>
<span class="col-xs-2"><label>Latest Version</label></span>
<span class="col-xs-3"><label>Current Version</label></span>
<span class="col-xs-3"><label>Latest Version</label></span>
<span class="col-xs-2"><label>Bobby Rule Violation</label></span>
</li>
@partials.dependency_section(mayBeDependencies.get.libraryDependencies)
5 changes: 2 additions & 3 deletions app/views/partials/DependenciesTeamPartial.scala.html
Original file line number Diff line number Diff line change
@@ -40,9 +40,8 @@ <h3 class="board__heading">Out of Date Platform Dependencies for Team @teamName<
<h4>@dependency.repositoryName</h4>
<li>
<span class="col-xs-4"><label>Dependency</label></span>
<span class="col-xs-2"><label>Current Version</label></span>
<span class="col-xs-1"><label> </label></span>
<span class="col-xs-2"><label>Latest Version</label></span>
<span class="col-xs-3"><label>Current Version</label></span>
<span class="col-xs-3"><label>Latest Version</label></span>
<span class="col-xs-2"><label>Bobby Rule Violation</label></span>

</li>
10 changes: 6 additions & 4 deletions app/views/partials/dependency_section.scala.html
Original file line number Diff line number Diff line change
@@ -30,10 +30,12 @@
@dependency.name
}
</span>
<span id="@{dependency.name}-current-version" class="col-xs-2">@dependency.currentVersion.toString</span>
<span class="col-xs-1 glyphicon glyphicon-arrow-right small-glyphicon"> </span>
<span id="@{dependency.name}-latestVersion-version" class="col-xs-2">@dependency.latestVersion.map(_.toString).getOrElse("(not found)")</span>
<span id="@{dependency.name}-latestVersion-version" class="col-xs-2">
<span id="@{dependency.name}-current-version" class="col-xs-3">@dependency.currentVersion.toString</span>
<span id="@{dependency.name}-latestVersion-version" class="col-xs-3">
<span class="glyphicon glyphicon-arrow-right small-glyphicon" style="padding-right: 10;"> </span>
@dependency.latestVersion.map(_.toString).getOrElse("(not found)")
</span>
<span id="@{dependency.name}-bobbyrule" class="col-xs-2">
@if(dependency.versionState.fold(false)(v => List(VersionState.BobbyRuleViolated, VersionState.BobbyRulePending).contains(v))) {
<a href="@{appRoutes.BobbyExplorerController.list()}#@{dependency.name}">See rule</a>
} else { }
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -46,15 +46,15 @@ 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 {
new Dependency(
"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")))
14 changes: 10 additions & 4 deletions test/view/partials/DependencySectionSpec.scala
Original file line number Diff line number Diff line change
@@ -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 ("<span id=\"example-library-current-version\" class=\"col-xs-3\">1.2.3-play-25</span>")
res should include ("<span id=\"example-library-latestVersion-version\" class=\"col-xs-3\">1.2.3-play-26</span>")
res should include ("""<span id="example-library-current-version" class="col-xs-3">1.2.3-play-25</span>""")
res should include ("""<span id="example-library-latestVersion-version" class="col-xs-3">
| <span class="glyphicon glyphicon-arrow-right small-glyphicon" style="padding-right: 10;"> </span>
| 1.2.3-play-26
| </span>""".stripMargin)
}

"not display the version suffix when missing" in {
val res = views.html.partials.dependency_section(Seq(dependency2)).body
res should include ("<span id=\"library4j-current-version\" class=\"col-xs-3\">4.0.1</span>")
res should include ("<span id=\"library4j-latestVersion-version\" class=\"col-xs-3\">4.2.0</span>")
res should include ("""<span id="library4j-current-version" class="col-xs-3">4.0.1</span>""")
res should include ("""<span id="library4j-latestVersion-version" class="col-xs-3">
| <span class="glyphicon glyphicon-arrow-right small-glyphicon" style="padding-right: 10;"> </span>
| 4.2.0
| </span>""".stripMargin)
}
}

0 comments on commit 7f0f521

Please sign in to comment.