Skip to content

Commit

Permalink
Merge pull request #3012 from endertunc/check-merge-reguest-status-wi…
Browse files Browse the repository at this point in the history
…th-backoff

Check merge request status with backoff
  • Loading branch information
fthomas committed Mar 29, 2023
2 parents 75b49de + 9a99f9d commit e8a1a8c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Expand Up @@ -16,8 +16,9 @@

package org.scalasteward.core.forge

import cats.effect.Temporal
import cats.syntax.all._
import cats.{Applicative, MonadThrow, Parallel}
import cats.{Applicative, Parallel}
import org.http4s.headers.Authorization
import org.http4s.{BasicCredentials, Header, Request}
import org.scalasteward.core.application.Config
Expand All @@ -42,7 +43,7 @@ object ForgeSelection {
)(implicit
httpJsonClient: HttpJsonClient[F],
logger: Logger[F],
F: MonadThrow[F]
F: Temporal[F]
): ForgeApiAlg[F] = {
val auth = (_: Any) => authenticate(forgeCfg.tpe, user)
forgeSpecificCfg match {
Expand Down
Expand Up @@ -16,7 +16,8 @@

package org.scalasteward.core.forge.gitlab

import cats.{MonadThrow, Parallel}
import cats.effect.Temporal
import cats.Parallel
import cats.syntax.all._
import io.circe._
import io.circe.generic.semiauto._
Expand All @@ -31,6 +32,8 @@ import org.scalasteward.core.util.uri.uriDecoder
import org.scalasteward.core.util.{intellijThisImportIsUsed, HttpJsonClient, UnexpectedResponse}
import org.typelevel.log4cats.Logger

import scala.concurrent.duration.{Duration, DurationInt}

final private[gitlab] case class ForkPayload(id: String, namespace: String)
final private[gitlab] case class MergeRequestPayload(
id: String,
Expand Down Expand Up @@ -162,7 +165,7 @@ final class GitLabApiAlg[F[_]: Parallel](
)(implicit
client: HttpJsonClient[F],
logger: Logger[F],
F: MonadThrow[F]
F: Temporal[F]
) extends ForgeApiAlg[F] {
import GitLabJsonCodec._

Expand Down Expand Up @@ -205,14 +208,29 @@ final class GitLabApiAlg[F[_]: Parallel](

def waitForMergeRequestStatus(
number: PullRequestNumber,
retries: Int = 10
retries: Int = 10,
initialDelay: Duration = 100.milliseconds,
backoffMultiplier: Double = 2.0
): F[MergeRequestOut] =
client
.get[MergeRequestOut](url.existingMergeRequest(repo, number), modify(repo))
.flatMap {
case mr if mr.mergeStatus =!= GitLabMergeStatus.Checking => F.pure(mr)
case _ if retries > 0 => waitForMergeRequestStatus(number, retries - 1)
case other => F.pure(other)
case mr if retries > 0 =>
logger.info(
s"Merge request is still in '${mr.mergeStatus}' state. We will check merge request status in $initialDelay again. " +
s"Remaining retries count is $retries"
) >> F.sleep(initialDelay) >> waitForMergeRequestStatus(
number,
retries - 1,
initialDelay * backoffMultiplier
)
case mr =>
logger
.warn(
s"Exhausted all retries while waiting for merge request status. Last known status is '${mr.mergeStatus}'"
)
.as(mr)
}

val updatedMergeRequest =
Expand Down

0 comments on commit e8a1a8c

Please sign in to comment.