-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4605d8f
commit e8eb53c
Showing
4 changed files
with
117 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package teksturepako.pakku.api.actions | ||
|
||
import teksturepako.pakku.api.data.PakkuLock | ||
import teksturepako.pakku.api.projects.Project | ||
import teksturepako.pakku.typoSuggester | ||
|
||
suspend fun Project?.createRemovalRequest( | ||
onWarning: WarningBlock, | ||
onRemoval: RemovalBlock, | ||
onDepRemoval: RemovalBlock, | ||
projectArg: String, | ||
pakkuLock: PakkuLock, | ||
) | ||
{ | ||
if (this != null) | ||
{ | ||
val linkedProjects = pakkuLock.getLinkedProjects(this.pakkuId!!, ignore = this) | ||
|
||
if (linkedProjects.isEmpty()) | ||
{ | ||
onRemoval.remove(this, true) | ||
} | ||
else | ||
{ | ||
onWarning.warning("$projectArg is required by ${linkedProjects.map { it.slug }}") | ||
onRemoval.remove(this, false) | ||
} | ||
|
||
x@ for (pakkuLink in this.pakkuLinks) | ||
{ | ||
val dependency = pakkuLock.getProjectByPakkuId(pakkuLink) ?: continue@x | ||
val depLinkedProjects = pakkuLock.getLinkedProjects(dependency.pakkuId!!) | ||
|
||
if (depLinkedProjects.isNotEmpty()) | ||
{ | ||
onWarning.warning("${dependency.slug} is required by ${depLinkedProjects.map { it.slug }}") | ||
onDepRemoval.remove(dependency, false) | ||
} | ||
else onDepRemoval.remove(dependency, true) | ||
} | ||
} | ||
else | ||
{ | ||
onWarning.warning("$projectArg not found") | ||
val slugs = pakkuLock.getAllProjects().flatMap { it.slug.values } | ||
|
||
typoSuggester(projectArg, slugs).firstOrNull()?.let { arg -> | ||
onWarning.warning("Did you mean $arg?") | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/teksturepako/pakku/api/actions/RequestHandlers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package teksturepako.pakku.api.actions | ||
|
||
import teksturepako.pakku.api.platforms.Platform | ||
import teksturepako.pakku.api.projects.Project | ||
|
||
fun interface WarningBlock | ||
{ | ||
suspend fun warning(message: String) | ||
} | ||
|
||
fun interface ErrorBlock | ||
{ | ||
suspend fun error(error: Error) | ||
} | ||
|
||
fun interface RetryBlock | ||
{ | ||
suspend fun retryWith(platform: Platform): Project? | ||
} | ||
|
||
fun interface SuccessBlock | ||
{ | ||
suspend fun success(project: Project, isRecommended: Boolean, ctx: RequestHandlers) | ||
} | ||
|
||
fun interface RemovalBlock | ||
{ | ||
suspend fun remove(project: Project, isRecommended: Boolean) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters