Fixes #26 Update dependencies and fix octokit types

Fixes #27 Add inputs for specifying owner and repo
This commit is contained in:
Nick Cipollo
2021-02-09 20:46:38 -05:00
parent 970fd8405b
commit 09eb035337
15 changed files with 525 additions and 482 deletions

View File

@@ -1,13 +1,14 @@
import {Context} from "@actions/github/lib/context";
import { GitHub } from '@actions/github/lib/utils'
import {
OctokitResponse,
ReposListReleaseAssetsResponseData,
ReposCreateReleaseResponseData,
ReposGetReleaseByTagResponseData,
ReposListReleasesResponseData,
ReposUploadReleaseAssetResponseData
} from "@octokit/types";
import {GitHub} from '@actions/github/lib/utils'
import {OctokitResponse} from "@octokit/types";
import {RestEndpointMethodTypes} from "@octokit/plugin-rest-endpoint-methods";
import {Inputs} from "./Inputs";
export type CreateReleaseResponse = RestEndpointMethodTypes["repos"]["createRelease"]["response"]
export type ReleaseByTagResponse = RestEndpointMethodTypes["repos"]["getReleaseByTag"]["response"]
export type ListReleasesResponse = RestEndpointMethodTypes["repos"]["listReleases"]["response"]
export type ListReleaseAssetsResponse = RestEndpointMethodTypes["repos"]["listReleaseAssets"]["response"]
export type UpdateReleaseResponse = RestEndpointMethodTypes["repos"]["updateRelease"]["response"]
export type UploadArtifactResponse = RestEndpointMethodTypes["repos"]["uploadReleaseAsset"]["response"]
export interface Releases {
create(
@@ -17,15 +18,15 @@ export interface Releases {
draft?: boolean,
name?: string,
prerelease?: boolean
): Promise<OctokitResponse<ReposCreateReleaseResponseData>>
): Promise<CreateReleaseResponse>
deleteArtifact(assetId: number): Promise<OctokitResponse<any>>
getByTag(tag: string): Promise<OctokitResponse<ReposGetReleaseByTagResponseData>>
getByTag(tag: string): Promise<ReleaseByTagResponse>
listArtifactsForRelease(releaseId: number): Promise<OctokitResponse<ReposListReleaseAssetsResponseData>>
listArtifactsForRelease(releaseId: number): Promise<ListReleaseAssetsResponse>
listReleases(): Promise<OctokitResponse<ReposListReleasesResponseData>>
listReleases(): Promise<ListReleasesResponse>
update(
id: number,
@@ -35,7 +36,7 @@ export interface Releases {
draft?: boolean,
name?: string,
prerelease?: boolean
): Promise<OctokitResponse<ReposCreateReleaseResponseData>>
): Promise<UpdateReleaseResponse>
uploadArtifact(
assetUrl: string,
@@ -44,15 +45,15 @@ export interface Releases {
file: string | object,
name: string,
releaseId: number,
): Promise<OctokitResponse<ReposUploadReleaseAssetResponseData>>
): Promise<UploadArtifactResponse>
}
export class GithubReleases implements Releases {
context: Context
git: InstanceType<typeof GitHub>
inputs: Inputs
constructor(context: Context, git: InstanceType<typeof GitHub>) {
this.context = context
constructor(inputs: Inputs, git: InstanceType<typeof GitHub>) {
this.inputs = inputs
this.git = git
}
@@ -63,15 +64,15 @@ export class GithubReleases implements Releases {
draft?: boolean,
name?: string,
prerelease?: boolean
): Promise<OctokitResponse<ReposCreateReleaseResponseData>> {
): Promise<CreateReleaseResponse> {
// noinspection TypeScriptValidateJSTypes
return this.git.repos.createRelease({
body: body,
name: name,
draft: draft,
owner: this.context.repo.owner,
owner: this.inputs.owner,
prerelease: prerelease,
repo: this.context.repo.repo,
repo: this.inputs.repo,
target_commitish: commitHash,
tag_name: tag
})
@@ -82,33 +83,33 @@ export class GithubReleases implements Releases {
): Promise<OctokitResponse<any>> {
return this.git.repos.deleteReleaseAsset({
asset_id: assetId,
owner: this.context.repo.owner,
repo: this.context.repo.repo
owner: this.inputs.owner,
repo: this.inputs.repo
})
}
async getByTag(tag: string): Promise<ReleaseByTagResponse> {
return this.git.repos.getReleaseByTag({
owner: this.inputs.owner,
repo: this.inputs.repo,
tag: tag
})
}
async listArtifactsForRelease(
releaseId: number
): Promise<OctokitResponse<ReposListReleaseAssetsResponseData>> {
): Promise<ListReleaseAssetsResponse> {
return this.git.repos.listReleaseAssets({
owner: this.context.repo.owner,
owner: this.inputs.owner,
release_id: releaseId,
repo: this.context.repo.repo
repo: this.inputs.repo
})
}
async listReleases(): Promise<OctokitResponse<ReposListReleasesResponseData>> {
async listReleases(): Promise<ListReleasesResponse> {
return this.git.repos.listReleases({
owner: this.context.repo.owner,
repo: this.context.repo.repo
})
}
async getByTag(tag: string): Promise<OctokitResponse<ReposGetReleaseByTagResponseData>> {
return this.git.repos.getReleaseByTag({
owner: this.context.repo.owner,
repo: this.context.repo.repo,
tag: tag
owner: this.inputs.owner,
repo: this.inputs.repo
})
}
@@ -120,16 +121,16 @@ export class GithubReleases implements Releases {
draft?: boolean,
name?: string,
prerelease?: boolean
): Promise<OctokitResponse<ReposCreateReleaseResponseData>> {
): Promise<UpdateReleaseResponse> {
// noinspection TypeScriptValidateJSTypes
return this.git.repos.updateRelease({
release_id: id,
body: body,
name: name,
draft: draft,
owner: this.context.repo.owner,
owner: this.inputs.owner,
prerelease: prerelease,
repo: this.context.repo.repo,
repo: this.inputs.repo,
target_commitish: commitHash,
tag_name: tag
})
@@ -142,7 +143,7 @@ export class GithubReleases implements Releases {
file: string | object,
name: string,
releaseId: number,
): Promise<OctokitResponse<ReposUploadReleaseAssetResponseData>> {
): Promise<UploadArtifactResponse> {
return this.git.repos.uploadReleaseAsset({
url: assetUrl,
headers: {
@@ -151,9 +152,9 @@ export class GithubReleases implements Releases {
},
data: file as any,
name: name,
owner: this.context.repo.owner,
owner: this.inputs.owner,
release_id: releaseId,
repo: this.context.repo.repo
repo: this.inputs.repo
})
}
}