Skip to content

Commit

Permalink
Merge pull request #984 from hmrc/BDOG-3337
Browse files Browse the repository at this point in the history
BDOG-3337 add bobby reports page
  • Loading branch information
Shnick authored Jan 7, 2025
2 parents 19890ee + ac90baf commit 385c560
Show file tree
Hide file tree
Showing 19 changed files with 500 additions and 79 deletions.
48 changes: 0 additions & 48 deletions app/uk/gov/hmrc/cataloguefrontend/BobbyExplorerController.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2023 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.bobby

import cats.data.EitherT
import play.api.data.{Form, Forms}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents, MessagesRequest, Result, RequestHeader}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
import uk.gov.hmrc.internalauth.client.FrontendAuthComponents
import uk.gov.hmrc.cataloguefrontend.auth.CatalogueAuthBuilders
import uk.gov.hmrc.cataloguefrontend.bobby.view.html.{BobbyExplorerPage, BobbyViolationsPage}
import uk.gov.hmrc.cataloguefrontend.connector.{RepoType, ServiceDependenciesConnector, TeamsAndRepositoriesConnector}
import uk.gov.hmrc.cataloguefrontend.model.{DigitalService, SlugInfoFlag, TeamName}

import javax.inject.Inject
import scala.concurrent.{ExecutionContext, Future}

class BobbyExplorerController @Inject() (
teamsAndReposConnector: TeamsAndRepositoriesConnector
, serviceDeps : ServiceDependenciesConnector
, bobbyService : BobbyService
, bobbyViolationsPage : BobbyViolationsPage
, bobbyExplorerPage : BobbyExplorerPage
, override val mcc : MessagesControllerComponents
, override val auth : FrontendAuthComponents
)(using
override val ec: ExecutionContext
) extends FrontendController(mcc)
with CatalogueAuthBuilders:

def bobbyViolations(team: Option[TeamName], digitalService: Option[DigitalService], flag: Option[String]): Action[AnyContent] =
BasicAuthAction.async: request =>
given MessagesRequest[AnyContent] = request
( for
teams <- EitherT.right[Result](teamsAndReposConnector.allTeams())
digitalServices <- EitherT.right[Result](teamsAndReposConnector.allDigitalServices())
form = BobbyReportFilter.form.bindFromRequest()
filter <- EitherT.fromEither[Future](form.fold(
formErrors => Left(BadRequest(bobbyViolationsPage(form, teams, digitalServices, results = None)))
, formObject => Right(formObject)
))
results <- EitherT.right[Result]:
serviceDeps.bobbyReports(filter.team, filter.digitalService, filter.repoType, filter.flag)
yield
Ok(bobbyViolationsPage(form, teams, digitalServices, results = Some(results)))
).merge

def list(selector: Option[String]): Action[AnyContent] =
BasicAuthAction.async: request =>
given RequestHeader = request
for
rules <- bobbyService.getRules()
counts <- serviceDeps.getBobbyRuleViolations()
yield Ok(bobbyExplorerPage(rules, counts))

case class BobbyReportFilter(
team : Option[TeamName] = None
, digitalService: Option[DigitalService] = None
, repoType : Option[RepoType] = None
, flag : SlugInfoFlag = SlugInfoFlag.Latest
, isActive : Option[Boolean] = None
)

object BobbyReportFilter:
lazy val form: Form[BobbyReportFilter] =
Form(
Forms.mapping(
"team" -> Forms.optional(Forms.of[TeamName])
, "digitalService" -> Forms.optional(Forms.of[DigitalService])
, "repoType" -> Forms.optional(Forms.of[RepoType])
, "flag" -> Forms.optional(Forms.of[SlugInfoFlag]).transform(_.getOrElse(SlugInfoFlag.Latest), Some.apply)
, "isActive" -> Forms.optional(Forms.boolean)
)(BobbyReportFilter.apply)(f => Some(Tuple.fromProductTyped(f)))
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* limitations under the License.
*/

package uk.gov.hmrc.cataloguefrontend
package uk.gov.hmrc.cataloguefrontend.bobby

import cats.data.EitherT
import cats.instances.future._
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents, MessagesRequest, Result}
import uk.gov.hmrc.cataloguefrontend.auth.CatalogueAuthBuilders
import uk.gov.hmrc.cataloguefrontend.bobby.view.html.BobbyRulesTrendPage
import uk.gov.hmrc.cataloguefrontend.connector.ServiceDependenciesConnector
import uk.gov.hmrc.cataloguefrontend.model.{SlugInfoFlag, VersionRange}
import uk.gov.hmrc.cataloguefrontend.serviceconfigs.ServiceConfigsConnector
import uk.gov.hmrc.cataloguefrontend.view.html.BobbyRulesTrendPage
import uk.gov.hmrc.internalauth.client.FrontendAuthComponents
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController

Expand Down Expand Up @@ -134,7 +134,7 @@ class BobbyRulesTrendController @Inject() (

object BobbyRulesTrendController:
def display(group: String, artefact: String, versionRange: VersionRange): String =
uk.gov.hmrc.cataloguefrontend.routes.BobbyRulesTrendController.display(
uk.gov.hmrc.cataloguefrontend.bobby.routes.BobbyRulesTrendController.display(
`rules[]` = Seq(s"$group:$artefact:${versionRange.range}")
).toString

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package uk.gov.hmrc.cataloguefrontend.service
package uk.gov.hmrc.cataloguefrontend.bobby

import uk.gov.hmrc.cataloguefrontend.connector.model.{BobbyRule, BobbyRuleSet}
import uk.gov.hmrc.cataloguefrontend.serviceconfigs.ServiceConfigsConnector
Expand All @@ -33,15 +33,14 @@ class BobbyService @Inject() (
)(using ExecutionContext):

def getRules()(using HeaderCarrier): Future[BobbyRulesView] =
val today = LocalDate.now(clock)

def ordering(dateAscending: Boolean) =
Ordering.by: (br: BobbyRule) =>
( br.from.atStartOfDayInstant.toEpochMilli.pipe(x => if dateAscending then x else -x)
, br.group
, br.artefact
)

val today = LocalDate.now(clock)
serviceConfigsConnector
.bobbyRules()
.map: ruleset =>
Expand All @@ -55,7 +54,6 @@ class BobbyService @Inject() (
BobbyRuleSet(activeLibraries.sorted, activePlugins.sorted)
}
)

end getRules

end BobbyService
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*@

@import uk.gov.hmrc.cataloguefrontend.{BobbyRulesTrendController, routes => appRoutes}
@import uk.gov.hmrc.cataloguefrontend.bobby.{BobbyRulesTrendController, routes => appRoutes}
@import uk.gov.hmrc.cataloguefrontend.connector.RepoType
@import uk.gov.hmrc.cataloguefrontend.connector.model.{BobbyRule, BobbyRuleSet, DependencyScope}
@import uk.gov.hmrc.cataloguefrontend.dependency.DependencyExplorerController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*@

@import uk.gov.hmrc.cataloguefrontend.{BobbyRulesTrendController, routes => appRoutes }
@import uk.gov.hmrc.cataloguefrontend.bobby.{BobbyRulesTrendController, routes => appRoutes }
@import uk.gov.hmrc.cataloguefrontend.connector.model.BobbyRule
@import helper._

Expand Down
Loading

0 comments on commit 385c560

Please sign in to comment.