Skip to content

Commit

Permalink
Remove GitHub App code from core
Browse files Browse the repository at this point in the history
  • Loading branch information
fthomas committed Dec 20, 2023
1 parent a3a2507 commit 75ebd2c
Show file tree
Hide file tree
Showing 18 changed files with 901 additions and 69 deletions.
18 changes: 13 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ val moduleCrossPlatformMatrix: Map[String, List[Platform]] = Map(
"benchmark" -> List(JVMPlatform),
"core" -> List(JVMPlatform),
"docs" -> List(JVMPlatform),
"dummy" -> List(JVMPlatform)
"dummy" -> List(JVMPlatform),
"gh-app-facade" -> List(JVMPlatform)
)

val Scala213 = "2.13.12"
Expand Down Expand Up @@ -111,7 +112,6 @@ lazy val core = myCrossProject("core")
.settings(dockerSettings)
.settings(
libraryDependencies ++= Seq(
Dependencies.bcprovJdk15to18,
Dependencies.betterFiles,
Dependencies.catsCore,
Dependencies.catsEffect,
Expand All @@ -132,9 +132,6 @@ lazy val core = myCrossProject("core")
Dependencies.http4sClient,
Dependencies.http4sCore,
Dependencies.http4sJdkhttpClient,
Dependencies.jjwtApi,
Dependencies.jjwtImpl % Runtime,
Dependencies.jjwtJackson % Runtime,
Dependencies.log4catsSlf4j,
Dependencies.monocleCore,
Dependencies.refined,
Expand Down Expand Up @@ -276,6 +273,17 @@ lazy val dummy = myCrossProject("dummy")
)
)

lazy val ghAppFacade = myCrossProject("gh-app-facade")
.dependsOn(core)
.settings(
libraryDependencies ++= Seq(
Dependencies.bcprovJdk15to18,
Dependencies.jjwtApi,
Dependencies.jjwtImpl % Runtime,
Dependencies.jjwtJackson % Runtime
)
)

/// settings

def myCrossProject(name: String): CrossProject =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.scalasteward.core.application.Config._
import org.scalasteward.core.data.Resolver
import org.scalasteward.core.forge.ForgeType
import org.scalasteward.core.forge.ForgeType.{AzureRepos, 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
Expand Down Expand Up @@ -291,21 +290,6 @@ object Cli {
GitLabCfg.apply
)

private val githubAppId: Opts[Long] =
option[Long](
"github-app-id",
"GitHub application id. Repos accessible by this app are added to the repos in repos.md. git-ask-pass is still required."
)

private val githubAppKeyFile: Opts[File] =
option[File](
"github-app-key-file",
"GitHub application key file. Repos accessible by this app are added to the repos in repos.md. git-ask-pass is still required."
)

private val gitHubApp: Opts[Option[GitHubApp]] =
(githubAppId, githubAppKeyFile).mapN(GitHubApp.apply).orNone

private val azureReposOrganization: Opts[Option[String]] =
option[String](
"azure-repos-organization",
Expand Down Expand Up @@ -352,7 +336,6 @@ object Cli {
bitbucketServerCfg,
gitLabCfg,
azureReposCfg,
gitHubApp,
urlCheckerTestUrls,
defaultMavenRepo,
refreshBackoffPeriod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ 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
Expand Down Expand Up @@ -66,7 +65,6 @@ final case class Config(
bitbucketServerCfg: BitbucketServerCfg,
gitLabCfg: GitLabCfg,
azureReposCfg: AzureReposCfg,
githubApp: Option[GitHubApp],
urlCheckerTestUrls: Nel[Uri],
defaultResolver: Resolver,
refreshBackoffPeriod: FiniteDuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import org.scalasteward.core.edit.EditAlg
import org.scalasteward.core.edit.hooks.HookExecutor
import org.scalasteward.core.edit.scalafix._
import org.scalasteward.core.edit.update.ScannerAlg
import org.scalasteward.core.forge.github.{GitHubAppApiAlg, GitHubAuthAlg}
import org.scalasteward.core.forge.{ForgeApiAlg, ForgeRepoAlg, ForgeSelection}
import org.scalasteward.core.git.{GenGitAlg, GitAlg}
import org.scalasteward.core.io.{FileAlg, ProcessAlg, WorkspaceAlg}
Expand Down Expand Up @@ -159,7 +158,6 @@ object Context {
implicit val repoConfigAlg: RepoConfigAlg[F] = new RepoConfigAlg[F](maybeGlobalRepoConfig)
implicit val filterAlg: FilterAlg[F] = new FilterAlg[F]
implicit val gitAlg: GitAlg[F] = GenGitAlg.create[F](config.gitCfg)
implicit val gitHubAuthAlg: GitHubAuthAlg[F] = GitHubAuthAlg.create[F]
implicit val hookExecutor: HookExecutor[F] = new HookExecutor[F]
implicit val httpJsonClient: HttpJsonClient[F] = new HttpJsonClient[F]
implicit val repoCacheRepository: RepoCacheRepository[F] =
Expand Down Expand Up @@ -191,8 +189,6 @@ object Context {
implicit val nurtureAlg: NurtureAlg[F] = new NurtureAlg[F](config.forgeCfg)
implicit val pruningAlg: PruningAlg[F] = new PruningAlg[F]
implicit val reposFilesLoader: ReposFilesLoader[F] = new ReposFilesLoader[F]
implicit val gitHubAppApiAlg: GitHubAppApiAlg[F] =
new GitHubAppApiAlg[F](config.forgeCfg.apiHost)
implicit val stewardAlg: StewardAlg[F] = new StewardAlg[F](config)
new Context[F]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ package org.scalasteward.core.application

import cats.effect.{ExitCode, Sync}
import cats.syntax.all._
import fs2.Stream
import org.scalasteward.core.data.Repo
import org.scalasteward.core.forge.github.{GitHubApp, GitHubAppApiAlg, GitHubAuthAlg}
import org.scalasteward.core.git.GitAlg
import org.scalasteward.core.io.{FileAlg, WorkspaceAlg}
import org.scalasteward.core.nurture.NurtureAlg
Expand All @@ -30,14 +28,11 @@ import org.scalasteward.core.util
import org.scalasteward.core.util.DateTimeAlg
import org.scalasteward.core.util.logger.LoggerOps
import org.typelevel.log4cats.Logger
import scala.concurrent.duration._

final class StewardAlg[F[_]](config: Config)(implicit
dateTimeAlg: DateTimeAlg[F],
fileAlg: FileAlg[F],
gitAlg: GitAlg[F],
githubAppApiAlg: GitHubAppApiAlg[F],
githubAuthAlg: GitHubAuthAlg[F],
logger: Logger[F],
nurtureAlg: NurtureAlg[F],
pruningAlg: PruningAlg[F],
Expand All @@ -47,25 +42,6 @@ final class StewardAlg[F[_]](config: Config)(implicit
workspaceAlg: WorkspaceAlg[F],
F: Sync[F]
) {
private def getGitHubAppRepos(githubApp: GitHubApp): Stream[F, Repo] =
Stream.evals[F, List, Repo] {
for {
jwt <- githubAuthAlg.createJWT(githubApp, 2.minutes)
installations <- githubAppApiAlg.installations(jwt)
repositories <- installations.traverse { installation =>
githubAppApiAlg
.accessToken(jwt, installation.id)
.flatMap(token => githubAppApiAlg.repositories(token.token))
}
repos <- repositories.flatMap(_.repositories).flatTraverse { repo =>
repo.full_name.split('/') match {
case Array(owner, name) => F.pure(List(Repo(owner, name)))
case _ => logger.error(s"invalid repo $repo").as(List.empty[Repo])
}
}
} yield repos
}

private def steward(repo: Repo): F[Either[Throwable, Unit]] = {
val label = s"Steward ${repo.show}"
logger.infoTotalTime(label) {
Expand All @@ -87,19 +63,18 @@ final class StewardAlg[F[_]](config: Config)(implicit
for {
_ <- selfCheckAlg.checkAll
_ <- workspaceAlg.removeAnyRunSpecificFiles
exitCode <-
(config.githubApp.map(getGitHubAppRepos).getOrElse(Stream.empty) ++
reposFilesLoader.loadAll(config.reposFiles))
.evalMap(repo => steward(repo).map(_.bimap(repo -> _, _ => repo)))
.compile
.toList
.flatMap { results =>
val runResults = RunResults(results)
for {
summaryFile <- workspaceAlg.runSummaryFile
_ <- fileAlg.writeFile(summaryFile, runResults.markdownSummary)
} yield runResults.exitCode
}
exitCode <- reposFilesLoader
.loadAll(config.reposFiles)
.evalMap(repo => steward(repo).map(_.bimap(repo -> _, _ => repo)))
.compile
.toList
.flatMap { results =>
val runResults = RunResults(results)
for {
summaryFile <- workspaceAlg.runSummaryFile
_ <- fileAlg.writeFile(summaryFile, runResults.markdownSummary)
} yield runResults.exitCode
}
} yield exitCode
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.http4s.syntax.literals._
import org.scalasteward.core.application.Cli.ParseResult._
import org.scalasteward.core.application.Cli.{EnvVar, Usage}
import org.scalasteward.core.forge.ForgeType
import org.scalasteward.core.forge.github.GitHubApp
import org.scalasteward.core.util.Nel
import scala.concurrent.duration._

Expand All @@ -30,8 +29,6 @@ class CliTest extends FunSuite {
List("--scalafix-migrations", "/opt/scala-steward/extra-scalafix-migrations.conf"),
List("--artifact-migrations", "/opt/scala-steward/extra-artifact-migrations.conf"),
List("--repo-config", "/opt/scala-steward/scala-steward.conf"),
List("--github-app-id", "12345678"),
List("--github-app-key-file", "example_app_key"),
List("--refresh-backoff-period", "1 day"),
List("--bitbucket-use-default-reviewers")
).flatten
Expand Down Expand Up @@ -60,7 +57,6 @@ class CliTest extends FunSuite {
obtained.artifactCfg.migrations,
List(uri"/opt/scala-steward/extra-artifact-migrations.conf")
)
assertEquals(obtained.githubApp, Some(GitHubApp(12345678L, File("example_app_key"))))
assertEquals(obtained.refreshBackoffPeriod, 1.day)
assert(!obtained.gitLabCfg.mergeWhenPipelineSucceeds)
assertEquals(obtained.gitLabCfg.requiredReviewers, None)
Expand Down
Loading

0 comments on commit 75ebd2c

Please sign in to comment.