aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data/repo
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2024-05-24 17:37:44 +1000
committerGitHub <noreply@github.com>2024-05-24 09:37:44 +0200
commit17ac70d7cd8416324acfffcde656930b4e9ae612 (patch)
tree97774ea6f112879386bf69df4830a4091f3cd13b /src/main/java/at/hannibal2/skyhanni/data/repo
parent2a036647d4a06d8d1c5bcbfe9437c4def1aa7eee (diff)
downloadskyhanni-17ac70d7cd8416324acfffcde656930b4e9ae612.tar.gz
skyhanni-17ac70d7cd8416324acfffcde656930b4e9ae612.tar.bz2
skyhanni-17ac70d7cd8416324acfffcde656930b4e9ae612.zip
Add: Ability to switch repo branch (#1835)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data/repo')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt56
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt11
2 files changed, 59 insertions, 8 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt
index 29a22138d..358b00c9c 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt
@@ -36,22 +36,28 @@ class RepoManager(private val configLocation: File) {
companion object {
+ private val config get() = SkyHanniMod.feature.dev.repo
+
val successfulConstants = mutableListOf<String>()
val unsuccessfulConstants = mutableListOf<String>()
private var lastConstant: String? = null
- fun setlastConstant(constant: String) {
+ fun setLastConstant(constant: String) {
lastConstant?.let {
successfulConstants.add(it)
}
lastConstant = constant
}
+
+ fun getRepoLocation(): String {
+ return "${config.location.user}/${config.location.name}/${config.location.branch}"
+ }
}
fun loadRepoInformation() {
atomicShouldManuallyReload.set(true)
- if (SkyHanniMod.feature.dev.repoAutoUpdate) {
+ if (config.repoAutoUpdate) {
fetchRepository(false).thenRun(this::reloadRepository)
} else {
reloadRepository()
@@ -62,6 +68,7 @@ class RepoManager(private val configLocation: File) {
fun updateRepo() {
atomicShouldManuallyReload.set(true)
+ checkRepoLocation()
fetchRepository(true).thenRun { this.reloadRepository("Repo updated successfully.") }
}
@@ -219,7 +226,7 @@ class RepoManager(private val configLocation: File) {
if (unsuccessfulConstants.isNotEmpty()) {
ChatUtils.error(
"§7Repo Issue! Some features may not work. Please report this error on the Discord!\n"
- + "§7Repo Auto Update Value: §c${SkyHanniMod.feature.dev.repoAutoUpdate}\n"
+ + "§7Repo Auto Update Value: §c${config.repoAutoUpdate}\n"
+ "§7If you have Repo Auto Update turned off, please try turning that on.\n"
+ "§cUnsuccessful Constants §7(${unsuccessfulConstants.size}):"
)
@@ -266,15 +273,15 @@ class RepoManager(private val configLocation: File) {
}
private fun getCommitApiUrl(): String {
- val repoUser = "hannibal002"
- val repoName = "SkyHanni-REPO"
- val repoBranch = "main"
+ val repoUser = config.location.user
+ val repoName = config.location.name
+ val repoBranch = config.location.branch
return String.format("https://api.github.com/repos/%s/%s/commits/%s", repoUser, repoName, repoBranch)
}
private fun getDownloadUrl(commitId: String?): String {
- val repoUser = "hannibal002"
- val repoName = "SkyHanni-REPO"
+ val repoUser = config.location.user
+ val repoName = config.location.name
return String.format("https://github.com/%s/%s/archive/%s.zip", repoUser, repoName, commitId)
}
@@ -293,4 +300,37 @@ class RepoManager(private val configLocation: File) {
fun onNeuRepoReload(event: io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent) {
NeuRepositoryReloadEvent().postAndCatch()
}
+
+ fun resetRepositoryLocation(manual: Boolean = false) {
+ val defaultUser = "hannibal002"
+ val defaultName = "SkyHanni-Repo"
+ val defaultBranch = "main"
+
+ with(config.location) {
+ if (user == defaultUser && name == defaultName && branch == defaultBranch) {
+ if (manual) {
+ ChatUtils.chat("Repo settings are already on default!")
+ }
+ return
+ }
+
+ user = defaultUser
+ name = defaultName
+ branch = defaultBranch
+ if (manual) {
+ ChatUtils.clickableChat("Reset Repo settings to default. " +
+ "Click §aUpdate Repo Now §ein config or run /shupdaterepo to update!",
+ onClick = {
+ updateRepo()
+ })
+ }
+ }
+ }
+
+ private fun checkRepoLocation() {
+ if (config.location.user.isEmpty() || config.location.name.isEmpty() || config.location.branch.isEmpty()) {
+ ChatUtils.userError("Invalid Repo settings detected, resetting default settings.")
+ resetRepositoryLocation()
+ }
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt
index 861e17c82..1e9af5d69 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.data.repo
+import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.test.command.ErrorManager
import com.google.gson.Gson
import java.io.BufferedReader
@@ -103,4 +104,14 @@ object RepoUtils {
}
}
}
+
+ @JvmStatic
+ fun updateRepo() {
+ SkyHanniMod.repo.updateRepo()
+ }
+
+ @JvmStatic
+ fun resetRepoLocation() {
+ SkyHanniMod.repo.resetRepositoryLocation(manual = true)
+ }
}