Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace VCS with Forge #2916

Merged
merged 4 commits into from
Jan 13, 2023
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
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ runSteward := Def.taskDyn {
Seq("--workspace", s"$projectDir/workspace"),
Seq("--repos-file", s"$projectDir/repos.md"),
Seq("--git-author-email", s"me@$projectName.org"),
Seq("--vcs-login", projectName),
Seq("--forge-login", projectName),
Seq("--git-ask-pass", s"$home/.github/askpass/$projectName.sh"),
Seq("--whitelist", s"$home/.cache/coursier"),
Seq("--whitelist", s"$home/.cache/JNA"),
Expand Down
18 changes: 12 additions & 6 deletions docs/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All command line arguments for the `scala-steward` application.
```
Usage:
scala-steward validate-repo-config
scala-steward --workspace <file> --repos-file <file> [--git-author-name <string>] --git-author-email <string> [--git-author-signing-key <string>] --git-ask-pass <file> [--sign-commits] [--vcs-type <vcs-type>] [--vcs-api-host <uri>] --vcs-login <string> [--do-not-fork] [--add-labels] [--ignore-opts-files] [--env-var <name=value>]... [--process-timeout <duration>] [--whitelist <string>]... [--read-only <string>]... [--enable-sandbox | --disable-sandbox] [--max-buffer-size <integer>] [--repo-config <uri>]... [--disable-default-repo-config] [--scalafix-migrations <uri>]... [--disable-default-scalafix-migrations] [--artifact-migrations <uri>]... [--disable-default-artifact-migrations] [--cache-ttl <duration>] [--bitbucket-use-default-reviewers] [--bitbucket-server-use-default-reviewers] [--gitlab-merge-when-pipeline-succeeds] [--gitlab-required-reviewers <integer>] [--azure-repos-organization <string>] [--github-app-id <integer> --github-app-key-file <file>] [--url-checker-test-url <uri>]... [--default-maven-repo <string>] [--refresh-backoff-period <duration>]
scala-steward --workspace <file> --repos-file <file> [--git-author-name <string>] --git-author-email <string> [--git-author-signing-key <string>] --git-ask-pass <file> [--sign-commits] [--forge-type <forge-type>] [--forge-api-host <uri>] --forge-login <string> [--do-not-fork] [--add-labels] [--ignore-opts-files] [--env-var <name=value>]... [--process-timeout <duration>] [--whitelist <string>]... [--read-only <string>]... [--enable-sandbox | --disable-sandbox] [--max-buffer-size <integer>] [--repo-config <uri>]... [--disable-default-repo-config] [--scalafix-migrations <uri>]... [--disable-default-scalafix-migrations] [--artifact-migrations <uri>]... [--disable-default-artifact-migrations] [--cache-ttl <duration>] [--bitbucket-use-default-reviewers] [--bitbucket-server-use-default-reviewers] [--gitlab-merge-when-pipeline-succeeds] [--gitlab-required-reviewers <integer>] [--azure-repos-organization <string>] [--github-app-id <integer> --github-app-key-file <file>] [--url-checker-test-url <uri>]... [--default-maven-repo <string>] [--refresh-backoff-period <duration>]



Expand All @@ -26,16 +26,22 @@ Options and flags:
An executable file that returns the git credentials
--sign-commits
Whether to sign commits; default: false
--vcs-type <vcs-type>
--forge-type <forge-type>
One of azure-repos, bitbucket, bitbucket-server, github, gitlab; default: github
--vcs-type <forge-type>
deprecated in favor of --forge-type
--forge-api-host <uri>
API URL of the forge; default: https://api.github.com
--vcs-api-host <uri>
API URL of the git hoster; default: https://api.github.com
deprecated in favor of --forge-api-host
--forge-login <string>
The user name for the forge
--vcs-login <string>
The user name for the git hoster
deprecated in favor of --forge-login
--do-not-fork
Whether to not push the update branches to a fork; default: false
--add-labels
Whether to add labels on pull or merge requests (if supported by git hoster)
Whether to add labels on pull or merge requests (if supported by the forge)
--ignore-opts-files
Whether to remove ".jvmopts" and ".sbtopts" files before invoking the build tool
--env-var <name=value>
Expand Down Expand Up @@ -75,7 +81,7 @@ Options and flags:
--gitlab-required-reviewers <integer>
When set, the number of required reviewers for a merge request will be set to this number (non-negative integer). Is only used in the context of gitlab-merge-when-pipeline-succeeds being enabled, and requires that the configured access token have the appropriate privileges. Also requires a Gitlab Premium subscription.
--azure-repos-organization <string>
The Azure organization (required when vcs type is azure-repos)
The Azure organization (required when --forge-type is azure-repos)
--github-app-id <integer>
GitHub application id
--github-app-key-file <file>
Expand Down
34 changes: 17 additions & 17 deletions docs/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ sbt stage
--repos-file "$STEWARD_DIR/repos.md" \
--repo-config "$STEWARD_DIR/default.scala-steward.conf" \
--git-author-email ${EMAIL} \
--vcs-api-host "https://api.github.com" \
--vcs-login ${LOGIN} \
--forge-api-host "https://api.github.com" \
--forge-login ${LOGIN} \
--git-ask-pass "$STEWARD_DIR/.github/askpass/$LOGIN.sh" \
--sign-commits \
--env-var FOO=BAR
Expand All @@ -27,8 +27,8 @@ docker run -v $STEWARD_DIR:/opt/scala-steward -it fthomas/scala-steward:latest \
--repos-file "/opt/scala-steward/repos.md" \
--repo-config "/opt/scala-steward/default.scala-steward.conf" \
--git-author-email ${EMAIL} \
--vcs-api-host "https://api.github.com" \
--vcs-login ${LOGIN} \
--forge-api-host "https://api.github.com" \
--forge-login ${LOGIN} \
--git-ask-pass "/opt/scala-steward/.github/askpass/$LOGIN.sh" \
--sign-commits \
--env-var FOO=BAR \
Expand Down Expand Up @@ -90,7 +90,7 @@ example1.realm=Example Realm
```
sbt
project core
run --do-not-fork --workspace "/path/workspace" --repos-file "/path/repos.md" --repo-config "/path/default.scala-steward.conf" --git-ask-pass "/path/pass.sh" --git-author-email "email@example.org" --vcs-type "gitlab" --vcs-api-host "https://gitlab.com/api/v4/" --vcs-login "gitlab.steward"
run --do-not-fork --workspace "/path/workspace" --repos-file "/path/repos.md" --repo-config "/path/default.scala-steward.conf" --git-ask-pass "/path/pass.sh" --git-author-email "email@example.org" --forge-type "gitlab" --forge-api-host "https://gitlab.com/api/v4/" --forge-login "gitlab.steward"
```


Expand All @@ -115,9 +115,9 @@ docker run -v $PWD:/opt/scala-steward \
--repo-config "/opt/scala-steward/default.scala-steward.conf" \
--git-ask-pass "/opt/scala-steward/pass.sh" \
--git-author-email "myemail@company.xyz" \
--vcs-type "bitbucket" \
--vcs-api-host "https://api.bitbucket.org/2.0" \
--vcs-login "$BITBUCKET_USERNAME"
--forge-type "bitbucket" \
--forge-api-host "https://api.bitbucket.org/2.0" \
--forge-login "$BITBUCKET_USERNAME"
```

* Run it from a CI tool or manually using with this command:
Expand All @@ -144,9 +144,9 @@ docker run -v $PWD:/opt/scala-steward \
--repo-config "/opt/scala-steward/default.scala-steward.conf" \
--git-ask-pass "/opt/scala-steward/pass.sh" \
--git-author-email "myemail@company.xyz" \
--vcs-type "bitbucket" \
--vcs-api-host "https://api.bitbucket.org/2.0" \
--vcs-login "$BITBUCKET_USERNAME"
--forge-type "bitbucket" \
--forge-api-host "https://api.bitbucket.org/2.0" \
--forge-login "$BITBUCKET_USERNAME"
```

NOTE: This script is slightly different to the one in the previous Bitbucket
Expand Down Expand Up @@ -238,9 +238,9 @@ check:
--repos-file "$CI_PROJECT_DIR/repos.md"
--repo-config "$CI_PROJECT_DIR/default.scala-steward.conf"
--git-author-email "${EMAIL}"
--vcs-type "gitlab"
--vcs-api-host "${CI_API_V4_URL}"
--vcs-login "${LOGIN}"
--forge-type "gitlab"
--forge-api-host "${CI_API_V4_URL}"
--forge-login "${LOGIN}"
--git-ask-pass "$CI_PROJECT_DIR/askpass.sh"
cache:
key: scala-steward
Expand Down Expand Up @@ -306,9 +306,9 @@ docker run -v $PWD:/opt/scala-steward \
--workspace "/opt/scala-steward/workspace" \
--repos-file "/opt/scala-steward/repos.md" \
--git-author-email "email@mycompany.com" \
--vcs-type "azure-repos" \
--vcs-api-host "https://dev.azure.com" \
--vcs-login "email@mycompany.com" \
--forge-type "azure-repos" \
--forge-api-host "https://dev.azure.com" \
--forge-login "email@mycompany.com" \
--azure-repos-organization "mycompany" \
--git-ask-pass "/opt/scala-steward/pass.sh"
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import org.http4s.Uri
import org.http4s.syntax.literals._
import org.scalasteward.core.application.Config._
import org.scalasteward.core.data.Resolver
import org.scalasteward.core.forge.ForgeType
import org.scalasteward.core.forge.ForgeType.GitHub
import org.scalasteward.core.forge.github.GitHubApp
import org.scalasteward.core.git.Author
import org.scalasteward.core.util.Nel
import org.scalasteward.core.util.dateTime.renderFiniteDuration
import org.scalasteward.core.vcs.VCSType
import org.scalasteward.core.vcs.VCSType.GitHub
import org.scalasteward.core.vcs.github.GitHubApp
import scala.concurrent.duration._

object Cli {
Expand All @@ -57,9 +57,9 @@ object Cli {
Validated.fromEither(Uri.fromString(s).leftMap(_.message)).toValidatedNel
}

implicit val vcsTypeArgument: Argument[VCSType] =
Argument.from("vcs-type") { s =>
Validated.fromEither(VCSType.parse(s)).toValidatedNel
implicit val forgeTypeArgument: Argument[ForgeType] =
Argument.from("forge-type") { s =>
Validated.fromEither(ForgeType.parse(s)).toValidatedNel
}

private val multiple = "(can be used multiple times)"
Expand Down Expand Up @@ -94,36 +94,58 @@ object Cli {
private val gitCfg: Opts[GitCfg] =
(gitAuthor, gitAskPass, signCommits).mapN(GitCfg.apply)

private val vcsType = {
val help = VCSType.all.map(_.asString).mkString("One of ", ", ", "") +
private val vcsType =
option[ForgeType](
"vcs-type",
"deprecated in favor of --forge-type",
visibility = Visibility.Partial
)

private val forgeType = {
val help = ForgeType.all.map(_.asString).mkString("One of ", ", ", "") +
s"; default: ${GitHub.asString}"
option[VCSType]("vcs-type", help).withDefault(GitHub)
option[ForgeType]("forge-type", help).orElse(vcsType).withDefault(GitHub)
}

private val vcsApiHost: Opts[Uri] =
option[Uri]("vcs-api-host", s"API URL of the git hoster; default: ${GitHub.publicApiBaseUrl}")
private val vcsApiHost =
option[Uri](
"vcs-api-host",
"deprecated in favor of --forge-api-host",
visibility = Visibility.Partial
)

private val forgeApiHost: Opts[Uri] =
option[Uri]("forge-api-host", s"API URL of the forge; default: ${GitHub.publicApiBaseUrl}")
.orElse(vcsApiHost)
.withDefault(GitHub.publicApiBaseUrl)

private val vcsLogin: Opts[String] =
option[String]("vcs-login", "The user name for the git hoster")
private val vcsLogin =
option[String](
"vcs-login",
"deprecated in favor of --forge-login",
visibility = Visibility.Partial
)

private val forgeLogin: Opts[String] =
option[String]("forge-login", "The user name for the forge").orElse(vcsLogin)

private val doNotFork: Opts[Boolean] =
flag("do-not-fork", "Whether to not push the update branches to a fork; default: false").orFalse

private val addPrLabels: Opts[Boolean] =
flag(
"add-labels",
"Whether to add labels on pull or merge requests (if supported by git hoster)"
"Whether to add labels on pull or merge requests (if supported by the forge)"
).orFalse

private val vcsCfg: Opts[VCSCfg] =
(vcsType, vcsApiHost, vcsLogin, doNotFork, addPrLabels)
.mapN(VCSCfg.apply)
private val forgeCfg: Opts[ForgeCfg] =
(forgeType, forgeApiHost, forgeLogin, doNotFork, addPrLabels)
.mapN(ForgeCfg.apply)
.validate(
s"${VCSType.allNot(_.supportsForking)} do not support fork mode"
s"${ForgeType.allNot(_.supportsForking)} do not support fork mode"
)(cfg => cfg.tpe.supportsForking || cfg.doNotFork)
.validate(
s"${VCSType.allNot(_.supportsLabels)} do not support pull request labels"
s"${ForgeType.allNot(_.supportsLabels)} do not support pull request labels"
)(cfg => cfg.tpe.supportsLabels || !cfg.addLabels)

private val ignoreOptsFiles: Opts[Boolean] =
Expand Down Expand Up @@ -265,7 +287,7 @@ object Cli {
private val azureReposOrganization: Opts[Option[String]] =
option[String](
"azure-repos-organization",
"The Azure organization (required when vcs type is azure-repos)"
"The Azure organization (required when --forge-type is azure-repos)"
).orNone

private val azureReposConfig: Opts[AzureReposConfig] =
Expand Down Expand Up @@ -306,7 +328,7 @@ object Cli {
workspace,
reposFile,
gitCfg,
vcsCfg,
forgeCfg,
ignoreOptsFiles,
processCfg,
repoConfigCfg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ import org.http4s.Uri.UserInfo
import org.scalasteward.core.application.Cli.EnvVar
import org.scalasteward.core.application.Config._
import org.scalasteward.core.data.Resolver
import org.scalasteward.core.forge.ForgeType
import org.scalasteward.core.forge.data.AuthenticatedUser
import org.scalasteward.core.forge.github.GitHubApp
import org.scalasteward.core.git.Author
import org.scalasteward.core.io.{ProcessAlg, WorkspaceAlg}
import org.scalasteward.core.util
import org.scalasteward.core.util.Nel
import org.scalasteward.core.vcs.VCSType
import org.scalasteward.core.vcs.data.AuthenticatedUser
import org.scalasteward.core.vcs.github.GitHubApp
import scala.concurrent.duration.FiniteDuration

/** Configuration for scala-steward.
*
* ==vcsCfg.apiHost==
* ==forgeCfg.apiHost==
* REST API v3 endpoints prefix
*
* For github.com this is "https://api.github.com", see [[https://developer.github.com/v3/]].
Expand All @@ -45,7 +45,7 @@ import scala.concurrent.duration.FiniteDuration
*
* ==gitCfg.gitAskPass==
* Program that is invoked by scala-steward and git (via the `GIT_ASKPASS` environment variable) to
* request the password for the user vcsCfg.vcsLogin.
* request the password for the user forgeCfg.forgeLogin.
*
* This program could just be a simple shell script that echos the password.
*
Expand All @@ -55,7 +55,7 @@ final case class Config(
workspace: File,
reposFile: File,
gitCfg: GitCfg,
vcsCfg: VCSCfg,
forgeCfg: ForgeCfg,
ignoreOptsFiles: Boolean,
processCfg: ProcessCfg,
repoConfigCfg: RepoConfigCfg,
Expand All @@ -71,19 +71,19 @@ final case class Config(
defaultResolver: Resolver,
refreshBackoffPeriod: FiniteDuration
) {
def vcsUser[F[_]](implicit
def forgeUser[F[_]](implicit
processAlg: ProcessAlg[F],
workspaceAlg: WorkspaceAlg[F],
F: Monad[F]
): F[AuthenticatedUser] =
for {
rootDir <- workspaceAlg.rootDir
urlWithUser = util.uri.withUserInfo
.replace(UserInfo(vcsCfg.login, None))(vcsCfg.apiHost)
.replace(UserInfo(forgeCfg.login, None))(forgeCfg.apiHost)
.renderString
prompt = s"Password for '$urlWithUser': "
password <- processAlg.exec(Nel.of(gitCfg.gitAskPass.pathAsString, prompt), rootDir)
} yield AuthenticatedUser(vcsCfg.login, password.mkString.trim)
} yield AuthenticatedUser(forgeCfg.login, password.mkString.trim)
}

object Config {
Expand All @@ -93,8 +93,8 @@ object Config {
signCommits: Boolean
)

final case class VCSCfg(
tpe: VCSType,
final case class ForgeCfg(
tpe: ForgeType,
apiHost: Uri,
login: String,
doNotFork: Boolean,
Expand Down
Loading