Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Make --default-repo-conf an optional argument
Browse files Browse the repository at this point in the history
--default-repo-conf is not a mandatory argument and this should be
reflected in the type of Cli.defaultRepoConf.
  • Loading branch information
fthomas committed Jun 23, 2020
1 parent d4cd7d9 commit 24455bb
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ runSteward := Def.taskDyn {
val args = Seq(
Seq("--workspace", s"$projectDir/workspace"),
Seq("--repos-file", s"$projectDir/repos.md"),
Seq("--default-repo-config", s"$projectDir/default.scala-steward.conf"),
Seq("--default-repo-conf", s"$projectDir/default.scala-steward.conf"),
Seq("--git-author-email", s"me@$projectName.org"),
Seq("--vcs-login", projectName),
Seq("--git-ask-pass", s"$home/.github/askpass/$projectName.sh"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object Cli {
final case class Args(
workspace: String,
reposFile: String,
defaultRepoConf: String = "default.scala-steward.conf",
defaultRepoConf: Option[String] = None,
gitAuthorName: String = "Scala Steward",
gitAuthorEmail: String,
vcsType: SupportedVCS = SupportedVCS.GitHub,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import scala.sys.process.Process
final case class Config(
workspace: File,
reposFile: File,
defaultRepoConfigFile: File,
defaultRepoConfigFile: Option[File],
gitAuthor: Author,
vcsType: SupportedVCS,
vcsApiHost: Uri,
Expand Down Expand Up @@ -90,7 +90,7 @@ object Config {
Config(
workspace = args.workspace.toFile,
reposFile = args.reposFile.toFile,
defaultRepoConfigFile = args.defaultRepoConf.toFile,
defaultRepoConfigFile = args.defaultRepoConf.map(_.toFile),
gitAuthor = Author(args.gitAuthorName, args.gitAuthorEmail),
vcsType = args.vcsType,
vcsApiHost = args.vcsApiHost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final case class RepoConfig(
}

object RepoConfig {
private[repoconfig] val empty: RepoConfig = RepoConfig()
val empty: RepoConfig = RepoConfig()

implicit val customConfig: Configuration =
Configuration.default.withDefaults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,25 @@ final class RepoConfigAlg[F[_]](implicit
}

/**
* Default configuration will try to read file specified in config.reposDefaultConfig first;
* Default configuration will try to read file specified in config.defaultRepoConfigFile first;
* if not found - fallback to empty configuration.
*/
lazy val defaultRepoConfig: F[RepoConfig] =
readRepoConfigFromFile(config.defaultRepoConfigFile).map(_.getOrElse(RepoConfig.empty))
val defaultRepoConfig: F[RepoConfig] =
OptionT
.fromOption[F](config.defaultRepoConfigFile)
.flatMap(readRepoConfigFromFile)
.getOrElse(RepoConfig.empty)

def readRepoConfig(repo: Repo): F[Option[RepoConfig]] =
workspaceAlg
.repoDir(repo)
.flatMap(dir => readRepoConfigFromFile(dir / repoConfigBasename))
.flatMap(dir => readRepoConfigFromFile(dir / repoConfigBasename).value)

private def readRepoConfigFromFile(configFile: File): F[Option[RepoConfig]] = {
val maybeRepoConfig = OptionT(fileAlg.readFile(configFile)).map(parseRepoConfig).flatMapF {
case Right(config) => logger.info(s"Parsed $config").as(config.some)
case Left(errorMsg) => logger.info(errorMsg).as(none[RepoConfig])
private def readRepoConfigFromFile(configFile: File): OptionT[F, RepoConfig] =
OptionT(fileAlg.readFile(configFile)).map(parseRepoConfig).flatMapF {
case Right(repoConfig) => logger.info(s"Parsed $repoConfig").as(repoConfig.some)
case Left(errorMsg) => logger.info(errorMsg).as(none[RepoConfig])
}
maybeRepoConfig.value
}
}

object RepoConfigAlg {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CliTest extends AnyFunSuite with Matchers {
Cli.Args(
workspace = "a",
reposFile = "b",
defaultRepoConf = "c",
defaultRepoConf = Some("c"),
gitAuthorEmail = "d",
vcsType = SupportedVCS.Gitlab,
vcsApiHost = uri"http://example.com",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object MockContext {
implicit val config: Config = Config(
workspace = File.temp / "ws",
reposFile = File.temp / "repos.md",
defaultRepoConfigFile = File.temp / "default.scala-steward.conf",
defaultRepoConfigFile = Some(File.temp / "default.scala-steward.conf"),
gitAuthor = Author("Bot Doe", "bot@example.org"),
vcsType = SupportedVCS.GitHub,
vcsApiHost = Uri(),
Expand Down
1 change: 0 additions & 1 deletion scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ curl -s -o "$REPOS_GITLAB" https://raw.githubusercontent.com/scala-steward-org/r

LOGIN="scala-steward"

# Used for running public Scala Steward instance, repos-file / repos-default-conf will be set later
COMMON_ARGS=(
--workspace "$STEWARD_DIR/workspace"
--git-author-email "me@$LOGIN.org"
Expand Down

0 comments on commit 24455bb

Please sign in to comment.