From 5b1a25bd53b144f33642a68ca02c0dd99bf2c38b Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Sat, 30 Nov 2024 18:25:44 +0000 Subject: [PATCH] feat(lib): relocate `GithubReleases` type and implement custom payload * Also breaks down `GithubReleases` into array of `GithubRelease` type * Adds a `Custom` operation type for internal `Github` class, allowing user to mention custom request data --- toolchainlib/src/github.luau | 27 ++++++++++++++++++++++++++- toolchainlib/src/init.luau | 17 ++--------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/toolchainlib/src/github.luau b/toolchainlib/src/github.luau index 7d359e5..d636d45 100644 --- a/toolchainlib/src/github.luau +++ b/toolchainlib/src/github.luau @@ -18,7 +18,28 @@ export type Config = { authToken: Option, retries: Option, } -export type GithubOperation = "FetchReleases" | "GetMetadata" | "GetActionArtifacts" +export type GithubOperation = + "FetchReleases" + | "GetMetadata" + | "GetActionArtifacts" + | { type: "Custom", payload: net.FetchParams } + +export type GithubRelease = { + tag_name: string, + created_at: string, + published_at: string, + prerelease: boolean, + draft: boolean, + assets: { + { + name: string, + browser_download_url: string, + size: number, + content_type: string, + } + }, +} +export type GithubReleases = { GithubRelease } local API_BASE_URL = "https://api.github.com" local DEFAULT_MAX_RETRIES = 5 @@ -60,6 +81,10 @@ function Github.queueTransactions(self: Github, operations: { GithubOperation }) req.method = "GET" end + if typeof(operation) == "table" and operation.type == "Custom" then + req = operation.payload + end + -- TODO: Other methods table.insert(queue, function(retries: number) diff --git a/toolchainlib/src/init.luau b/toolchainlib/src/init.luau index 540a20e..6b9c43a 100644 --- a/toolchainlib/src/init.luau +++ b/toolchainlib/src/init.luau @@ -31,21 +31,8 @@ export type ToolId = { version: Option, } -export type GithubReleases = { - { - tag_name: string, - prerelease: boolean, - draft: boolean, - assets: { - { - name: string, - browser_download_url: string, - size: number, - content_type: string, - } - }, - } -} +-- TODO: Remove this in a breaking change +export type GithubReleases = Github.GithubReleases local WARN_PREFIX = `{stdio.color("yellow")}{stdio.style("bold")}warn{stdio.color("reset")}:`