Skip to content

Commit

Permalink
Merge branch 'main' into topic/scala3
Browse files Browse the repository at this point in the history
  • Loading branch information
fthomas committed Jan 5, 2025
2 parents 39fe442 + 0844668 commit f83fb13
Show file tree
Hide file tree
Showing 46 changed files with 318 additions and 261 deletions.
1 change: 0 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ lazy val core = myCrossProject("core")
Dependencies.catsParse,
Dependencies.circeConfig,
Dependencies.circeGeneric,
Dependencies.circeGenericExtras,
Dependencies.circeParser,
Dependencies.circeRefined,
Dependencies.commonsIo,
Expand Down
2 changes: 1 addition & 1 deletion docs/repo-specific-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ updates.allowPreReleases = [ { groupId = "com.example", artifactId="foo" } ]
updates.limit = 5

# The extensions of files that should be updated.
# Default: [".mill-version",".sbt",".sbt.shared",".sc",".scala",".scalafmt.conf",".sdkmanrc",".yml","build.properties","mill-version","pom.xml"]
# Default: [".mill",".mill-version",".sbt",".sbt.shared",".sc",".scala",".scalafmt.conf",".sdkmanrc",".yml","build.properties","mill-version","pom.xml"]
updates.fileExtensions = [".scala", ".sbt", ".sbt.shared", ".sc", ".yml", ".md", ".markdown", ".txt"]

# If "on-conflicts", Scala Steward will update the PR it created to resolve conflicts as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class UpdatesConfigBenchmark {
val update = Update.ForArtifactId(dependency, newerVersions)

UpdatesConfig().keep(update)
UpdatesConfig(allow = List(UpdatePattern(groupId, None, None))).keep(update)
UpdatesConfig(allow = Some(List(UpdatePattern(groupId, None, None)))).keep(update)
UpdatesConfig(allow =
List(UpdatePattern(groupId, None, Some(VersionPattern(prefix = Some("6.0")))))
Some(List(UpdatePattern(groupId, None, Some(VersionPattern(prefix = Some("6.0"))))))
).keep(update)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ object Cli {
private val defaultMavenRepo: Opts[Resolver] = {
val default = Resolver.mavenCentral
option[String]("default-maven-repo", s"default: ${default.location}")
.map(location => Resolver.MavenRepository("default", location, None, Nil))
.map(location => Resolver.MavenRepository("default", location, None, None))
.withDefault(default)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ object parser {
id <- stringNoSpace
_ <- wsp.rep0 ~ Parser.string("url:") ~ wsp
url <- stringNoSpace
} yield Resolver.MavenRepository(id, url, None, Nil)
} yield Resolver.MavenRepository(id, url, None, None)

def parseResolvers(input: List[String]): List[Resolver] =
input.mkString.split("""\[INFO]""").toList.flatMap { line =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ object parser {
*
* @param artifactName
* name of the artifact parsed from the build file
* @param millVerion
* @param millVersion
* the current Mill version being used
* @return
* the newly put together ArtifactId
Expand Down Expand Up @@ -127,13 +127,13 @@ object MillModule {
url <- c.downField("url").as[String]
creds <- c.downField("auth").as[Option[Resolver.Credentials]]
headers <- c.downField("headers").as[Option[List[Resolver.Header]]]
} yield Resolver.MavenRepository(url, url, creds, headers.getOrElse(Nil))
} yield Resolver.MavenRepository(url, url, creds, headers)
case "ivy" =>
for {
url <- c.downField("pattern").as[String]
creds <- c.downField("auth").as[Option[Resolver.Credentials]]
headers <- c.downField("headers").as[Option[List[Resolver.Header]]]
} yield Resolver.IvyRepository(url, url, creds, headers.getOrElse(Nil))
} yield Resolver.IvyRepository(url, url, creds, headers)
case typ => Left(DecodingFailure(s"Not a matching resolver type, $typ", c.history))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ package org.scalasteward.core.buildtool.sbt.data

import cats.Order
import cats.syntax.all._
import io.circe.Codec
import io.circe.generic.extras.semiauto._
import io.circe.{Decoder, Encoder}

final case class SbtVersion(value: String)

object SbtVersion {
implicit val sbtVersionCodec: Codec[SbtVersion] =
deriveUnwrappedCodec
implicit val sbtVersionDecoder: Decoder[SbtVersion] =
Decoder[String].map(SbtVersion.apply)

implicit val sbtVersionEncoder: Encoder[SbtVersion] =
Encoder[String].contramap(_.value)

implicit val sbtVersionOrder: Order[SbtVersion] =
Order[String].contramap(_.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ package org.scalasteward.core.buildtool.sbt.data

import cats.Order
import cats.syntax.all._
import io.circe.Codec
import io.circe.generic.extras.semiauto._
import io.circe.{Decoder, Encoder}

final case class ScalaVersion(value: String)

object ScalaVersion {
implicit val scalaVersionCodec: Codec[ScalaVersion] =
deriveUnwrappedCodec
implicit val scalaVersionDecoder: Decoder[ScalaVersion] =
Decoder[String].map(ScalaVersion.apply)

implicit val scalaVersionEncoder: Encoder[ScalaVersion] =
Encoder[String].contramap(_.value)

implicit val scalaVersionOrder: Order[ScalaVersion] =
Order[String].contramap(_.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ object CoursierAlg {
private def toCoursierRepository(resolver: Resolver): Either[String, coursier.Repository] =
resolver match {
case Resolver.MavenRepository(_, location, creds, headers) =>
val authentication = toCoursierAuthentication(creds, headers)
val authentication = toCoursierAuthentication(creds, headers.getOrElse(Nil))
Right(coursier.maven.SbtMavenRepository.apply(location, authentication))
case Resolver.IvyRepository(_, pattern, creds, headers) =>
val authentication = toCoursierAuthentication(creds, headers)
val authentication = toCoursierAuthentication(creds, headers.getOrElse(Nil))
coursier.ivy.IvyRepository.parse(pattern, authentication = authentication)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ package org.scalasteward.core.data

import cats.Order
import cats.syntax.all._
import io.circe.Codec
import io.circe.generic.extras.semiauto._
import io.circe.{Decoder, Encoder}
import org.scalasteward.core.util.Nel

/** A list of dependencies with the same groupId, (non-cross) artifactId, and version. */
Expand All @@ -44,9 +43,12 @@ object CrossDependency {
.map(grouped => CrossDependency(grouped.sorted))
.toList

implicit val crossDependencyCodec: Codec[CrossDependency] =
deriveUnwrappedCodec
implicit val crossDependencyDecoder: Decoder[CrossDependency] =
Decoder[Nel[Dependency]].map(CrossDependency.apply)

implicit val crossDependencyEncoder: Encoder[CrossDependency] =
Encoder[Nel[Dependency]].contramap(_.dependencies)

implicit val crossDependencyOrder: Order[CrossDependency] =
Order.by((_: CrossDependency).dependencies)
Order.by(_.dependencies)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package org.scalasteward.core.data

import cats.Order
import io.circe.Codec
import io.circe.generic.extras.Configuration
import io.circe.generic.extras.semiauto.deriveConfiguredCodec
import io.circe.generic.semiauto._
import org.scalasteward.core.data.Resolver._

Expand All @@ -41,28 +39,27 @@ object Resolver {
}
final case class Header(key: String, value: String)
object Header {
implicit val headerCodec: Codec[Header] = deriveCodec
implicit val headerCodec: Codec[Header] =
deriveCodec
}
final case class MavenRepository(
name: String,
location: String,
credentials: Option[Credentials],
headers: List[Header] = Nil
headers: Option[List[Header]]
) extends Resolver
final case class IvyRepository(
name: String,
pattern: String,
credentials: Option[Credentials],
headers: List[Header] = Nil
headers: Option[List[Header]]
) extends Resolver

val mavenCentral: MavenRepository =
MavenRepository("public", "https://repo1.maven.org/maven2/", None, Nil)
MavenRepository("public", "https://repo1.maven.org/maven2/", None, None)

implicit val resolverCodec: Codec[Resolver] = {
implicit val customConfig: Configuration = Configuration.default.withDefaults
deriveConfiguredCodec
}
implicit val resolverCodec: Codec[Resolver] =
deriveCodec

implicit val resolverOrder: Order[Resolver] =
Order.by {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ package org.scalasteward.core.data
import cats.Order
import cats.implicits._
import cats.parse.{Numbers, Parser, Rfc5234}
import io.circe.Codec
import io.circe.generic.extras.semiauto.deriveUnwrappedCodec
import io.circe.{Decoder, Encoder}
import org.scalasteward.core.data.Version.startsWithDate

final case class Version(value: String) {
Expand Down Expand Up @@ -128,8 +127,11 @@ object Version {

val tagNames: List[Version => String] = List("v" + _, _.value, "release-" + _)

implicit val versionCodec: Codec[Version] =
deriveUnwrappedCodec
implicit val versionDecoder: Decoder[Version] =
Decoder[String].map(Version.apply)

implicit val versionEncoder: Encoder[Version] =
Encoder[String].contramap(_.value)

implicit val versionOrder: Order[Version] =
Order.from[Version] { (v1, v2) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ final class EditAlg[F[_]](implicit
fileAlg.editFile(repoDir / path, Substring.Replacement.applyAll[F](replacements))
}
_ <- reformatChangedFiles(data)
msgTemplate = data.config.commits.messageOrDefault
msgTemplate = data.config.commitsOrDefault.messageOrDefault
commitMsg = CommitMsg.replaceVariables(msgTemplate)(update, data.repo.branch)
maybeCommit <- gitAlg.commitAllIfDirty(data.repo, commitMsg, data.config.signoffCommits)
} yield maybeCommit.map(UpdateEdit(update, _))

private def reformatChangedFiles(data: RepoData): F[Unit] = {
val reformat =
data.config.scalafmt.runAfterUpgradingOrDefault && data.cache.dependsOn(List(scalafmtModule))
val reformat = data.config.scalafmtOrDefault.runAfterUpgradingOrDefault &&
data.cache.dependsOn(List(scalafmtModule))
F.whenA(reformat) {
data.config.buildRootsOrDefault(data.repo).traverse_ { buildRoot =>
logger.attemptWarn.log_(s"Reformatting changed files failed in ${buildRoot.relativePath}") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ object HookExecutor {
useSandbox = false,
commitMessage = update => CommitMsg(s"Reformat with scalafmt ${update.nextVersion}"),
enabledByCache = _ => true,
enabledByConfig = _.scalafmt.runAfterUpgradingOrDefault,
enabledByConfig = _.scalafmtOrDefault.runAfterUpgradingOrDefault,
addToGitBlameIgnoreRevs = true,
signoffCommits = signoffCommits
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@
package org.scalasteward.core.edit.scalafix

import io.circe.Decoder
import io.circe.generic.extras.Configuration
import io.circe.generic.extras.semiauto._
import io.circe.generic.semiauto._

final case class ScalafixMigrations(
migrations: List[ScalafixMigration] = List.empty
)
final case class ScalafixMigrations(migrations: List[ScalafixMigration])

object ScalafixMigrations {
implicit val configuration: Configuration =
Configuration.default.withDefaults

implicit val scalafixMigrationsDecoder: Decoder[ScalafixMigrations] =
deriveConfiguredDecoder
deriveDecoder
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ final class ScannerAlg[F[_]](implicit
Stream.eval(workspaceAlg.repoDir(repo)).flatMap { repoDir =>
Stream
.evalSeq(gitAlg.findFilesContaining(repo, string))
.filter(path => config.updates.fileExtensionsOrDefault.exists(path.endsWith))
.filter(path => config.updatesOrDefault.fileExtensionsOrDefault.exists(path.endsWith))
.evalMapFilter(path => fileAlg.readFile(repoDir / path).map(_.map(FileData(path, _))))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ object NewPullRequestData {
): NewPullRequestData =
NewPullRequestData(
title = CommitMsg
.replaceVariables(data.repoConfig.commits.messageOrDefault)(
.replaceVariables(data.repoConfig.commitsOrDefault.messageOrDefault)(
data.update,
data.repoData.repo.branch
)
Expand All @@ -287,8 +287,8 @@ object NewPullRequestData {
head = branchName,
base = data.baseBranch,
labels = if (addLabels) labels else List.empty,
assignees = data.repoConfig.assignees,
reviewers = data.repoConfig.reviewers
assignees = data.repoConfig.assigneesOrDefault,
reviewers = data.repoConfig.reviewersOrDefault
)

def updateTypeLabels(anUpdate: Update): List[String] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@

package org.scalasteward.core.forge.data

import io.circe.Codec
import io.circe.generic.extras.semiauto.deriveUnwrappedCodec
import io.circe.{Decoder, Encoder}

final case class PullRequestNumber(value: Int) {
override def toString: String = value.toString
}

object PullRequestNumber {
implicit val pullRequestNumberCodec: Codec[PullRequestNumber] =
deriveUnwrappedCodec
implicit val pullRequestNumberDecoder: Decoder[PullRequestNumber] =
Decoder[Int].map(PullRequestNumber.apply)

implicit val pullRequestNumberEncoder: Encoder[PullRequestNumber] =
Encoder[Int].contramap(_.value)
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final class NurtureAlg[F[_]](config: ForgeCfg)(implicit
_ <- logger.info(s"Nurture ${data.repo.show}")
baseBranch <- cloneAndSync(data.repo, fork)
(grouped, notGrouped) = Update.groupByPullRequestGroup(
data.config.pullRequests.grouping,
data.config.pullRequestsOrDefault.groupingOrDefault,
updates.toList
)
finalUpdates = Update.groupByGroupId(notGrouped) ++ grouped
Expand Down Expand Up @@ -80,7 +80,7 @@ final class NurtureAlg[F[_]](config: ForgeCfg)(implicit
val updateData = UpdateData(data, fork, update, baseBranch, baseSha1, updateBranch)
processUpdate(updateData)
}
.through(util.takeUntilMaybe(0, data.config.updates.limit.map(_.value)) {
.through(util.takeUntilMaybe(0, data.config.updatesOrDefault.limit.map(_.value)) {
case Ignored => 0
case Updated => 1
case Created(_) => 1
Expand Down Expand Up @@ -231,7 +231,8 @@ final class NurtureAlg[F[_]](config: ForgeCfg)(implicit
.flatTraverse(gitAlg.findFilesContaining(data.repo, _))
.map(_.distinct)
allLabels = labelsFor(data.update, edits, filesWithOldVersion, artifactIdToVersionScheme)
labels = filterLabels(allLabels, data.repoData.config.pullRequests.includeMatchedLabels)
labels =
filterLabels(allLabels, data.repoData.config.pullRequestsOrDefault.includeMatchedLabels)
} yield NewPullRequestData.from(
data = data,
branchName = config.tpe.pullRequestHeadFor(data.fork, data.updateBranch),
Expand All @@ -240,7 +241,7 @@ final class NurtureAlg[F[_]](config: ForgeCfg)(implicit
artifactIdToUpdateInfoUrls = artifactIdToUpdateInfoUrls.toMap,
filesWithOldVersion = filesWithOldVersion,
addLabels = config.addLabels,
labels = data.repoData.config.pullRequests.customLabels ++ labels
labels = data.repoData.config.pullRequestsOrDefault.customLabelsOrDefault ++ labels
)

private def createPullRequest(data: UpdateData, edits: List[EditAttempt]): F[ProcessResult] =
Expand Down Expand Up @@ -309,7 +310,7 @@ final class NurtureAlg[F[_]](config: ForgeCfg)(implicit

def closeRetractedPullRequests(data: RepoData): F[Unit] =
pullRequestRepository
.getRetractedPullRequests(data.repo, data.config.updates.retracted)
.getRetractedPullRequests(data.repo, data.config.updatesOrDefault.retractedOrDefault)
.flatMap {
_.traverse_ { case (oldPr, retractedArtifact) =>
closeRetractedPullRequest(data, oldPr, retractedArtifact)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ package org.scalasteward.core.repoconfig

import cats.{Eq, Monoid}
import io.circe.Codec
import io.circe.generic.extras.Configuration
import io.circe.generic.extras.semiauto._
import io.circe.generic.semiauto.deriveCodec

final case class CommitsConfig(
message: Option[String] = None
private val message: Option[String] = None
) {
def messageOrDefault: String =
message.getOrElse(CommitsConfig.defaultMessage)
Expand All @@ -34,11 +33,8 @@ object CommitsConfig {
implicit val commitsConfigEq: Eq[CommitsConfig] =
Eq.fromUniversalEquals

implicit val commitsConfigConfiguration: Configuration =
Configuration.default.withDefaults

implicit val commitsConfigCodec: Codec[CommitsConfig] =
deriveConfiguredCodec
deriveCodec

implicit val commitsConfigMonoid: Monoid[CommitsConfig] =
Monoid.instance(CommitsConfig(), (x, y) => CommitsConfig(message = x.message.orElse(y.message)))
Expand Down
Loading

0 comments on commit f83fb13

Please sign in to comment.