Skip to content

Commit 5fc5c36

Browse files
committed
reduce threshold, use dedicated exception, rename lastCommitMaxAge
1 parent 216f9d4 commit 5fc5c36

File tree

4 files changed

+36
-19
lines changed

4 files changed

+36
-19
lines changed

modules/core/src/main/resources/default.scala-steward.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Changes to this file are therefore immediately visible to all
55
// Scala Steward instances.
66

7-
lastCommitMaxAge = "540 days"
7+
inactivityThreshold = "270 days"
88

99
postUpdateHooks = [
1010
{

modules/core/src/main/scala/org/scalasteward/core/repocache/RepoCacheAlg.scala

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ import org.scalasteward.core.data.{Dependency, DependencyInfo, Repo, RepoData}
2424
import org.scalasteward.core.forge.data.RepoOut
2525
import org.scalasteward.core.forge.{ForgeApiAlg, ForgeRepoAlg}
2626
import org.scalasteward.core.git.GitAlg
27+
import org.scalasteward.core.repocache.RepoCacheAlg.RepositoryInactive
2728
import org.scalasteward.core.repoconfig.RepoConfigAlg
28-
import org.scalasteward.core.util.{dateTime, DateTimeAlg}
29+
import org.scalasteward.core.util.DateTimeAlg
30+
import org.scalasteward.core.util.dateTime.showDuration
2931
import org.typelevel.log4cats.Logger
32+
import scala.concurrent.duration.FiniteDuration
3033
import scala.util.control.NoStackTrace
3134

3235
final class RepoCacheAlg[F[_]](config: Config)(implicit
@@ -89,14 +92,23 @@ final class RepoCacheAlg[F[_]](config: Config)(implicit
8992
gitAlg.findFilesContaining(repo, dependency.version.value).map(DependencyInfo(dependency, _))
9093

9194
private[repocache] def throwIfInactive(data: RepoData): F[Unit] =
92-
data.config.lastCommitMaxAge.traverse_ { maxAge =>
95+
data.config.inactivityThreshold.traverse_ { threshold =>
9396
dateTimeAlg.currentTimestamp.flatMap { now =>
94-
val sinceLastCommit = data.cache.commitDate.until(now)
95-
val isInactive = sinceLastCommit > maxAge
96-
F.raiseWhen(isInactive) {
97-
val msg = s"Skipping because last commit is older than ${dateTime.showDuration(maxAge)}"
98-
new Throwable(msg) with NoStackTrace
99-
}
97+
val inactiveSince = data.cache.commitDate.until(now)
98+
val isInactive = inactiveSince > threshold
99+
F.raiseWhen(isInactive)(RepositoryInactive(data.repo, inactiveSince, threshold))
100100
}
101101
}
102102
}
103+
104+
object RepoCacheAlg {
105+
final case class RepositoryInactive(
106+
repo: Repo,
107+
inactiveSince: FiniteDuration,
108+
threshold: FiniteDuration
109+
) extends RuntimeException
110+
with NoStackTrace {
111+
override val getMessage: String =
112+
s"${repo.show}, inactiveSince = ${showDuration(inactiveSince)}, threshold = ${showDuration(threshold)}"
113+
}
114+
}

modules/core/src/main/scala/org/scalasteward/core/repoconfig/RepoConfig.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ final case class RepoConfig(
4141
private val reviewers: Option[List[String]] = None,
4242
private val dependencyOverrides: Option[List[GroupRepoConfig]] = None,
4343
signoffCommits: Option[Boolean] = None,
44-
lastCommitMaxAge: Option[FiniteDuration] = None
44+
inactivityThreshold: Option[FiniteDuration] = None
4545
) {
4646
def commitsOrDefault: CommitsConfig =
4747
commits.getOrElse(CommitsConfig())
@@ -112,7 +112,8 @@ object RepoConfig {
112112
reviewers = x.reviewers |+| y.reviewers,
113113
dependencyOverrides = x.dependencyOverrides |+| y.dependencyOverrides,
114114
signoffCommits = x.signoffCommits.orElse(y.signoffCommits),
115-
lastCommitMaxAge = combineOptions(x.lastCommitMaxAge, y.lastCommitMaxAge)(_ max _)
115+
inactivityThreshold =
116+
combineOptions(x.inactivityThreshold, y.inactivityThreshold)(_ max _)
116117
)
117118
}
118119
)

modules/core/src/test/scala/org/scalasteward/core/repocache/RepoCacheAlgTest.scala

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import org.scalasteward.core.forge.github.Repository
1515
import org.scalasteward.core.git.Branch
1616
import org.scalasteward.core.mock.MockContext.context.{repoCacheAlg, repoConfigAlg, workspaceAlg}
1717
import org.scalasteward.core.mock.{GitHubAuth, MockEff, MockEffOps, MockState}
18+
import org.scalasteward.core.repocache.RepoCacheAlg.RepositoryInactive
1819
import org.scalasteward.core.repoconfig.RepoConfig
1920
import org.scalasteward.core.util.{intellijThisImportIsUsed, Timestamp}
2021
import scala.concurrent.duration.*
@@ -60,7 +61,7 @@ class RepoCacheAlgTest extends CatsEffectSuite with Http4sDsl[MockEff] {
6061
assertIO(obtained, expected)
6162
}
6263

63-
test("throwIfInactive: no maxAge") {
64+
test("throwIfInactive: no threshold") {
6465
val repo = Repo("repo-cache-alg", "test-1")
6566
val cache = RepoCache(dummySha1, Timestamp(0L), Nil, None, None)
6667
val config = RepoConfig.empty
@@ -69,23 +70,26 @@ class RepoCacheAlgTest extends CatsEffectSuite with Http4sDsl[MockEff] {
6970
assertIO(obtained, Right(()))
7071
}
7172

72-
test("throwIfInactive: lastCommit < maxAge") {
73+
test("throwIfInactive: inactiveSince < threshold") {
7374
val repo = Repo("repo-cache-alg", "test-2")
7475
val commitDate = Timestamp.fromLocalDateTime(LocalDateTime.now())
7576
val cache = RepoCache(dummySha1, commitDate, Nil, None, None)
76-
val config = RepoConfig(lastCommitMaxAge = Some(1.day))
77+
val config = RepoConfig(inactivityThreshold = Some(1.day))
7778
val data = RepoData(repo, cache, config)
7879
val obtained = repoCacheAlg.throwIfInactive(data).runA(MockState.empty).attempt
7980
assertIO(obtained, Right(()))
8081
}
8182

82-
test("throwIfInactive: lastCommit > maxAge") {
83+
test("throwIfInactive: inactiveSince > threshold") {
8384
val repo = Repo("repo-cache-alg", "test-3")
8485
val cache = RepoCache(dummySha1, Timestamp(0L), Nil, None, None)
85-
val config = RepoConfig(lastCommitMaxAge = Some(1.day))
86+
val config = RepoConfig(inactivityThreshold = Some(1.day))
8687
val data = RepoData(repo, cache, config)
87-
val obtained =
88-
repoCacheAlg.throwIfInactive(data).runA(MockState.empty).attempt.map(_.leftMap(_.getMessage))
89-
assertIO(obtained, Left("Skipping because last commit is older than 1d"))
88+
val obtained = repoCacheAlg
89+
.throwIfInactive(data)
90+
.runA(MockState.empty)
91+
.attemptNarrow[RepositoryInactive]
92+
.map(_.leftMap(_.copy(inactiveSince = Duration.Zero)))
93+
assertIO(obtained, Left(RepositoryInactive(repo, Duration.Zero, 1.day)))
9094
}
9195
}

0 commit comments

Comments
 (0)