feat: Allow checking out repo PRs
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package moe.nea.firmament.commands
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType
|
||||
import com.mojang.brigadier.arguments.StringArgumentType.string
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
|
||||
@@ -130,6 +131,15 @@ fun firmamentCommand() = literal("firmament") {
|
||||
}
|
||||
}
|
||||
thenLiteral("repo") {
|
||||
thenLiteral("checkpr") {
|
||||
thenArgument("prnum", IntegerArgumentType.integer(1)) { prnum ->
|
||||
thenExecute {
|
||||
val prnum = this[prnum]
|
||||
source.sendFeedback(tr("firmament.repo.reload.pr", "Temporarily reloading repo from PR #${prnum}."))
|
||||
RepoManager.downloadOverridenBranch("refs/pull/$prnum/head")
|
||||
}
|
||||
}
|
||||
}
|
||||
thenLiteral("reload") {
|
||||
thenLiteral("fetch") {
|
||||
thenExecute {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
package moe.nea.firmament.repo
|
||||
|
||||
import io.ktor.client.call.body
|
||||
@@ -55,12 +53,12 @@ object RepoDownloadManager {
|
||||
@Serializable
|
||||
private class GithubCommitsResponse(val sha: String)
|
||||
|
||||
private suspend fun requestLatestGithubSha(): String? {
|
||||
private suspend fun requestLatestGithubSha(branchOverride: String?): String? {
|
||||
if (RepoManager.Config.branch == "prerelease") {
|
||||
RepoManager.Config.branch = "master"
|
||||
}
|
||||
val response =
|
||||
Firmament.httpClient.get("https://api.github.com/repos/${RepoManager.Config.username}/${RepoManager.Config.reponame}/commits/${RepoManager.Config.branch}")
|
||||
Firmament.httpClient.get("https://api.github.com/repos/${RepoManager.Config.username}/${RepoManager.Config.reponame}/commits/${branchOverride ?: RepoManager.Config.branch}")
|
||||
if (response.status.value != 200) {
|
||||
return null
|
||||
}
|
||||
@@ -79,8 +77,9 @@ object RepoDownloadManager {
|
||||
* Downloads the latest repository from github, setting [latestSavedVersionHash].
|
||||
* @return true, if an update was performed, false, otherwise (no update needed, or wasn't able to complete update)
|
||||
*/
|
||||
suspend fun downloadUpdate(force: Boolean): Boolean = withContext(CoroutineName("Repo Update Check")) {
|
||||
val latestSha = requestLatestGithubSha()
|
||||
suspend fun downloadUpdate(force: Boolean, branch: String? = null): Boolean =
|
||||
withContext(CoroutineName("Repo Update Check")) {
|
||||
val latestSha = requestLatestGithubSha(branch)
|
||||
if (latestSha == null) {
|
||||
logger.warn("Could not request github API to retrieve latest REPO sha.")
|
||||
return@withContext false
|
||||
|
||||
@@ -102,6 +102,13 @@ object RepoManager {
|
||||
|
||||
fun getNEUItem(skyblockId: SkyblockId): NEUItem? = neuRepo.items.getItemBySkyblockId(skyblockId.neuItem)
|
||||
|
||||
fun downloadOverridenBranch(branch: String) {
|
||||
Firmament.coroutineScope.launch {
|
||||
RepoDownloadManager.downloadUpdate(true, branch)
|
||||
reload()
|
||||
}
|
||||
}
|
||||
|
||||
fun launchAsyncUpdate(force: Boolean = false) {
|
||||
Firmament.coroutineScope.launch {
|
||||
RepoDownloadManager.downloadUpdate(force)
|
||||
|
||||
Reference in New Issue
Block a user