diff --git a/build.sbt b/build.sbt index cd1a2da667..42ac3e5e37 100644 --- a/build.sbt +++ b/build.sbt @@ -23,7 +23,7 @@ val moduleCrossPlatformMatrix: Map[String, List[Platform]] = Map( ) val Scala213 = "2.13.15" -val Scala3 = "3.6.2" +val Scala3 = "3.3.4" /// sbt-typelevel configuration diff --git a/modules/core/src/main/scala/org/scalasteward/core/application/Context.scala b/modules/core/src/main/scala/org/scalasteward/core/application/Context.scala index d2c1180b6a..a58e817854 100644 --- a/modules/core/src/main/scala/org/scalasteward/core/application/Context.scala +++ b/modules/core/src/main/scala/org/scalasteward/core/application/Context.scala @@ -19,7 +19,6 @@ package org.scalasteward.core.application import cats.effect._ import cats.effect.implicits._ import cats.syntax.all._ -import eu.timepit.refined.auto._ import org.http4s.Uri import org.http4s.client.Client import org.http4s.headers.`User-Agent` @@ -94,7 +93,7 @@ object Context { userAgent <- Resource.eval(F.fromEither(`User-Agent`.parse(1)(userAgentString))) middleware = ClientConfiguration .setUserAgent[F](userAgent) - .andThen(ClientConfiguration.retryAfter[F](maxAttempts = 5)) + .andThen(ClientConfiguration.retryAfter[F]()) defaultClient <- ClientConfiguration.build( ClientConfiguration.BuilderMiddleware.default, middleware diff --git a/modules/core/src/main/scala/org/scalasteward/core/client/ClientConfiguration.scala b/modules/core/src/main/scala/org/scalasteward/core/client/ClientConfiguration.scala index 1e6f6ae0a7..1b23f0a722 100644 --- a/modules/core/src/main/scala/org/scalasteward/core/client/ClientConfiguration.scala +++ b/modules/core/src/main/scala/org/scalasteward/core/client/ClientConfiguration.scala @@ -18,7 +18,6 @@ package org.scalasteward.core.client import cats.effect._ import cats.syntax.all._ -import eu.timepit.refined.auto._ import eu.timepit.refined.types.numeric.PosInt import java.net.http.HttpClient import java.net.http.HttpClient.Builder @@ -69,26 +68,27 @@ object ClientConfiguration { * max number times the HTTP request should be sent useful to avoid unexpected cloud provider * costs */ - def retryAfter[F[_]: Temporal](maxAttempts: PosInt = 5): Middleware[F] = { client => - Client[F] { req => - def run(attempt: Int = 1): Resource[F, Response[F]] = client - .run(req.putHeaders("X-Attempt" -> attempt.toString)) - .flatMap { response => - val maybeRetried = for { - header <- response.headers.get(ci"Retry-After") - seconds <- header.head.value.toIntOption - if seconds > 0 - duration = seconds.seconds - if RetryAfterStatuses.contains(response.status.code) - if attempt < maxAttempts.value - } yield Resource - .eval(response.as[Unit].voidError *> Temporal[F].sleep(duration)) - .flatMap(_ => run(attempt + 1)) - maybeRetried.getOrElse(Resource.pure(response)) - } + def retryAfter[F[_]: Temporal](maxAttempts: PosInt = PosInt.unsafeFrom(5)): Middleware[F] = { + client => + Client[F] { req => + def run(attempt: Int = 1): Resource[F, Response[F]] = client + .run(req.putHeaders("X-Attempt" -> attempt.toString)) + .flatMap { response => + val maybeRetried = for { + header <- response.headers.get(ci"Retry-After") + seconds <- header.head.value.toIntOption + if seconds > 0 + duration = seconds.seconds + if RetryAfterStatuses.contains(response.status.code) + if attempt < maxAttempts.value + } yield Resource + .eval(response.as[Unit].voidError *> Temporal[F].sleep(duration)) + .flatMap(_ => run(attempt + 1)) + maybeRetried.getOrElse(Resource.pure(response)) + } - run() - } + run() + } } def disableFollowRedirect: BuilderMiddleware = _.followRedirects(HttpClient.Redirect.NEVER)