mirror of
https://github.com/MillironX/setup-nextflow.git
synced 2024-11-23 10:09:54 +00:00
feat!: Remove Octokit API
This commit is contained in:
parent
d72644926c
commit
b51df5d41b
2 changed files with 0 additions and 184 deletions
|
@ -1,95 +0,0 @@
|
|||
import * as core from "@actions/core"
|
||||
import { getOctokitOptions, GitHub } from "@actions/github/lib/utils"
|
||||
import { throttling } from "@octokit/plugin-throttling"
|
||||
|
||||
import { nextflow_release, NextflowRelease } from "./nextflow-release"
|
||||
|
||||
const NEXTFLOW_REPO = {
|
||||
owner: "nextflow-io",
|
||||
repo: "nextflow",
|
||||
per_page: 100,
|
||||
headers: {
|
||||
"x-github-api-version": "2022-11-28"
|
||||
}
|
||||
}
|
||||
|
||||
export async function setup_octokit(
|
||||
github_token: string,
|
||||
cooldown = 60,
|
||||
max_retries = 3
|
||||
): Promise<InstanceType<typeof GitHub>> {
|
||||
const throttledOctokit = GitHub.plugin(throttling)
|
||||
let octokit = {} as InstanceType<typeof GitHub>
|
||||
try {
|
||||
octokit = new throttledOctokit(
|
||||
getOctokitOptions(github_token, {
|
||||
throttle: {
|
||||
onRateLimit: (retryAfter, options, ok, retryCount) => {
|
||||
ok.log.warn(
|
||||
`Request quota exhausted for request ${options.method} ${options.url}`
|
||||
)
|
||||
|
||||
if (retryCount < max_retries) {
|
||||
ok.log.info(`Retrying after ${retryAfter} seconds!`)
|
||||
return true
|
||||
}
|
||||
},
|
||||
onSecondaryRateLimit: (retryAfter, options, ok, retryCount) => {
|
||||
ok.log.warn(
|
||||
`SecondaryRateLimit detected for request ${options.method} ${options.url}`
|
||||
)
|
||||
|
||||
if (retryCount < max_retries) {
|
||||
octokit.log.info(`Retrying after ${retryAfter} seconds!`)
|
||||
return true
|
||||
}
|
||||
},
|
||||
fallbackSecondaryRateRetryAfter: cooldown
|
||||
}
|
||||
})
|
||||
)
|
||||
} catch (e: unknown) {
|
||||
if (e instanceof Error) {
|
||||
core.setFailed(
|
||||
`Could not authenticate to GitHub Releases API with provided token\n${e.message}`
|
||||
)
|
||||
}
|
||||
}
|
||||
return octokit
|
||||
}
|
||||
|
||||
export async function* pull_releases(
|
||||
octokit: InstanceType<typeof GitHub>
|
||||
): AsyncGenerator<NextflowRelease> {
|
||||
const iterator = octokit.paginate.iterator(
|
||||
octokit.rest.repos.listReleases,
|
||||
NEXTFLOW_REPO
|
||||
)
|
||||
let item_index = 0
|
||||
let release_items = []
|
||||
|
||||
/* eslint-disable-next-line @typescript-eslint/unbound-method */
|
||||
const { next } = iterator[Symbol.asyncIterator]()
|
||||
|
||||
let request = await next()
|
||||
release_items = request.value.data
|
||||
|
||||
while (true) {
|
||||
if (item_index > release_items.length) {
|
||||
request = await next()
|
||||
release_items = request.value.data
|
||||
item_index = 0
|
||||
}
|
||||
yield nextflow_release(release_items[item_index++])
|
||||
}
|
||||
}
|
||||
|
||||
export async function pull_latest_stable_release(
|
||||
ok: InstanceType<typeof GitHub>
|
||||
): Promise<NextflowRelease> {
|
||||
const { data: stable_release } = await ok.rest.repos.getLatestRelease(
|
||||
NEXTFLOW_REPO
|
||||
)
|
||||
|
||||
return nextflow_release(stable_release)
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
import * as github from "@actions/github"
|
||||
import { GitHub } from "@actions/github/lib/utils"
|
||||
import anyTest, { TestFn } from "ava" // eslint-disable-line import/no-unresolved
|
||||
|
||||
import { NextflowRelease } from "../src/nextflow-release"
|
||||
import {
|
||||
pull_latest_stable_release,
|
||||
pull_releases
|
||||
} from "../src/octokit-wrapper"
|
||||
import { getToken } from "./utils"
|
||||
|
||||
const test = anyTest as TestFn<{
|
||||
token: string
|
||||
octokit: InstanceType<typeof GitHub>
|
||||
}>
|
||||
|
||||
test.before(t => {
|
||||
const first = true
|
||||
const current_token = getToken(first)
|
||||
t.context = {
|
||||
token: current_token,
|
||||
octokit: github.getOctokit(current_token)
|
||||
}
|
||||
})
|
||||
|
||||
async function get_latest_release(
|
||||
octokit: InstanceType<typeof GitHub>,
|
||||
use_latest_api: boolean
|
||||
): Promise<NextflowRelease> {
|
||||
if (use_latest_api) {
|
||||
return await pull_latest_stable_release(octokit)
|
||||
} else {
|
||||
const all_releases = pull_releases(octokit)
|
||||
const first_response = await all_releases.next()
|
||||
const first_release = first_response.value
|
||||
? first_response.value
|
||||
: ({} as NextflowRelease)
|
||||
return first_release
|
||||
}
|
||||
}
|
||||
|
||||
const version_macro = test.macro(
|
||||
async (t, object_name: string, use_latest_api: boolean) => {
|
||||
const latest_release = await get_latest_release(
|
||||
t.context.octokit,
|
||||
use_latest_api
|
||||
)
|
||||
t.assert(latest_release[object_name])
|
||||
}
|
||||
)
|
||||
|
||||
test(
|
||||
"OctoKit iterator returns semver-parsable version number",
|
||||
version_macro,
|
||||
"versionNumber",
|
||||
false
|
||||
)
|
||||
test(
|
||||
"OctoKit latest API returns semver-parable version number",
|
||||
version_macro,
|
||||
"versionNumber",
|
||||
true
|
||||
)
|
||||
|
||||
const binary_url_macro = test.macro(
|
||||
async (t, get_all: boolean, use_latest_api: boolean) => {
|
||||
const latest_release = await get_latest_release(
|
||||
t.context.octokit,
|
||||
use_latest_api
|
||||
)
|
||||
const url = get_all ? latest_release.allBinaryURL : latest_release.binaryURL
|
||||
t.notThrows(() => new URL(url))
|
||||
}
|
||||
)
|
||||
|
||||
test("Nextflow binary URL from iterator valid", binary_url_macro, false, false)
|
||||
test("Nextflow binary URL from latest API valid", binary_url_macro, false, true)
|
||||
test(
|
||||
"Nextflow all binary URL from iterator valid",
|
||||
binary_url_macro,
|
||||
true,
|
||||
false
|
||||
)
|
||||
test(
|
||||
"Nextflow all binary URL from latest API valid",
|
||||
binary_url_macro,
|
||||
true,
|
||||
true
|
||||
)
|
Loading…
Reference in a new issue