mirror of
https://github.com/MillironX/setup-nextflow.git
synced 2024-11-23 10:09:54 +00:00
refactor!: Move all Octokit code to own file
Separation of concerns. We want to completely separate the internals of Octokit from this application, so move any reference/call to Octokit into its own file to symbolize that.
This commit is contained in:
parent
d45224364c
commit
18999426ee
2 changed files with 62 additions and 24 deletions
62
src/OctokitWrapper.ts
Normal file
62
src/OctokitWrapper.ts
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
import { GitHub } from "@actions/github/lib/utils"
|
||||||
|
import * as github from "@actions/github"
|
||||||
|
import * as core from "@actions/core"
|
||||||
|
|
||||||
|
import { NextflowRelease, nextflow_release } from "./NextflowRelease"
|
||||||
|
|
||||||
|
const NEXTFLOW_REPO = { owner: "nextflow-io", repo: "nextflow" }
|
||||||
|
|
||||||
|
export async function setup_octokit(
|
||||||
|
github_token: string
|
||||||
|
): Promise<InstanceType<typeof GitHub>> {
|
||||||
|
let octokit = {} as InstanceType<typeof GitHub>
|
||||||
|
try {
|
||||||
|
octokit = github.getOctokit(github_token)
|
||||||
|
} 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>
|
||||||
|
): Promise<Array<NextflowRelease>> {
|
||||||
|
const all_release_data: object[] = await all_nf_release_data(octokit)
|
||||||
|
var all_releases: NextflowRelease[] = []
|
||||||
|
all_release_data.forEach(data => {
|
||||||
|
all_releases.push(nextflow_release(data))
|
||||||
|
})
|
||||||
|
|
||||||
|
return all_releases
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function all_nf_release_data(
|
||||||
|
ok: InstanceType<typeof GitHub>
|
||||||
|
): Promise<object[]> {
|
||||||
|
return await ok.paginate(
|
||||||
|
ok.rest.repos.listReleases,
|
||||||
|
NEXTFLOW_REPO,
|
||||||
|
response => response.data
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function latest_stable_release_data(
|
||||||
|
ok: InstanceType<typeof GitHub>
|
||||||
|
): Promise<object> {
|
||||||
|
const { data: stable_release } = await ok.rest.repos.getLatestRelease(
|
||||||
|
NEXTFLOW_REPO
|
||||||
|
)
|
||||||
|
|
||||||
|
return stable_release
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function pull_latest_stable_release(
|
||||||
|
ok: InstanceType<typeof GitHub>
|
||||||
|
): Promise<NextflowRelease> {
|
||||||
|
const latest_release = await latest_stable_release_data(ok)
|
||||||
|
return nextflow_release(latest_release)
|
||||||
|
}
|
|
@ -1,33 +1,9 @@
|
||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
import { GitHub } from "@actions/github/lib/utils"
|
|
||||||
import * as tc from "@actions/tool-cache"
|
import * as tc from "@actions/tool-cache"
|
||||||
import retry from "async-retry"
|
import retry from "async-retry"
|
||||||
import * as fs from "fs"
|
import * as fs from "fs"
|
||||||
import semver from "semver"
|
import semver from "semver"
|
||||||
|
|
||||||
const NEXTFLOW_REPO = { owner: "nextflow-io", repo: "nextflow" }
|
|
||||||
|
|
||||||
// HACK Private but I want to test this
|
|
||||||
export async function all_nf_releases(
|
|
||||||
ok: InstanceType<typeof GitHub>
|
|
||||||
): Promise<object[]> {
|
|
||||||
return await ok.paginate(
|
|
||||||
ok.rest.repos.listReleases,
|
|
||||||
NEXTFLOW_REPO,
|
|
||||||
response => response.data
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// HACK Private but I want to test this
|
|
||||||
export async function latest_stable_release_data(
|
|
||||||
ok: InstanceType<typeof GitHub>
|
|
||||||
): Promise<object> {
|
|
||||||
const { data: stable_release } = await ok.rest.repos.getLatestRelease(
|
|
||||||
NEXTFLOW_REPO
|
|
||||||
)
|
|
||||||
|
|
||||||
return stable_release
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function release_data(
|
export async function release_data(
|
||||||
version: string,
|
version: string,
|
||||||
|
|
Loading…
Reference in a new issue