From 1ae0a5d88310abeeaa2e1781f51323178f83b8ad Mon Sep 17 00:00:00 2001 From: Brian Holt Date: Fri, 1 Jul 2022 11:41:25 -0500 Subject: [PATCH] dogfood the request_reviews Mergify action --- .mergify.yml | 11 ++++++++ build.sbt | 6 +++++ .../typelevel/sbt/mergify/MergifyAction.scala | 27 ++++++++++++++++--- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/.mergify.yml b/.mergify.yml index 8cb30377..9cb910ae 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -168,3 +168,14 @@ pull_request_rules: add: - versioning remove: [] +- name: assign scala-steward's PRs for review + conditions: + - author=scala-steward + actions: + request_reviews: + users: + - armanbilge + - rossabaker + - ChristopherDavenport + - djspiewak + random_count: 2 diff --git a/build.sbt b/build.sbt index 26451d64..d1a77420 100644 --- a/build.sbt +++ b/build.sbt @@ -14,6 +14,12 @@ ThisBuild / developers := List( ThisBuild / mergifyStewardConfig ~= { _.map(_.copy(mergeMinors = true)) } ThisBuild / mergifySuccessConditions += MergifyCondition.Custom("#approved-reviews-by>=1") ThisBuild / mergifyLabelPaths += { "docs" -> file("docs") } +ThisBuild / mergifyPrRules += MergifyPrRule("assign scala-steward's PRs for review", + List(MergifyCondition.Custom("author=scala-steward")), + List( + MergifyAction.RequestReviews((ThisBuild / developers).value, randomCount = 2) + ) +) ThisBuild / scalafixDependencies ++= Seq( "com.github.liancheng" %% "organize-imports" % "0.6.0" diff --git a/mergify/src/main/scala/org/typelevel/sbt/mergify/MergifyAction.scala b/mergify/src/main/scala/org/typelevel/sbt/mergify/MergifyAction.scala index ea37f24c..61d1eb08 100644 --- a/mergify/src/main/scala/org/typelevel/sbt/mergify/MergifyAction.scala +++ b/mergify/src/main/scala/org/typelevel/sbt/mergify/MergifyAction.scala @@ -16,10 +16,11 @@ package org.typelevel.sbt.mergify -import cats.data._ -import cats.syntax.all._ -import io.circe._ -import io.circe.syntax._ +import cats.data.* +import cats.syntax.all.* +import io.circe.* +import io.circe.syntax.* +import sbt.librarymanagement.Developer sealed abstract class MergifyAction { private[mergify] def name = getClass.getSimpleName.toLowerCase @@ -84,6 +85,24 @@ object MergifyAction { Option(randomCount) ) + def apply(developers: List[Developer]) = + new RequestReviews( + developers + .map(_.id) + .toNel + .getOrElse(throw new RuntimeException("developers must be non-empty")) + .asLeft, + None) + + def apply(developers: List[Developer], randomCount: Int) = + new RequestReviews( + developers + .map(_.id) + .toNel + .getOrElse(throw new RuntimeException("developers must be non-empty")) + .asLeft, + randomCount.some) + implicit def encoder: Encoder[RequestReviews] = Encoder.forProduct2("users", "random_count") { requestReviews => (requestReviews.users.fold(_.asJson, _.asJson), requestReviews.randomCount)