mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-04-02 17:40:08 +02:00
🐛 Fix issue with Packagist version check
This commit is contained in:
@@ -34,32 +34,23 @@ class Packagist {
|
|||||||
throw PackagistError.unexpectedResponseStructure
|
throw PackagistError.unexpectedResponseStructure
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter for stable versions using the version_normalized string.
|
// Packagist v2 API returns versions in descending order (newest first).
|
||||||
// A stable version typically does not have a hyphen (-) indicating a pre-release.
|
// Filter for stable versions - those without a hyphen in version_normalized.
|
||||||
let stableVersions = versionsArray.filter { version in
|
let stableVersions = versionsArray.filter { version in
|
||||||
guard let versionNormalized = version.version_normalized else {
|
guard let versionNormalized = version.version_normalized else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
// Filter out pre-release versions (alpha, beta, RC, etc.)
|
||||||
// Filter out versions with a hyphen, which are usually unstable.
|
|
||||||
return !versionNormalized.contains("-")
|
return !versionNormalized.contains("-")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort the filtered versions using version_normalized, which is designed for lexicographical sorting.
|
// Get the first stable version (which is the latest)
|
||||||
let sortedVersions = stableVersions.sorted { (version1, version2) -> Bool in
|
guard let latestVersionInfo = stableVersions.first,
|
||||||
guard let v1 = version1.version_normalized, let v2 = version2.version_normalized else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return v1.lexicographicallyPrecedes(v2)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The last element of the sorted array is the latest version
|
|
||||||
guard let latestVersionInfo = sortedVersions.last,
|
|
||||||
let latestVersion = latestVersionInfo.version else {
|
let latestVersion = latestVersionInfo.version else {
|
||||||
throw PackagistError.noStableVersions
|
throw PackagistError.noStableVersions
|
||||||
}
|
}
|
||||||
|
|
||||||
return try! VersionNumber.parse(latestVersion)
|
return try VersionNumber.parse(latestVersion)
|
||||||
} catch {
|
} catch {
|
||||||
// Catch any errors that occurred and re-throw them as our custom error type for better diagnostics.
|
// Catch any errors that occurred and re-throw them as our custom error type for better diagnostics.
|
||||||
if let decodingError = error as? DecodingError {
|
if let decodingError = error as? DecodingError {
|
||||||
|
|||||||
Reference in New Issue
Block a user