Skip to content

Commit

Permalink
use smart constructors instead of case classes for the new mergify ac…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
bpholt committed Jul 1, 2022
1 parent d478996 commit bc28493
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.typelevel.sbt.mergify

import cats.data._
import cats.syntax.all._
import io.circe._
import io.circe.syntax._

Expand Down Expand Up @@ -59,19 +61,37 @@ object MergifyAction {
}
}

final case class RequestReviews(users: List[String] = Nil) extends MergifyAction {
final class RequestReviews(
val users: Either[Seq[String], Map[String, Int]],
val randomCount: Option[Int])
extends MergifyAction {
override private[mergify] def name = "request_reviews"
}

object RequestReviews {
def apply(user: String, users: String*) =
new RequestReviews((user :: users.toList).asLeft, None)

def apply(weightedUser: (String, Int), weightedUsers: (String, Int)*) =
new RequestReviews((weightedUser :: weightedUsers.toList).toMap.asRight, None)

def apply(users: NonEmptyList[String], randomCount: Int) =
new RequestReviews(users.toList.asLeft, Option(randomCount))

def apply(weightedUsers: NonEmptyMap[String, Int], randomCount: Int) =
new RequestReviews(weightedUsers.toSortedMap.asRight, Option(randomCount))

implicit def encoder: Encoder[RequestReviews] =
Encoder.forProduct1("users")(_.users)
Encoder.forProduct2("users", "random_count") { requestReviews =>
(requestReviews.users.fold(_.asJson, _.asJson), requestReviews.randomCount)
}
}

final case object Update extends MergifyAction {
object Update extends MergifyAction {
override private[mergify] def name = "update"

implicit def encoder: Encoder[Update.type] = Encoder[JsonObject].contramap(_ => JsonObject.empty)
implicit def encoder: Encoder[Update.type] =
Encoder[JsonObject].contramap(_ => JsonObject.empty)
}

private[this] object Dummy extends MergifyAction
Expand Down

0 comments on commit bc28493

Please sign in to comment.