Skip to content

Commit f71ba88

Browse files
Prepare for integration with gh-bot-orchestrator
1 parent 9e866d7 commit f71ba88

8 files changed

Lines changed: 26 additions & 18 deletions

File tree

allwrite-cli/src/main/kotlin/pl/allegro/tech/allwrite/cli/CliModule.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package pl.allegro.tech.allwrite.cli
22

33
import org.koin.core.annotation.Module
4-
import pl.allegro.tech.allwrite.runtime.RuntimeModule
54
import pl.allegro.tech.allwrite.cli.application.ApplicationModule
65
import pl.allegro.tech.allwrite.cli.infrastructure.os.OperatingSystemModule
7-
import pl.allegro.tech.allwrite.cli.infrastructure.pullrequestmanager.PullRequestManagerModule
86
import pl.allegro.tech.allwrite.cli.util.ClockModule
7+
import pl.allegro.tech.allwrite.runtime.RuntimeModule
98

109
/**
1110
* This module aggregates all core modules required for the CLI to work correctly.
@@ -17,6 +16,5 @@ import pl.allegro.tech.allwrite.cli.util.ClockModule
1716
RuntimeModule::class,
1817
OperatingSystemModule::class,
1918
ClockModule::class,
20-
PullRequestManagerModule::class,
2119
])
2220
public class CliModule

allwrite-cli/src/main/kotlin/pl/allegro/tech/allwrite/cli/Main.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,29 @@ import org.koin.core.context.startKoin
55
import org.koin.ksp.generated.module
66
import pl.allegro.tech.allwrite.kapt.GenerateCompletions
77
import pl.allegro.tech.allwrite.cli.application.port.incoming.AppEntrypoint
8+
import pl.allegro.tech.allwrite.cli.infrastructure.bot.GithubBotModule
89
import pl.allegro.tech.allwrite.cli.infrastructure.github.GithubModule
910
import pl.allegro.tech.allwrite.cli.infrastructure.os.port.incoming.SystemEnvironment
1011

1112
@GenerateCompletions
1213
public fun main(args: Array<String>) {
1314
startKoin {
1415
modules(CliModule().module)
15-
16-
if (env["GITHUB_ACTIONS"] == "true") {
17-
modules(GithubModule().module)
18-
}
19-
16+
loadDynamicModules()
2017
koin.get<AppEntrypoint>().execute(args)
2118
}
2219
}
2320

21+
private fun KoinApplication.loadDynamicModules() {
22+
val dynamicModules = mapOf(
23+
"GITHUB_ACTIONS" to GithubModule().module,
24+
"GH_BOT" to GithubBotModule().module
25+
)
26+
dynamicModules
27+
.filterKeys { env[it] == "true" }
28+
.values
29+
.forEach(::modules)
30+
}
31+
2432
private val KoinApplication.env: SystemEnvironment
2533
get() = koin.get<SystemEnvironment>()

allwrite-cli/src/main/kotlin/pl/allegro/tech/allwrite/cli/application/RunWithDependabotCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ internal class RunWithDependabotCommand(
8484

8585
companion object {
8686

87-
const val ENV_VAR_RUN_DEPENDABOT_PAYLOAD_NAME: String = "PR_MANAGER_EXTRA_PARAMS"
87+
const val ENV_VAR_RUN_DEPENDABOT_PAYLOAD_NAME: String = "GH_BOT_EXTRA_PARAMS"
8888
const val COMMAND_NAME: String = "run-dependabot"
8989
}
9090
}

allwrite-cli/src/main/kotlin/pl/allegro/tech/allwrite/cli/infrastructure/pullrequestmanager/PullRequestManagerModule.kt renamed to allwrite-cli/src/main/kotlin/pl/allegro/tech/allwrite/cli/infrastructure/bot/GithubBotModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package pl.allegro.tech.allwrite.cli.infrastructure.pullrequestmanager
1+
package pl.allegro.tech.allwrite.cli.infrastructure.bot
22

33
import org.koin.core.annotation.ComponentScan
44
import org.koin.core.annotation.Module
55

66
@Module
77
@ComponentScan
8-
public class PullRequestManagerModule
8+
public class GithubBotModule

allwrite-cli/src/main/kotlin/pl/allegro/tech/allwrite/cli/infrastructure/pullrequestmanager/PullRequestManagerUserProblemReporter.kt renamed to allwrite-cli/src/main/kotlin/pl/allegro/tech/allwrite/cli/infrastructure/bot/GithubBotUserProblemReporter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package pl.allegro.tech.allwrite.cli.infrastructure.pullrequestmanager
1+
package pl.allegro.tech.allwrite.cli.infrastructure.bot
22

33
import io.github.oshai.kotlinlogging.KotlinLogging
44
import org.koin.core.annotation.Single
@@ -10,7 +10,7 @@ import java.io.File
1010
import java.io.PrintStream
1111

1212
@Single
13-
internal class PullRequestManagerUserProblemReporter(
13+
internal class GithubBotUserProblemReporter(
1414
private val systemEnvironment: SystemEnvironment,
1515
) : UserProblemReporter, ShutdownListener {
1616

@@ -22,7 +22,7 @@ internal class PullRequestManagerUserProblemReporter(
2222

2323
override fun onAppShutdown() {
2424
if (issues.isNotEmpty()) {
25-
val commentOutput = systemEnvironment["PR_MANAGER_SUMMARY_COMMENT_FILE"]
25+
val commentOutput = systemEnvironment["GH_BOT_SUMMARY_COMMENT_FILE"]
2626
?.let(::File)
2727
?.printWriter()
2828
?: fallbackOutput()

allwrite-cli/src/test/kotlin/pl/allegro/tech/allwrite/cli/CliIntegrationSpec.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import pl.allegro.tech.allwrite.cli.base.BaseCliSpec
77
import pl.allegro.tech.allwrite.cli.fake.os.FakeOperatingSystemModule
88
import pl.allegro.tech.allwrite.cli.fake.os.FakeSystemEnvironment
99
import pl.allegro.tech.allwrite.cli.fake.recipes.FailingPostProcessingRecipe
10+
import pl.allegro.tech.allwrite.cli.infrastructure.bot.GithubBotModule
1011
import pl.allegro.tech.allwrite.runtime.util.injectEagerly
1112
import java.nio.file.Files
1213
import java.nio.file.Path
@@ -23,14 +24,15 @@ class CliIntegrationSpec : BaseCliSpec() {
2324
private val fakeSystemEnvironment: FakeSystemEnvironment by injectEagerly()
2425

2526
override fun additionalModules() = listOf(
27+
GithubBotModule().module,
2628
FakeOperatingSystemModule().module
2729
)
2830

2931
init {
3032
test("should post a comment with summary from failing post-processing recipe") {
3133
// given
3234
val summaryCommentFile = createSummaryCommentFile()
33-
fakeSystemEnvironment["PR_MANAGER_SUMMARY_COMMENT_FILE"] = summaryCommentFile.pathString
35+
fakeSystemEnvironment["GH_BOT_SUMMARY_COMMENT_FILE"] = summaryCommentFile.pathString
3436

3537
// when
3638
appEntrypoint.execute("run", "--recipe", FailingPostProcessingRecipe.name)

allwrite-cli/src/test/kotlin/pl/allegro/tech/allwrite/cli/RunWithDependabotCommandSpec.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class RunWithDependabotCommandSpec : BaseCliSpec() {
4040
test("should fail when incorrect dependabot payload provided") {
4141
shouldThrow<Exception> {
4242
runWithDependabotCommand.test(
43-
envvars = mapOf("PR_MANAGER_EXTRA_PARAMS" to "test")
43+
envvars = mapOf("GH_BOT_EXTRA_PARAMS" to "test")
4444
)
4545
}
4646
}

allwrite-runtime/src/main/kotlin/pl/allegro/tech/allwrite/runtime/OpenrewriteRecipeExecutor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import kotlin.io.path.writeText
2222
@Single
2323
internal class OpenrewriteRecipeExecutor(
2424
private val sourceFilesParser: SourceFilesParser,
25-
private val userProblemReporter: UserProblemReporter,
25+
private val userProblemReporter: UserProblemReporter?,
2626
) : RecipeExecutor {
2727

2828
override fun execute(recipe: Recipe, inputFiles: List<Path>, failOnError: Boolean) {
@@ -77,7 +77,7 @@ internal class OpenrewriteRecipeExecutor(
7777
postprocessingRecipe.postprocess()
7878
}
7979
.filterIsInstance<PostprocessingResult.Failure>()
80-
.forEach { result -> userProblemReporter.reportProblem(Problem(result.errorMessage)) }
80+
.forEach { result -> userProblemReporter?.reportProblem(Problem(result.errorMessage)) }
8181
}
8282

8383
private fun allRecipes(recipe: Recipe): List<Recipe> =

0 commit comments

Comments
 (0)