From ffea00187e3c852de34cd61eeea7a443ea1c00ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Hrivn=C3=A1k?= Date: Tue, 17 Dec 2024 15:33:54 +0100 Subject: [PATCH] Fix updating GitHub projects not working properly The issue was in combining it with the old version of the project --- src/commonMain/kotlin/teksturepako/pakku/Version.kt | 2 +- .../teksturepako/pakku/api/actions/update/Update.kt | 7 +++++-- .../kotlin/teksturepako/pakku/api/platforms/GitHub.kt | 4 +++- .../kotlin/teksturepako/pakku/cli/cmd/Status.kt | 11 ++++++++++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/commonMain/kotlin/teksturepako/pakku/Version.kt b/src/commonMain/kotlin/teksturepako/pakku/Version.kt index a390079..a3cad48 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/Version.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/Version.kt @@ -2,4 +2,4 @@ package teksturepako.pakku -const val VERSION = "0.21.0" +const val VERSION = "0.22.0" diff --git a/src/commonMain/kotlin/teksturepako/pakku/api/actions/update/Update.kt b/src/commonMain/kotlin/teksturepako/pakku/api/actions/update/Update.kt index 71ac746..953caec 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/api/actions/update/Update.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/api/actions/update/Update.kt @@ -9,7 +9,6 @@ import teksturepako.pakku.api.platforms.GitHub import teksturepako.pakku.api.platforms.Multiplatform.platforms import teksturepako.pakku.api.projects.Project import teksturepako.pakku.api.projects.UpdateStrategy -import teksturepako.pakku.api.projects.combineWith import teksturepako.pakku.api.projects.inheritPropertiesFrom /** @@ -53,7 +52,11 @@ suspend fun updateMultipleProjectsWithFiles( val ghProjects = ghProjectsDeferred.await().toSet() - (updatedProjects combineWith ghProjects) + updatedProjects.map { accProject -> + ghProjects.find { it.slug[GitHub.serialName] == accProject.slug[GitHub.serialName] } + ?.let { newProject -> combineProjects(accProject, newProject, GitHub.serialName, numberOfFiles) } + ?: accProject + } .filter { it.updateStrategy == UpdateStrategy.LATEST && it !in projects } .toMutableSet() } diff --git a/src/commonMain/kotlin/teksturepako/pakku/api/platforms/GitHub.kt b/src/commonMain/kotlin/teksturepako/pakku/api/platforms/GitHub.kt index 5ae5192..de4b26f 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/api/platforms/GitHub.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/api/platforms/GitHub.kt @@ -74,14 +74,16 @@ object GitHub : Http(), Provider val projectFiles = if (fileId == null) { + // Multiple files json.decodeFromString>( this.requestBody("https://api.github.com/repos/$input/releases") ?: return null ) - .flatMap { it.toProjectFiles(project.id[this.serialName]!!).take(numberOfFiles) } + .flatMap { it.toProjectFiles(project.id[this.serialName]!!).take(1) } .take(numberOfFiles) } else { + // One file json.decodeFromString( this.requestBody("https://api.github.com/repos/$input/releases/tags/$fileId") ?: return null ).toProjectFiles(project.id[this.serialName]!!).take(numberOfFiles) diff --git a/src/commonMain/kotlin/teksturepako/pakku/cli/cmd/Status.kt b/src/commonMain/kotlin/teksturepako/pakku/cli/cmd/Status.kt index 545f8d5..0b093f6 100644 --- a/src/commonMain/kotlin/teksturepako/pakku/cli/cmd/Status.kt +++ b/src/commonMain/kotlin/teksturepako/pakku/cli/cmd/Status.kt @@ -18,6 +18,7 @@ import teksturepako.pakku.api.data.ConfigFile import teksturepako.pakku.api.data.LockFile import teksturepako.pakku.api.platforms.Platform import teksturepako.pakku.cli.ui.* +import teksturepako.pakku.debug class Status: CliktCommand() @@ -111,9 +112,16 @@ class Status: CliktCommand() for (provider in updatedProject.getProviders()) { + debug { println(provider.serialName) } + val cFile = currentProject.getFilesForProvider(provider).firstOrNull()?.fileName val uFile = updatedProject.getFilesForProvider(provider).firstOrNull()?.fileName + debug { + println(cFile) + println(updatedProject.files) + } + if (cFile == null || uFile == null || cFile == uFile) continue val (cDiffFile, uDiffFile) = coloredStringDiff(cFile, uFile) @@ -154,7 +162,7 @@ class Status: CliktCommand() ) projects() } - else -> + updatedProjects.size > 1 -> { terminal.pInfo("Following projects have a new version available:") terminal.println( @@ -165,6 +173,7 @@ class Status: CliktCommand() ) projects() } + else -> echo() } } } \ No newline at end of file