Skip to content

Commit 6595ca7

Browse files
author
Devon Stewart
committed
Revert "Exploratory commit to rough out what could constitute a useful test"
This reverts commit ced9ed1.
1 parent 773ee53 commit 6595ca7

File tree

3 files changed

+19
-55
lines changed

3 files changed

+19
-55
lines changed

modules/core/src/main/scala/org/scalasteward/core/nurture/NurtureAlg.scala

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,29 @@ final class NurtureAlg[F[_]](config: Config)(implicit
155155
gitAlg.removeBranch(repo, branch)
156156
}
157157

158+
def ensureDistinctBranch(
159+
data: UpdateData,
160+
seenBranches: Ref[F, List[Branch]],
161+
whenDistinct: F[ProcessResult]
162+
): F[ProcessResult] =
163+
seenBranches.get
164+
.flatMap(_.forallM(gitAlg.diff(data.repo, _).map(_.nonEmpty)))
165+
.ifM(
166+
whenDistinct,
167+
logger.warn("Discovered a duplicate branch, not pushing").as(Ignored)
168+
)
169+
158170
def applyNewUpdate(data: UpdateData, seenBranches: Ref[F, List[Branch]]): F[ProcessResult] =
159171
gitAlg.returnToCurrentBranch(data.repo) {
160172
val createBranch = logger.info(s"Create branch ${data.updateBranch.name}") >>
161173
gitAlg.createBranch(data.repo, data.updateBranch)
162174
editAlg.applyUpdate(data.repoData, data.update, createBranch).flatMap { editCommits =>
163175
if (editCommits.isEmpty) logger.warn("No commits created").as(Ignored)
164176
else
165-
NurtureAlg.ensureDistinctBranch(
177+
ensureDistinctBranch(
178+
data,
166179
seenBranches,
167-
gitAlg.diff(data.repo, _).map(_.nonEmpty),
168-
pushCommits(data, editCommits) >> createPullRequest(data),
169-
logger.warn("Discovered a duplicate branch, not pushing").as[ProcessResult](Ignored)
180+
pushCommits(data, editCommits) >> createPullRequest(data)
170181
)
171182
}
172183
}
@@ -256,11 +267,10 @@ final class NurtureAlg[F[_]](config: Config)(implicit
256267
)
257268
maybeMergeCommit <- gitAlg.mergeTheirs(data.repo, data.baseBranch)
258269
editCommits <- editAlg.applyUpdate(data.repoData, data.update)
259-
result <- NurtureAlg.ensureDistinctBranch(
270+
result <- ensureDistinctBranch(
271+
data,
260272
seenBranches,
261-
gitAlg.diff(data.repo, _).map(_.nonEmpty),
262-
pushCommits(data, maybeMergeCommit.toList ++ editCommits),
263-
logger.warn("Discovered a duplicate branch, not pushing").as[ProcessResult](Ignored)
273+
pushCommits(data, maybeMergeCommit.toList ++ editCommits)
264274
)
265275
} yield result
266276
}
@@ -285,14 +295,4 @@ object NurtureAlg {
285295
.compile
286296
.drain
287297
}
288-
289-
def ensureDistinctBranch[F[_]: Sync: cats.FlatMap](
290-
seenBranches: Ref[F, List[Branch]],
291-
isDistinct: Branch => F[Boolean],
292-
whenDistinct: F[ProcessResult],
293-
whenDuplicate: F[ProcessResult]
294-
): F[ProcessResult] =
295-
seenBranches.get
296-
.flatMap(_.forallM(isDistinct))
297-
.ifM(whenDistinct, whenDuplicate)
298298
}

modules/core/src/test/scala/org/scalasteward/core/TestInstances.scala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import org.scalacheck.{Arbitrary, Cogen, Gen}
99
import org.scalasteward.core.TestSyntax._
1010
import org.scalasteward.core.data.Update.Single
1111
import org.scalasteward.core.data._
12-
import org.scalasteward.core.git.{Branch, Sha1}
12+
import org.scalasteward.core.git.Sha1
1313
import org.scalasteward.core.git.Sha1.HexString
1414
import org.scalasteward.core.repocache.RepoCache
1515
import org.scalasteward.core.repoconfig.PullRequestFrequency.{Asap, Timespan}
@@ -59,13 +59,6 @@ object TestInstances {
5959
} yield Single(groupId % artifactId % currentVersion, Nel.one(newerVersion))
6060
)
6161

62-
implicit val branchArbitrary: Arbitrary[Branch] =
63-
Arbitrary(
64-
for {
65-
name <- Gen.alphaStr
66-
} yield Branch(name)
67-
)
68-
6962
private val hashGen: Gen[String] =
7063
for {
7164
sep <- Gen.oneOf('-', '+')
Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package org.scalasteward.core.nurture
22

3-
import cats.Applicative
43
import cats.data.StateT
54
import cats.effect.IO
6-
import cats.effect.concurrent.Ref
7-
import cats.syntax.all._
85
import eu.timepit.refined.types.numeric.NonNegInt
96
import munit.ScalaCheckSuite
107
import org.scalacheck.Prop._
118
import org.scalasteward.core.TestInstances._
129
import org.scalasteward.core.data.ProcessResult.{Ignored, Updated}
1310
import org.scalasteward.core.data.{ProcessResult, Update}
14-
import org.scalasteward.core.git.Branch
1511

1612
class NurtureAlgTest extends ScalaCheckSuite {
1713
test("processUpdates with No Limiting") {
@@ -46,29 +42,4 @@ class NurtureAlgTest extends ScalaCheckSuite {
4642
assertEquals(obtained, updates.size)
4743
}
4844
}
49-
50-
test(
51-
"Ensure distinct should not push branches that are not different to other visited branches"
52-
) {
53-
forAll { branches: Set[Branch] =>
54-
val (duplicateBranches, distinctBranches) = branches.toList.splitAt(branches.size / 2)
55-
type F[A] = StateT[IO, Int, A]
56-
val F = Applicative[F]
57-
val f: StateT[IO, Int, ProcessResult] =
58-
StateT[IO, Int, ProcessResult](actionAcc => IO.pure(actionAcc + 1 -> Updated))
59-
val obtained = (for {
60-
seenBranches <- Ref[F].of(duplicateBranches)
61-
res <- (duplicateBranches ++ distinctBranches).traverse { branch =>
62-
NurtureAlg
63-
.ensureDistinctBranch(
64-
seenBranches,
65-
_ => F.pure(distinctBranches.contains(branch)),
66-
f,
67-
F.pure[ProcessResult](Ignored)
68-
)
69-
}
70-
} yield res).runS(0).unsafeRunSync()
71-
assertEquals(obtained, distinctBranches.length)
72-
}
73-
}
7445
}

0 commit comments

Comments
 (0)