Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,10 @@ interface VersionDao {
"""
SELECT * FROM version
WHERE repositoryId = :repositoryId
AND isPrerelease = 0
AND tagName != '$IGNORED_TAG'
ORDER BY publishedDate DESC
LIMIT 1
""",
)
suspend fun getLatestStableVersionWithAssets(repositoryId: Long): VersionWithAssets?

@Transaction
@Query(
"""
SELECT * FROM version
WHERE repositoryId = :repositoryId
AND tagName != '$IGNORED_TAG'
ORDER BY publishedDate DESC
LIMIT 1
""",
)
suspend fun getLatestBetaVersionWithAssets(repositoryId: Long): VersionWithAssets?
suspend fun getVersionsWithAssetsByRepository(repositoryId: Long): List<VersionWithAssets>

@Transaction
@Query("SELECT * FROM version WHERE repositoryId = :repositoryId AND tagName = :tagName LIMIT 1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,36 @@ class VersionWithAssetsRepository @Inject constructor(
}

suspend fun getLatestStableVersionWithAssets(repositoryId: Long): VersionWithAssets? =
versionDao.getLatestStableVersionWithAssets(repositoryId)
versionDao.getVersionsWithAssetsByRepository(repositoryId)
.filter { !it.version.isPrerelease }
.maxWithOrNull(SemVerComparator)
Comment thread
Moustachauve marked this conversation as resolved.
Outdated

suspend fun getLatestBetaVersionWithAssets(repositoryId: Long): VersionWithAssets? =
versionDao.getLatestBetaVersionWithAssets(repositoryId)
versionDao.getVersionsWithAssetsByRepository(repositoryId)
.maxWithOrNull(SemVerComparator)
Comment thread
Moustachauve marked this conversation as resolved.
Outdated

suspend fun getVersionByTag(repositoryId: Long, tagName: String): VersionWithAssets? =
versionDao.getVersionByTagName(repositoryId, tagName)

companion object {
val SemVerComparator = Comparator<VersionWithAssets> { v1, v2 ->
val semver1 = runCatching {
com.vdurmont.semver4j.Semver(v1.version.tagName, com.vdurmont.semver4j.Semver.SemverType.LOOSE)
}.getOrNull()

val semver2 = runCatching {
com.vdurmont.semver4j.Semver(v2.version.tagName, com.vdurmont.semver4j.Semver.SemverType.LOOSE)
}.getOrNull()

if (semver1 != null && semver2 != null) {
semver1.compareTo(semver2)
} else if (semver1 != null) {
1
} else if (semver2 != null) {
-1
} else {
v1.version.publishedDate.compareTo(v2.version.publishedDate)
}
}
Comment thread
Moustachauve marked this conversation as resolved.
Outdated
}
}