From 18999426ee33d7351daf373dd6bbfb245a926015 Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Sat, 23 Dec 2023 10:37:50 -0700 Subject: [PATCH] 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. --- src/OctokitWrapper.ts | 62 +++++++++++++++++++++++++++++++++++++++++++ src/functions.ts | 24 ----------------- 2 files changed, 62 insertions(+), 24 deletions(-) create mode 100644 src/OctokitWrapper.ts diff --git a/src/OctokitWrapper.ts b/src/OctokitWrapper.ts new file mode 100644 index 0000000..738c916 --- /dev/null +++ b/src/OctokitWrapper.ts @@ -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> { + let octokit = {} as InstanceType + 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 +): Promise> { + 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 +): Promise { + return await ok.paginate( + ok.rest.repos.listReleases, + NEXTFLOW_REPO, + response => response.data + ) +} + +export async function latest_stable_release_data( + ok: InstanceType +): Promise { + const { data: stable_release } = await ok.rest.repos.getLatestRelease( + NEXTFLOW_REPO + ) + + return stable_release +} + +export async function pull_latest_stable_release( + ok: InstanceType +): Promise { + const latest_release = await latest_stable_release_data(ok) + return nextflow_release(latest_release) +} diff --git a/src/functions.ts b/src/functions.ts index 51af3b0..f9df0ef 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -1,33 +1,9 @@ import * as core from "@actions/core" -import { GitHub } from "@actions/github/lib/utils" import * as tc from "@actions/tool-cache" import retry from "async-retry" import * as fs from "fs" 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 -): Promise { - 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 -): Promise { - const { data: stable_release } = await ok.rest.repos.getLatestRelease( - NEXTFLOW_REPO - ) - - return stable_release -} export async function release_data( version: string,