Fixes #6 Add support for updating releases

This commit is contained in:
Nick Cipollo
2019-12-12 17:09:21 -05:00
parent de74298134
commit 7319d490c8
12 changed files with 297 additions and 51 deletions

View File

@@ -1,6 +1,6 @@
import { Context } from "@actions/github/lib/context";
import { GitHub } from "@actions/github";
import { AnyResponse, Response, ReposCreateReleaseResponse } from "@octokit/rest";
import { AnyResponse, Response, ReposCreateReleaseResponse, ReposGetReleaseByTagResponse } from "@octokit/rest";
export interface Releases {
create(
@@ -11,6 +11,17 @@ export interface Releases {
name?: string
): Promise<Response<ReposCreateReleaseResponse>>
getByTag(tag: string): Promise<Response<ReposGetReleaseByTagResponse>>
update(
id: number,
tag: string,
body?: string,
commitHash?: string,
draft?: boolean,
name?: string
): Promise<Response<ReposCreateReleaseResponse>>
uploadArtifact(
assetUrl: string,
contentLength: number,
@@ -20,7 +31,7 @@ export interface Releases {
): Promise<Response<AnyResponse>>
}
export class GithubReleases implements Releases{
export class GithubReleases implements Releases {
context: Context
git: GitHub
@@ -47,6 +58,34 @@ export class GithubReleases implements Releases{
})
}
async getByTag(tag: string): Promise<Response<ReposGetReleaseByTagResponse>> {
return this.git.repos.getReleaseByTag({
owner: this.context.repo.owner,
repo: this.context.repo.repo,
tag: tag
})
}
async update(
id: number,
tag: string,
body?: string,
commitHash?: string,
draft?: boolean,
name?: string
): Promise<Response<ReposCreateReleaseResponse>> {
return this.git.repos.updateRelease({
release_id: id,
body: body,
name: name,
draft: draft,
owner: this.context.repo.owner,
repo: this.context.repo.repo,
target_commitish: commitHash,
tag_name: tag
})
}
async uploadArtifact(
assetUrl: string,
contentLength: number,