refactor: Make tag filtering work on NextflowRelease objects

This commit is contained in:
Thomas A. Christensen II 2023-12-23 10:39:47 -07:00
parent 18999426ee
commit 0b5ecde5fa
Signed by: millironx
GPG key ID: 09335146883990B9

View file

@ -4,14 +4,12 @@ import retry from "async-retry"
import * as fs from "fs" import * as fs from "fs"
import semver from "semver" import semver from "semver"
import { NextflowRelease } from "./NextflowRelease"
export async function release_data( function tag_filter(version: string): (NextflowRelease) => Boolean {
version: string,
ok: InstanceType<typeof GitHub>
): Promise<object> {
// Setup tag-based filtering // Setup tag-based filtering
let filter = (r: object): boolean => { let filter = (r: NextflowRelease): boolean => {
return semver.satisfies(r["tag_name"], version, true) return semver.satisfies(r.versionNumber, version, true)
} }
// Check if the user passed a 'latest*' tag, and override filtering // Check if the user passed a 'latest*' tag, and override filtering
@ -20,23 +18,21 @@ export async function release_data(
if (version.includes("-everything")) { if (version.includes("-everything")) {
// No filtering // No filtering
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
filter = (r: object) => { filter = (r: NextflowRelease) => {
return true return true
} }
} else if (version.includes("-edge")) { } else if (version.includes("-edge")) {
filter = r => { filter = (r: NextflowRelease) => {
return r["tag_name"].endsWith("-edge") return r.versionNumber.endsWith("-edge")
} }
} else { } else {
// This is special: passing 'latest' or 'latest-stable' allows us to use filter = (r: NextflowRelease) => {
// the latest stable GitHub release direct from the API return !r.isEdge
const stable_release = await latest_stable_release_data(ok)
return stable_release
} }
} }
}
// Get all the releases return filter
const all_releases: object[] = await all_nf_releases(ok) }
const matching_releases = all_releases.filter(filter) const matching_releases = all_releases.filter(filter)