mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-10 10:20:44 -07:00
remote fetch
This commit is contained in:
parent
973149e859
commit
905393d2be
5 changed files with 257 additions and 14 deletions
|
|
@ -11,54 +11,83 @@ import java.net.URL
|
|||
import javax.swing.SwingUtilities
|
||||
|
||||
object GitLabPluginFetcher {
|
||||
private const val GITLAB_ACCESS_TOKEN = "glpat-dE2Cs2e4b32-H7c9oGuS"
|
||||
private const val GITLAB_PROJECT_ID = "38297322"
|
||||
private const val GITLAB_BRANCH = "master"
|
||||
private const val CHROME_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
||||
private const val DEBUG = true // Set to false to disable debug logging
|
||||
|
||||
// Debug logging function
|
||||
private fun debugLog(message: String) {
|
||||
if (DEBUG) {
|
||||
println("[GitLabPluginFetcher] $message")
|
||||
}
|
||||
}
|
||||
|
||||
// Function to fetch plugins from GitLab
|
||||
fun fetchGitLabPlugins(onComplete: (List<GitLabPlugin>) -> Unit) {
|
||||
Thread {
|
||||
try {
|
||||
debugLog("Starting to fetch GitLab plugins...")
|
||||
val plugins = mutableListOf<GitLabPlugin>()
|
||||
val apiUrl = "https://gitlab.com/api/v4/projects/${GITLAB_PROJECT_ID}/repository/tree?ref=${GITLAB_BRANCH}"
|
||||
debugLog("API URL: $apiUrl")
|
||||
|
||||
// Create URL connection
|
||||
val url = URL(apiUrl)
|
||||
val connection = url.openConnection() as HttpURLConnection
|
||||
connection.requestMethod = "GET"
|
||||
connection.setRequestProperty("PRIVATE-TOKEN", GITLAB_ACCESS_TOKEN)
|
||||
connection.setRequestProperty("User-Agent", CHROME_USER_AGENT)
|
||||
debugLog("Set User-Agent header to: $CHROME_USER_AGENT")
|
||||
|
||||
// Read response
|
||||
val responseCode = connection.responseCode
|
||||
debugLog("Response code: $responseCode")
|
||||
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
val reader = BufferedReader(InputStreamReader(connection.inputStream))
|
||||
val response = reader.use { it.readText() }
|
||||
debugLog("Response length: ${response.length} characters")
|
||||
debugLog("Response preview: ${response.take(200)}...")
|
||||
|
||||
// Parse JSON response
|
||||
val gson = Gson()
|
||||
val treeItems = gson.fromJson(response, Array<JsonObject>::class.java)
|
||||
debugLog("Parsed ${treeItems.size} items from JSON")
|
||||
|
||||
// Filter for directories (trees)
|
||||
var directoryCount = 0
|
||||
for (jsonObject in treeItems) {
|
||||
if (jsonObject["type"].asString == "tree") {
|
||||
directoryCount++
|
||||
val folderId = jsonObject["id"].asString
|
||||
val folderPath = jsonObject["path"].asString
|
||||
debugLog("Processing directory: $folderPath (ID: $folderId)")
|
||||
|
||||
try {
|
||||
val pluginProperties = fetchPluginProperties(folderPath)
|
||||
plugins.add(GitLabPlugin(folderId, folderPath, pluginProperties, null))
|
||||
debugLog("Successfully fetched properties for: $folderPath")
|
||||
} catch (e: Exception) {
|
||||
debugLog("Error fetching plugin.properties for $folderPath: ${e.message}")
|
||||
plugins.add(GitLabPlugin(folderId, folderPath, null, "Error fetching plugin.properties"))
|
||||
}
|
||||
}
|
||||
}
|
||||
debugLog("Found $directoryCount directories (trees)")
|
||||
} else {
|
||||
debugLog("HTTP error: $responseCode")
|
||||
val errorReader = BufferedReader(InputStreamReader(connection.errorStream))
|
||||
val errorResponse = errorReader.use { it.readText() }
|
||||
debugLog("Error response: $errorResponse")
|
||||
}
|
||||
|
||||
debugLog("Completed fetching plugins. Total plugins: ${plugins.size}")
|
||||
// Update on UI thread
|
||||
SwingUtilities.invokeLater {
|
||||
onComplete(plugins)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
debugLog("Exception occurred: ${e.message}")
|
||||
e.printStackTrace()
|
||||
SwingUtilities.invokeLater {
|
||||
onComplete(emptyList())
|
||||
|
|
@ -71,27 +100,37 @@ object GitLabPluginFetcher {
|
|||
private fun fetchPluginProperties(folderPath: String): PluginProperties {
|
||||
val pluginFilePath = "$folderPath/plugin.properties"
|
||||
val pluginUrl = "https://gitlab.com/api/v4/projects/${GITLAB_PROJECT_ID}/repository/files/${pluginFilePath.replace("/", "%2F")}/raw?ref=${GITLAB_BRANCH}"
|
||||
debugLog("Fetching plugin.properties from: $pluginUrl")
|
||||
|
||||
// Create URL connection
|
||||
val url = URL(pluginUrl)
|
||||
val connection = url.openConnection() as HttpURLConnection
|
||||
connection.requestMethod = "GET"
|
||||
connection.setRequestProperty("PRIVATE-TOKEN", GITLAB_ACCESS_TOKEN)
|
||||
connection.setRequestProperty("User-Agent", CHROME_USER_AGENT)
|
||||
|
||||
// Read response
|
||||
val responseCode = connection.responseCode
|
||||
debugLog("plugin.properties response code: $responseCode")
|
||||
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
val reader = BufferedReader(InputStreamReader(connection.inputStream))
|
||||
val rawContent = reader.use { it.readText() }
|
||||
debugLog("plugin.properties content length: ${rawContent.length} characters")
|
||||
debugLog("plugin.properties content preview: ${rawContent.take(200)}...")
|
||||
|
||||
return parseProperties(rawContent)
|
||||
} else {
|
||||
debugLog("Failed to fetch plugin.properties. Response code: $responseCode")
|
||||
val errorReader = BufferedReader(InputStreamReader(connection.errorStream))
|
||||
val errorResponse = errorReader.use { it.readText() }
|
||||
debugLog("Error response for plugin.properties: $errorResponse")
|
||||
throw Exception("Plugin file not found for folder: $folderPath")
|
||||
}
|
||||
}
|
||||
|
||||
// Function to parse plugin.properties content
|
||||
private fun parseProperties(content: String): PluginProperties {
|
||||
debugLog("Parsing plugin.properties content")
|
||||
val lines = content.split("\n")
|
||||
var author = "Unknown"
|
||||
var version = "Unknown"
|
||||
|
|
@ -104,13 +143,23 @@ object GitLabPluginFetcher {
|
|||
val value = parts[1].replace("\"", "").replace("'", "").trim()
|
||||
|
||||
when {
|
||||
key.startsWith("AUTHOR", ignoreCase = true) -> author = value
|
||||
key.startsWith("VERSION", ignoreCase = true) -> version = value
|
||||
key.startsWith("DESCRIPTION", ignoreCase = true) -> description = value
|
||||
key.startsWith("AUTHOR", ignoreCase = true) -> {
|
||||
author = value
|
||||
debugLog("Found author: $value")
|
||||
}
|
||||
key.startsWith("VERSION", ignoreCase = true) -> {
|
||||
version = value
|
||||
debugLog("Found version: $value")
|
||||
}
|
||||
key.startsWith("DESCRIPTION", ignoreCase = true) -> {
|
||||
description = value
|
||||
debugLog("Found description: $value")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debugLog("Parsed properties - Author: $author, Version: $version, Description: $description")
|
||||
return PluginProperties(author, version, description)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package KondoKit.components.ReflectiveEditorComponents
|
||||
|
||||
/**
|
||||
* Simple test to verify GitLabPluginFetcher debug logging works
|
||||
*/
|
||||
fun main() {
|
||||
println("Testing GitLabPluginFetcher with debug logging...")
|
||||
|
||||
GitLabPluginFetcher.fetchGitLabPlugins { plugins ->
|
||||
println("Fetched ${plugins.size} plugins")
|
||||
plugins.forEach { plugin ->
|
||||
println("- ${plugin.path}: ${plugin.pluginProperties?.description ?: plugin.pluginError}")
|
||||
}
|
||||
}
|
||||
|
||||
// Give the async fetch some time to complete
|
||||
Thread.sleep(10000)
|
||||
println("Test completed")
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package KondoKit.components.ReflectiveEditorComponents
|
||||
|
||||
/**
|
||||
* Data class representing a plugin with its installation status and update information
|
||||
*/
|
||||
data class PluginStatus(
|
||||
val name: String,
|
||||
val installedVersion: String?,
|
||||
val remoteVersion: String?,
|
||||
val description: String?,
|
||||
val author: String?,
|
||||
val gitLabPlugin: GitLabPlugin?,
|
||||
val isInstalled: Boolean,
|
||||
val needsUpdate: Boolean
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue