releases: mutualize releases handling logic and move it to github class
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -31,13 +31,14 @@ import {SummaryTableCell} from '@actions/core/lib/summary';
|
||||
import * as github from '@actions/github';
|
||||
import {GitHub as Octokit} from '@actions/github/lib/utils';
|
||||
import {Context} from '@actions/github/lib/context';
|
||||
import * as httpm from '@actions/http-client';
|
||||
import {TransferProgressEvent} from '@azure/core-http';
|
||||
import {BlobClient, BlobHTTPHeaders} from '@azure/storage-blob';
|
||||
import {jwtDecode, JwtPayload} from 'jwt-decode';
|
||||
|
||||
import {Util} from './util';
|
||||
|
||||
import {BuildSummaryOpts, GitHubActionsRuntimeToken, GitHubActionsRuntimeTokenAC, GitHubRepo, UploadArtifactOpts, UploadArtifactResponse} from './types/github';
|
||||
import {BuildSummaryOpts, GitHubActionsRuntimeToken, GitHubActionsRuntimeTokenAC, GitHubContentOpts, GitHubRelease, GitHubRepo, UploadArtifactOpts, UploadArtifactResponse} from './types/github';
|
||||
|
||||
export interface GitHubOpts {
|
||||
token?: string;
|
||||
@@ -54,6 +55,18 @@ export class GitHub {
|
||||
return this.octokit.rest.repos.get({...github.context.repo}).then(response => response.data as GitHubRepo);
|
||||
}
|
||||
|
||||
public async releases(name: string, opts: GitHubContentOpts): Promise<Record<string, GitHubRelease>> {
|
||||
const url = `https://raw.githubusercontent.com/${opts.owner}/${opts.repo}/${opts.ref}/${opts.path}`;
|
||||
const http: httpm.HttpClient = new httpm.HttpClient('docker-actions-toolkit');
|
||||
const httpResp: httpm.HttpClientResponse = await http.get(url);
|
||||
const dt = await httpResp.readBody();
|
||||
const statusCode = httpResp.message.statusCode || 500;
|
||||
if (statusCode >= 400) {
|
||||
throw new Error(`Failed to get ${name} releases from ${url} with status code ${statusCode}: ${dt}`);
|
||||
}
|
||||
return <Record<string, GitHubRelease>>JSON.parse(dt);
|
||||
}
|
||||
|
||||
static get context(): Context {
|
||||
return github.context;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user