Repository: scala-steward-org/scala-steward
Pull request #1834 (2020-12-23 15:29:50)

Change findPullRequest to findLatestPullRequests
Closes https://github.com/scala-steward-org/scala-steward/issues/1831.


Patch:
diff --git a/modules/core/src/main/scala/org/scalasteward/core/nurture/PullRequestRepository.scala b/modules/core/src/main/scala/org/scalasteward/core/nurture/PullRequestRepository.scala
index 4042f428..80c9ca7c 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/nurture/PullRequestRepository.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/nurture/PullRequestRepository.scala
@@ -24,8 +24,8 @@ import org.scalasteward.core.git.Sha1
 import org.scalasteward.core.persistence.KeyValueStore
 import org.scalasteward.core.update.UpdateAlg
 import org.scalasteward.core.util.{DateTimeAlg, Timestamp}
-import org.scalasteward.core.vcs.data.{PullRequestNumber, PullRequestState, Repo}
 import org.scalasteward.core.vcs
+import org.scalasteward.core.vcs.data.{PullRequestNumber, PullRequestState, Repo}
 
 final class PullRequestRepository[F[_]](
     kvStore: KeyValueStore[F, Repo, Map[Uri, PullRequestData]]
@@ -82,18 +82,18 @@ final class PullRequestRepository[F[_]](
       }.flatten.toList
     }
 
-  def findPullRequest(
+  def findLatestPullRequest(
       repo: Repo,
       crossDependency: CrossDependency,
       newVersion: String
   ): F[Option[(Uri, Sha1, PullRequestState)]] =
     kvStore.getOrElse(repo, Map.empty).map {
-      _.collectFirst {
-        case (url, data)
-            if UpdateAlg.isUpdateFor(data.update, crossDependency) &&
-              data.update.nextVersion === newVersion =>
-          (url, data.baseSha1, data.state)
+      _.filter { case (_, data) =>
+        UpdateAlg.isUpdateFor(data.update, crossDependency) &&
+          data.update.nextVersion === newVersion
       }
+        .maxByOption { case (_, data) => data.entryCreatedAt.millis }
+        .map { case (url, data) => (url, data.baseSha1, data.state) }
     }
 
   def lastPullRequestCreatedAt(repo: Repo): F[Option[Timestamp]] =
diff --git a/modules/core/src/main/scala/org/scalasteward/core/update/PruningAlg.scala b/modules/core/src/main/scala/org/scalasteward/core/update/PruningAlg.scala
index ae17e25b..5a504957 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/update/PruningAlg.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/update/PruningAlg.scala
@@ -115,7 +115,7 @@ final class PruningAlg[F[_]](implicit
     updates.find(UpdateAlg.isUpdateFor(_, crossDependency)) match {
       case None => F.pure(DependencyUpToDate(crossDependency))
       case Some(update) =>
-        pullRequestRepository.findPullRequest(repo, crossDependency, update.nextVersion).map {
+        pullRequestRepository.findLatestPullRequest(repo, crossDependency, update.nextVersion).map {
           case None =>
             DependencyOutdated(crossDependency, update)
           case Some((uri, _, Closed)) =>


Test patch:
diff --git a/modules/core/src/test/scala/org/scalasteward/core/nurture/PullRequestRepositoryTest.scala b/modules/core/src/test/scala/org/scalasteward/core/nurture/PullRequestRepositoryTest.scala
index a0cca0c4..348dba92 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/nurture/PullRequestRepositoryTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/nurture/PullRequestRepositoryTest.scala
@@ -29,7 +29,7 @@ class PullRequestRepositoryTest extends FunSuite {
           PullRequestState.Open,
           number
         )
-        result <- pullRequestRepository.findPullRequest(repo, update.crossDependency, "1.0.0")
+        result <- pullRequestRepository.findLatestPullRequest(repo, update.crossDependency, "1.0.0")
         createdAt <- pullRequestRepository.lastPullRequestCreatedAt(repo)
       } yield (result, createdAt)
       val (state, (result, createdAt)) = p.run(MockState.empty).unsafeRunSync()