Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/repo-specific-configuration.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Repository-specific configuration

You can add a configuration file `.scala-steward.conf` to configure how Scala Steward updates your repository.
The `.scala-steward.conf` configuration file can be located in the root of your repository, in `.github` directory or in `.config` directory (searched in this order).
You can add a configuration file named either `.scala-steward.conf` or `scala-steward.conf` to configure how Scala Steward updates your repository.
The `[.]scala-steward.conf` configuration file can be located in the root of your repository, in `.github` directory or in `.config` directory (searched in this order).
If a configuration file exists in more than one location, only the first found file is taken into account.

```properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class RepoConfigAlg[F[_]](maybeGlobalRepoConfig: Option[RepoConfig])(impli
)(readRepoConfigFromFile(_))
_ <- configParsingResult.fold(
F.unit,
error => logger.info(s"Failed to parse $repoConfigBasename: ${error.getMessage}"),
error => logger.info(s"Failed to parse $activeConfigFile: ${error.getMessage}"),
repoConfig => logger.info(s"Parsed repo config ${repoConfig.show}")
)
} yield configParsingResult
Expand Down Expand Up @@ -86,8 +86,10 @@ object RepoConfigAlg {
private def activeConfigFile[F[_]](
repoDir: File
)(implicit fileAlg: FileAlg[F], logger: Logger[F], F: Monad[F]): F[Option[File]] = {
val configFileCandidates: F[List[File]] = repoConfigFileSearchPath
.map(_ :+ repoConfigBasename)
val configFileCandidates: F[List[File]] = (repoConfigFileSearchPath
.map(_ :+ repoConfigBasename) ++
repoConfigFileSearchPath
.map(_ :+ repoConfigBasename.substring(1)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is here: The .substring(1) removes the leading dot from the filename.
As you can see I just append the possible non-hidden config file locations to the end of the list, which later will be searched for the first existing config file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to change the repoConfigBasename to be without the . instead, and then add the dot here? substring use here adds a bit of a mental overhead.

PS: not associated with the project, but got a notification because of my PR and had to look at the code! Feel free to ignore :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repoConfigBasename variable is publicly accessible therefore I don't want to change it's value for backwards compatibility.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 46 of this file it maybe good to use the actual filename (activeConfigFile) instead of repoConfigBasename

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mzuehlke Done and pushed, thanks!

.map(path => path.foldLeft(repoDir)(_ / _))
.filterA(fileAlg.isRegularFile)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class RepoConfigAlgTest extends FunSuite {
assert(clue(log).contains(startOfErrorMsg))
}

test("config file in .github/") {
test("hidden config file in .github/") {
val repo = Repo("test", "dot-github-config")
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
val rootConfigFile = repoDir / ".scala-steward.conf"
Expand All @@ -278,7 +278,21 @@ class RepoConfigAlgTest extends FunSuite {
assert(config.maybeRepoConfig.isDefined)
}

test("config file in .config/") {
test("not hidden config file in .github/") {
val repo = Repo("test", "dot-github-config")
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
val rootConfigFile = repoDir / "scala-steward.conf"
val dotGithubConfigFile = repoDir / ".github" / "scala-steward.conf"
val initialState = MockState.empty.addFiles(dotGithubConfigFile -> "").unsafeRunSync()
val config = repoConfigAlg.readRepoConfig(repo).runA(initialState).unsafeRunSync()

assert(!fileAlg.isRegularFile(rootConfigFile).unsafeRunSync())
assert(fileAlg.isRegularFile(dotGithubConfigFile).unsafeRunSync())

assert(config.maybeRepoConfig.isDefined)
}
Copy link
Contributor Author

@mkurz mkurz Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests I added are basically just duplicates of the preceding test(s), just with the dot removed from the filename.


test("hidden config file in .config/") {
val repo = Repo("test", "dot-config-config")
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
val rootConfigFile = repoDir / ".scala-steward.conf"
Expand All @@ -292,6 +306,20 @@ class RepoConfigAlgTest extends FunSuite {
assert(config.maybeRepoConfig.isDefined)
}

test("not hidden config file in .config/") {
val repo = Repo("test", "dot-config-config")
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
val rootConfigFile = repoDir / "scala-steward.conf"
val dotConfigConfigFile = repoDir / ".config" / "scala-steward.conf"
val initialState = MockState.empty.addFiles(dotConfigConfigFile -> "").unsafeRunSync()
val config = repoConfigAlg.readRepoConfig(repo).runA(initialState).unsafeRunSync()

assert(!fileAlg.isRegularFile(rootConfigFile).unsafeRunSync())
assert(fileAlg.isRegularFile(dotConfigConfigFile).unsafeRunSync())

assert(config.maybeRepoConfig.isDefined)
}

test("log warning on multiple config files") {
val repo = Repo("test", "multiple-config")
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
Expand Down
4 changes: 2 additions & 2 deletions modules/docs/mdoc/repo-specific-configuration.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Repository-specific configuration

You can add a configuration file `.scala-steward.conf` to configure how Scala Steward updates your repository.
The `.scala-steward.conf` configuration file can be located in the root of your repository, in `.github` directory or in `.config` directory (searched in this order).
You can add a configuration file named either `.scala-steward.conf` or `scala-steward.conf` to configure how Scala Steward updates your repository.
The `[.]scala-steward.conf` configuration file can be located in the root of your repository, in `.github` directory or in `.config` directory (searched in this order).
If a configuration file exists in more than one location, only the first found file is taken into account.

```scala mdoc:passthrough
Expand Down