Skip to content

Commit

Permalink
Merge pull request #72 from hmrc/BDOG-205
Browse files Browse the repository at this point in the history
BDOG-205 Adds violation count to bobby explorer
  • Loading branch information
christopherjturner authored May 31, 2019
2 parents 04118a5 + 98ece6b commit ff5fc49
Showing 6 changed files with 107 additions and 28 deletions.
23 changes: 19 additions & 4 deletions app/uk/gov/hmrc/cataloguefrontend/BobbyExplorerController.scala
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ package uk.gov.hmrc.cataloguefrontend

import javax.inject.Inject
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.cataloguefrontend.connector.{ServiceDependenciesConnector, SlugInfoFlag}
import uk.gov.hmrc.cataloguefrontend.service.BobbyService
import uk.gov.hmrc.play.bootstrap.controller.FrontendController
import views.html.BobbyExplorerPage
@@ -27,10 +28,24 @@ import scala.concurrent.ExecutionContext
class BobbyExplorerController @Inject()(
mcc : MessagesControllerComponents,
page : BobbyExplorerPage,
bobbyService: BobbyService
bobbyService: BobbyService,
serviceDeps : ServiceDependenciesConnector
)(implicit val ec: ExecutionContext
) extends FrontendController(mcc) {
def list(): Action[AnyContent] = Action.async { implicit request =>
bobbyService.getRules().map(r => Ok(page(r)))
}

def list(): Action[AnyContent] = Action.async { implicit request =>
for {
rules <- bobbyService.getRules()
countsLatest <- serviceDeps.getBobbyRuleViolations(SlugInfoFlag.Latest)
countsProd <- serviceDeps.getBobbyRuleViolations(SlugInfoFlag.Production)
countsQA <- serviceDeps.getBobbyRuleViolations(SlugInfoFlag.QA)
counts = Map( SlugInfoFlag.Latest.s -> countsLatest
,SlugInfoFlag.Production.s -> countsProd
,SlugInfoFlag.QA.s -> countsQA)
response = Ok(page(rules, counts))
} yield response

}


}
4 changes: 2 additions & 2 deletions app/uk/gov/hmrc/cataloguefrontend/CatalogueController.scala
Original file line number Diff line number Diff line change
@@ -342,12 +342,12 @@ class CatalogueController @Inject()(

def repository(name: String): Action[AnyContent] = Action.async { implicit request =>
for {
repository <- teamsAndRepositoriesConnector.repositoryDetails(name)
repository <- teamsAndRepositoriesConnector.repositoryDetails(name)
.map(_.map(repo => repo.copy(teamNames = {
val (owners, other) = repo.teamNames.partition(s => repo.owningTeams.contains(s))
owners.sorted ++ other.sorted
})))
indicators <- indicatorsConnector.buildIndicatorsForRepository(name)
indicators <- indicatorsConnector.buildIndicatorsForRepository(name)
optDependencies <- serviceDependencyConnector.getDependencies(name)
optUrlIfLeaksFound <- leakDetectionService.urlIfLeaksFound(name)
} yield
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ package uk.gov.hmrc.cataloguefrontend.connector

import javax.inject.{Inject, Singleton}
import play.api.Logger
import play.api.libs.json.Json
import uk.gov.hmrc.cataloguefrontend.connector.model._
import uk.gov.hmrc.cataloguefrontend.service.ServiceDependencies
import uk.gov.hmrc.http.HeaderCarrier
@@ -120,4 +121,11 @@ class ServiceDependenciesConnector @Inject()(

private def buildQueryParams(queryParams: (String, Option[String])*): Seq[(String, String)] =
queryParams.flatMap(param => param._2.map(v => (param._1, v)))

def getBobbyRuleViolations(flag: SlugInfoFlag)(implicit hc:HeaderCarrier): Future[Map[BobbyRule, Int]] = {
implicit val brvr = BobbyRuleViolationCount.reads

http.GET[Seq[BobbyRuleViolationCount]](url = s"$servicesDependenciesBaseUrl/bobbyViolations?flag=${flag.s}")
.map(_.map(br => br.rule -> br.count).toMap)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2019 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.cataloguefrontend.connector.model


import play.api.libs.json.{Json, Reads}


case class BobbyRuleViolationCount(rule: BobbyRule, count: Int)

object BobbyRuleViolationCount {
val reads: Reads[BobbyRuleViolationCount] = {
implicit val brr = BobbyRule.reads
Json.reads[BobbyRuleViolationCount]
}
}
62 changes: 44 additions & 18 deletions app/views/BobbyExplorerPage.scala.html
Original file line number Diff line number Diff line change
@@ -22,54 +22,72 @@

@this(viewMessages: ViewMessages)

@(rules: BobbyRulesView)(implicit request: Request[_])
@(rules: BobbyRulesView, counts: Map[String, Map[BobbyRule, Int]])(implicit request: Request[_])

@standard_layout(s"Bobby rules") {
<header>
<h1>Bobby Rules</h1>
</header>
@bobbyRulesTimeSection(rules.upcoming, "Upcoming")
@bobbyRulesTimeSection(rules.active, "Active")
@bobbyRulesTimeSection(rules.upcoming, "Upcoming", counts)
@bobbyRulesTimeSection(rules.active, "Active", counts)
}

@bobbyRulesTimeSection(rulesByTime: BobbyRuleSet, heading: String) = {
@bobbyRulesTimeSection(rulesByTime: BobbyRuleSet, heading: String, counts: Map[String, Map[BobbyRule, Int]]) = {
@if(rulesByTime.libraries.nonEmpty || rulesByTime.plugins.nonEmpty) {
<div><h2>@heading</h2></div>
@bobbyRulesArtifactTypeSection(rulesByTime.libraries, "Library", inclViewSlugsLink = true)
@bobbyRulesArtifactTypeSection(rulesByTime.plugins, "Plugin", inclViewSlugsLink = false)
@bobbyRulesArtifactTypeSection(rulesByTime.libraries, "Library", inclViewSlugsLink = true, counts: Map[String, Map[BobbyRule, Int]])
@bobbyRulesArtifactTypeSection(rulesByTime.plugins, "Plugin", inclViewSlugsLink = false, counts: Map[String, Map[BobbyRule, Int]])
}
}

@bobbyRulesArtifactTypeSection(rulesByArtifactType: Seq[BobbyRule], artifactType: String, inclViewSlugsLink: Boolean) = {
@bobbyRulesArtifactTypeSection(rulesByArtifactType: Seq[BobbyRule], artifactType: String, inclViewSlugsLink: Boolean, counts: Map[String, Map[BobbyRule, Int]]) = {
@if(rulesByArtifactType.nonEmpty) {
<div>
<table class="@{artifactType.toLowerCase}-rules table table-striped">
<thead>

<tr>
<th class="col-xs-3">@artifactType</th>
<th class="col-xs-2" colspan="3">Banned Versions</th>
<th colspan="6"></th>
<th colspan="3" style="text-align: center;">Services Affected</th>
</tr>

<tr>
<th class="col-xs-3" colspan="1">@artifactType</th>
<th class="col-xs-2" colspan="3" style="text-align: center">Banned Versions</th>
<th class="col-xs-4">Reason</th>
<th class="col-xs-1">Active from</th>
<th class="col-xs-2"></th>
<th class="">Active from</th>
<th class="">Latest</th>
<th class="">QA</th>
<th class="">Prod</th>
</tr>
</thead>
<tbody>
@rulesByArtifactType.map(bobbyRuleRow(inclViewSlugsLink))
@rulesByArtifactType.map(rule => bobbyRuleRow(inclViewSlugsLink)(rule, counts))
</tbody>
</table>
</div>
}
}

@bobbyRuleRow(inclViewSlugsLink: Boolean)(rule: BobbyRule) = {
@bobbyViolationLink(rule: BobbyRule, env: SlugInfoFlag, count: Int) = @{
if(count == 0 )
<span>0</span>
else
<a href={DependencyExplorerController.search(flag = env, group = rule.group, artefact = rule.artefact, versionRange = rule.range)}>
{count}
</a>
}


@bobbyRuleRow(inclViewSlugsLink: Boolean)(rule: BobbyRule, counts: Map[String, Map[BobbyRule, Int]]) = {
<tr id="rule-@rule.artefact" class="bobby-rule">
<td>@rule.group:@rule.artefact</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>
<td class="bobby-range" data-toggle="tooltip" title="@rule.range.range" style="white-space: nowrap; padding-right: 0; text-align: right">@lbDescr</td>
<td class="bobby-range" data-toggle="tooltip" title="@rule.range.range">x</td>
<td class="bobby-range" 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>
@@ -78,8 +96,16 @@ <h1>Bobby Rules</h1>
}
<td>@rule.reason</td>
<td>@rule.from</td>
<td>@if(inclViewSlugsLink) { <a href="@DependencyExplorerController.search(flag = SlugInfoFlag.Latest, group = rule.group, artefact = rule.artefact, versionRange = rule.range)">Affected slugs</a> }
</td>
@if(inclViewSlugsLink) {
<td>@bobbyViolationLink(rule, SlugInfoFlag.Latest, counts(SlugInfoFlag.Latest.s).getOrElse(rule, 0))</td>
<td>@bobbyViolationLink(rule, SlugInfoFlag.QA, counts(SlugInfoFlag.QA.s).getOrElse(rule, 0))</td>
<td>@bobbyViolationLink(rule, SlugInfoFlag.Production, counts(SlugInfoFlag.Production.s).getOrElse(rule, 0))</td>
}else {
<td></td>
<td></td>
<td></td>
}

</tr>
}

8 changes: 4 additions & 4 deletions public/catalogue-frontend.css
Original file line number Diff line number Diff line change
@@ -11923,12 +11923,12 @@ section span.other-teams-message {
}

.pending {
color: orange;
font-weight: bold;
color: red;
font-weight: normal;
}
.pending a {
color: orange;
font-weight: bold;
color: red;
font-weight: normal;
}

.red {

0 comments on commit ff5fc49

Please sign in to comment.