Auto-commit after successful build: update app gameplay/UI, improve build setup
Changed files:\napp/build.gradle.kts app/src/main/java/solutions/tretter/githugandroid/GitRuntime.kt app/src/main/java/solutions/tretter/githugandroid/levels/CoreLevels.kt app/src/main/java/solutions/tretter/githugandroid/levels/LevelCatalog.kt
This commit is contained in:
@@ -18,7 +18,21 @@ internal fun coreLevels(): List<Level> = listOf(
|
||||
commandSuggestions = listOf("git config user.name GitHug", "git config user.email githug@example.com"),
|
||||
setup = { RepoState(initialized = true, branches = mapOf("master" to 0)) },
|
||||
validator = repoPredicate { repo ->
|
||||
repo.config.containsKey("user.name") && repo.config.containsKey("user.email")
|
||||
val hasUserName = repo.config.containsKey("user.name")
|
||||
val observedUserName = repo.config["user.name"]
|
||||
AppLog.d(
|
||||
"Validation",
|
||||
"Config rule key='user.name' expected=defined observed=${observedUserName ?: "<missing>"} passed=$hasUserName",
|
||||
)
|
||||
|
||||
val hasUserEmail = repo.config.containsKey("user.email")
|
||||
val observedUserEmail = repo.config["user.email"]
|
||||
AppLog.d(
|
||||
"Validation",
|
||||
"Config rule key='user.email' expected=defined observed=${observedUserEmail ?: "<missing>"} passed=$hasUserEmail",
|
||||
)
|
||||
|
||||
hasUserName && hasUserEmail
|
||||
},
|
||||
),
|
||||
level(
|
||||
|
||||
@@ -10,11 +10,68 @@ internal fun level(
|
||||
commandSuggestions: List<String> = listOf("git status", "git log", "git help"),
|
||||
setup: () -> RepoState,
|
||||
validator: (RepoState, String) -> Boolean,
|
||||
): Level = Level(id, title, description, hints, commandSuggestions, validator, setup)
|
||||
): Level = Level(
|
||||
id = id,
|
||||
title = title,
|
||||
description = description,
|
||||
hints = hints,
|
||||
commandSuggestions = commandSuggestions,
|
||||
validator = loggingValidator(id, title, validator),
|
||||
setup = setup,
|
||||
)
|
||||
|
||||
internal fun commandAnswer(vararg answers: String): (RepoState, String) -> Boolean = { _, command ->
|
||||
val normalized = command.trim()
|
||||
answers.any { it.equals(normalized, ignoreCase = true) }
|
||||
val matched = answers.firstOrNull { it.equals(normalized, ignoreCase = true) }
|
||||
AppLog.d(
|
||||
"Validation",
|
||||
"commandAnswer normalized='$normalized' expected=${answers.toList()} matched=${matched != null}",
|
||||
)
|
||||
matched != null
|
||||
}
|
||||
|
||||
internal fun repoPredicate(block: (RepoState) -> Boolean): (RepoState, String) -> Boolean = { repo, _ -> block(repo) }
|
||||
internal fun repoPredicate(block: (RepoState) -> Boolean): (RepoState, String) -> Boolean = { repo, _ ->
|
||||
block(repo)
|
||||
}
|
||||
|
||||
private fun loggingValidator(
|
||||
levelId: String,
|
||||
levelTitle: String,
|
||||
validator: (RepoState, String) -> Boolean,
|
||||
): (RepoState, String) -> Boolean = { repo, command ->
|
||||
AppLog.d(
|
||||
"Validation",
|
||||
buildString {
|
||||
append("Evaluating level=")
|
||||
append(levelId)
|
||||
append(" title=")
|
||||
append(levelTitle)
|
||||
append(" command='")
|
||||
append(command)
|
||||
append("' repo=")
|
||||
append(repo.validationSnapshot())
|
||||
},
|
||||
)
|
||||
val result = validator(repo, command)
|
||||
AppLog.d("Validation", "Result level=$levelId passed=$result")
|
||||
result
|
||||
}
|
||||
|
||||
private fun RepoState.validationSnapshot(): String = buildString {
|
||||
append("initialized=")
|
||||
append(initialized)
|
||||
append(", headBranch=")
|
||||
append(headBranch)
|
||||
append(", branches=")
|
||||
append(branches.keys.sorted())
|
||||
append(", tags=")
|
||||
append(tags.sorted())
|
||||
append(", remotes=")
|
||||
append(remotes.toSortedMap())
|
||||
append(", config=")
|
||||
append(config.toSortedMap())
|
||||
append(", files=")
|
||||
append(files.map { file -> "${file.name}(staged=${file.staged},tracked=${file.tracked})" }.sorted())
|
||||
append(", commits=")
|
||||
append(commits.map { it.id to it.message })
|
||||
}
|
||||
Reference in New Issue
Block a user