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
This commit is contained in:
Erica Marigold 2024-11-30 18:25:44 +00:00
parent bc2d438975
commit 5b1a25bd53
2 changed files with 28 additions and 16 deletions

View file

@ -18,7 +18,28 @@ export type Config = {
authToken: Option<string>,
retries: Option<number>,
}
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)

View file

@ -31,21 +31,8 @@ export type ToolId = {
version: Option<Semver.SemverImpl>,
}
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")}:`