17
17
package org .scalasteward .core .nurture
18
18
19
19
import cats .effect .Concurrent
20
- import cats .implicits ._
20
+ import cats .syntax . all ._
21
21
import cats .{Applicative , Id }
22
22
import org .scalasteward .core .application .Config .ForgeCfg
23
23
import org .scalasteward .core .coursier .CoursierAlg
@@ -99,7 +99,7 @@ final class NurtureAlg[F[_]](config: ForgeCfg)(implicit
99
99
logger.info(s " PR ${pr.html_url} is closed " ) >>
100
100
deleteRemoteBranch(data.repo, data.updateBranch).as(Ignored )
101
101
case Some (pr) if ! pr.state.isClosed =>
102
- logger.info(s " Found PR ${pr.html_url}" ) >> updatePullRequest(data)
102
+ logger.info(s " Found PR ${pr.html_url}" ) >> updatePullRequest(data, pr.number )
103
103
case _ =>
104
104
applyNewUpdate(data).flatTap {
105
105
case Created (newPrNumber) => closeObsoletePullRequests(data, newPrNumber)
@@ -262,14 +262,14 @@ final class NurtureAlg[F[_]](config: ForgeCfg)(implicit
262
262
_ <- logger.info(s " Created PR ${pr.html_url}" )
263
263
} yield Created (pr.number)
264
264
265
- private def updatePullRequest (data : UpdateData ): F [ProcessResult ] =
265
+ private def updatePullRequest (data : UpdateData , number : PullRequestNumber ): F [ProcessResult ] =
266
266
if (data.repoConfig.updatePullRequestsOrDefault =!= PullRequestUpdateStrategy .Never )
267
267
gitAlg.returnToCurrentBranch(data.repo) {
268
- for {
269
- _ <- gitAlg.checkoutBranch (data.repo, data.updateBranch)
270
- update <- shouldBeUpdated( data)
271
- result <- if (update) mergeAndApplyAgain(data) else F .pure[ ProcessResult ]( Ignored )
272
- } yield result
268
+ gitAlg.checkoutBranch(data.repo, data.updateBranch) >>
269
+ shouldBeUpdated (data).ifM(
270
+ ifTrue = mergeAndApplyAgain(number, data),
271
+ ifFalse = ( Ignored : ProcessResult ).pure
272
+ )
273
273
}
274
274
else
275
275
logger.info(" PR updates are disabled by flag" ).as(Ignored )
@@ -293,7 +293,7 @@ final class NurtureAlg[F[_]](config: ForgeCfg)(implicit
293
293
result.flatMap { case (update, msg) => logger.info(msg).as(update) }
294
294
}
295
295
296
- private def mergeAndApplyAgain (data : UpdateData ): F [ProcessResult ] =
296
+ private def mergeAndApplyAgain (number : PullRequestNumber , data : UpdateData ): F [ProcessResult ] =
297
297
for {
298
298
_ <- logger.info(
299
299
s " Merge branch ${data.baseBranch.name} into ${data.updateBranch.name} and apply again "
@@ -307,6 +307,8 @@ final class NurtureAlg[F[_]](config: ForgeCfg)(implicit
307
307
editCommits = edits.flatMap(_.commits)
308
308
commits = maybeRevertCommit.toList ++ maybeMergeCommit.toList ++ editCommits
309
309
result <- pushCommits(data, commits)
310
+ requestData <- preparePullRequest(data, edits)
311
+ _ <- forgeApiAlg.updatePullRequest(number : PullRequestNumber , data.repo, requestData)
310
312
} yield result
311
313
312
314
}
0 commit comments