@@ -28,7 +28,6 @@ import org.scalasteward.core.application.Config
28
28
import org .scalasteward .core .coursier .CoursierAlg
29
29
import org .scalasteward .core .data .ProcessResult .{Created , Ignored , Updated }
30
30
import org .scalasteward .core .data ._
31
- import org .scalasteward .core .edit .EditAlg
32
31
import org .scalasteward .core .git .{Branch , Commit , GitAlg }
33
32
import org .scalasteward .core .repoconfig .PullRequestUpdateStrategy
34
33
import org .scalasteward .core .edit .scalafix .ScalafixMigrationsFinder
@@ -40,7 +39,6 @@ import org.scalasteward.core.{git, util, vcs}
40
39
41
40
final class NurtureAlg [F [_]](config : Config )(implicit
42
41
coursierAlg : CoursierAlg [F ],
43
- editAlg : EditAlg [F ],
44
42
gitAlg : GitAlg [F ],
45
43
logger : Logger [F ],
46
44
pullRequestRepository : PullRequestRepository [F ],
@@ -50,6 +48,7 @@ final class NurtureAlg[F[_]](config: Config)(implicit
50
48
vcsRepoAlg : VCSRepoAlg [F ],
51
49
streamCompiler : Stream .Compiler [F , F ],
52
50
urlChecker : UrlChecker [F ],
51
+ applyAlg : ApplyAlg [F ],
53
52
F : BracketThrow [F ],
54
53
FS : Sync [F ]
55
54
) {
@@ -115,7 +114,7 @@ final class NurtureAlg[F[_]](config: Config)(implicit
115
114
case Some (pr) =>
116
115
logger.info(s " Found PR ${pr.html_url}" ) >> updatePullRequest(data, seenBranches)
117
116
case None =>
118
- applyNewUpdate(data, seenBranches)
117
+ applyAlg. applyNewUpdate(data, seenBranches, pushCommits, createPullRequest )
119
118
}
120
119
_ <- pullRequests.headOption.traverse_ { pr =>
121
120
pullRequestRepository.createOrUpdate(
@@ -159,22 +158,6 @@ final class NurtureAlg[F[_]](config: Config)(implicit
159
158
gitAlg.removeBranch(repo, branch)
160
159
}
161
160
162
- def applyNewUpdate (data : UpdateData , seenBranches : List [Branch ]): F [ProcessResult ] =
163
- gitAlg.returnToCurrentBranch(data.repo) {
164
- val createBranch = logger.info(s " Create branch ${data.updateBranch.name}" ) >>
165
- gitAlg.createBranch(data.repo, data.updateBranch)
166
- editAlg.applyUpdate(data.repoData, data.update, createBranch).flatMap { editCommits =>
167
- if (editCommits.isEmpty) logger.warn(" No commits created" ).as(Ignored )
168
- else
169
- seenBranches
170
- .forallM(gitAlg.diff(data.repo, _).map(_.nonEmpty))
171
- .ifM(
172
- pushCommits(data, editCommits) >> createPullRequest(data),
173
- logger.warn(" Discovered a duplicate branch, not pushing" ).as[ProcessResult ](Ignored )
174
- )
175
- }
176
- }
177
-
178
161
def pushCommits (data : UpdateData , commits : List [Commit ]): F [ProcessResult ] =
179
162
if (commits.isEmpty) F .pure[ProcessResult ](Ignored )
180
163
else
@@ -227,7 +210,8 @@ final class NurtureAlg[F[_]](config: Config)(implicit
227
210
_ <- gitAlg.checkoutBranch(data.repo, data.updateBranch)
228
211
update <- shouldBeUpdated(data)
229
212
result <-
230
- if (update) mergeAndApplyAgain(data, seenBranches) else F .pure[ProcessResult ](Ignored )
213
+ if (update) applyAlg.mergeAndApplyAgain(data, seenBranches, pushCommits)
214
+ else F .pure[ProcessResult ](Ignored )
231
215
} yield result
232
216
}
233
217
else
@@ -253,21 +237,6 @@ final class NurtureAlg[F[_]](config: Config)(implicit
253
237
result.flatMap { case (update, msg) => logger.info(msg).as(update) }
254
238
}
255
239
256
- def mergeAndApplyAgain (data : UpdateData , seenBranches : List [Branch ]): F [ProcessResult ] =
257
- for {
258
- _ <- logger.info(
259
- s " Merge branch ${data.baseBranch.name} into ${data.updateBranch.name} and apply again "
260
- )
261
- maybeMergeCommit <- gitAlg.mergeTheirs(data.repo, data.baseBranch)
262
- editCommits <- editAlg.applyUpdate(data.repoData, data.update)
263
- result <-
264
- seenBranches
265
- .forallM(gitAlg.diff(data.repo, _).map(_.nonEmpty))
266
- .ifM(
267
- pushCommits(data, maybeMergeCommit.toList ++ editCommits),
268
- logger.warn(" Discovered a duplicate branch, not pushing" ).as[ProcessResult ](Ignored )
269
- )
270
- } yield result
271
240
}
272
241
273
242
object NurtureAlg {
0 commit comments