Minor cleanup in gh actions - do not unpack in the signature

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-06-14 14:21:42 +02:00
parent e42cb3887e
commit 217f919f0a
4 changed files with 68 additions and 166 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-github-actions': patch
---
Minor cleanup of the API surface.
+14 -86
View File
@@ -71,18 +71,9 @@ export const EntityRecentGithubActionsRunsCard: ({
// @public (undocumented)
export const GITHUB_ACTIONS_ANNOTATION = 'github.com/project-slug';
// Warning: (ae-missing-release-tag) "GithubActionsApi" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
// @public
export type GithubActionsApi = {
listWorkflowRuns: ({
hostname,
owner,
repo,
pageSize,
page,
branch,
}: {
listWorkflowRuns: (options: {
hostname?: string;
owner: string;
repo: string;
@@ -92,12 +83,7 @@ export type GithubActionsApi = {
}) => Promise<
RestEndpointMethodTypes['actions']['listWorkflowRuns']['response']['data']
>;
getWorkflow: ({
hostname,
owner,
repo,
id,
}: {
getWorkflow: (options: {
hostname?: string;
owner: string;
repo: string;
@@ -105,12 +91,7 @@ export type GithubActionsApi = {
}) => Promise<
RestEndpointMethodTypes['actions']['getWorkflow']['response']['data']
>;
getWorkflowRun: ({
hostname,
owner,
repo,
id,
}: {
getWorkflowRun: (options: {
hostname?: string;
owner: string;
repo: string;
@@ -118,25 +99,13 @@ export type GithubActionsApi = {
}) => Promise<
RestEndpointMethodTypes['actions']['getWorkflowRun']['response']['data']
>;
reRunWorkflow: ({
hostname,
owner,
repo,
runId,
}: {
reRunWorkflow: (options: {
hostname?: string;
owner: string;
repo: string;
runId: number;
}) => Promise<any>;
listJobsForWorkflowRun: ({
hostname,
owner,
repo,
id,
pageSize,
page,
}: {
listJobsForWorkflowRun: (options: {
hostname?: string;
owner: string;
repo: string;
@@ -146,12 +115,7 @@ export type GithubActionsApi = {
}) => Promise<
RestEndpointMethodTypes['actions']['listJobsForWorkflowRun']['response']['data']
>;
downloadJobLogsForWorkflowRun: ({
hostname,
owner,
repo,
runId,
}: {
downloadJobLogsForWorkflowRun: (options: {
hostname?: string;
owner: string;
repo: string;
@@ -166,18 +130,11 @@ export type GithubActionsApi = {
// @public (undocumented)
export const githubActionsApiRef: ApiRef<GithubActionsApi>;
// Warning: (ae-missing-release-tag) "GithubActionsClient" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
// @public
export class GithubActionsClient implements GithubActionsApi {
constructor(options: { configApi: ConfigApi; githubAuthApi: OAuthApi });
// (undocumented)
downloadJobLogsForWorkflowRun({
hostname,
owner,
repo,
runId,
}: {
downloadJobLogsForWorkflowRun(options: {
hostname?: string;
owner: string;
repo: string;
@@ -186,12 +143,7 @@ export class GithubActionsClient implements GithubActionsApi {
RestEndpointMethodTypes['actions']['downloadJobLogsForWorkflowRun']['response']['data']
>;
// (undocumented)
getWorkflow({
hostname,
owner,
repo,
id,
}: {
getWorkflow(options: {
hostname?: string;
owner: string;
repo: string;
@@ -200,12 +152,7 @@ export class GithubActionsClient implements GithubActionsApi {
RestEndpointMethodTypes['actions']['getWorkflow']['response']['data']
>;
// (undocumented)
getWorkflowRun({
hostname,
owner,
repo,
id,
}: {
getWorkflowRun(options: {
hostname?: string;
owner: string;
repo: string;
@@ -214,14 +161,7 @@ export class GithubActionsClient implements GithubActionsApi {
RestEndpointMethodTypes['actions']['getWorkflowRun']['response']['data']
>;
// (undocumented)
listJobsForWorkflowRun({
hostname,
owner,
repo,
id,
pageSize,
page,
}: {
listJobsForWorkflowRun(options: {
hostname?: string;
owner: string;
repo: string;
@@ -232,14 +172,7 @@ export class GithubActionsClient implements GithubActionsApi {
RestEndpointMethodTypes['actions']['listJobsForWorkflowRun']['response']['data']
>;
// (undocumented)
listWorkflowRuns({
hostname,
owner,
repo,
pageSize,
page,
branch,
}: {
listWorkflowRuns(options: {
hostname?: string;
owner: string;
repo: string;
@@ -250,12 +183,7 @@ export class GithubActionsClient implements GithubActionsApi {
RestEndpointMethodTypes['actions']['listWorkflowRuns']['response']['data']
>;
// (undocumented)
reRunWorkflow({
hostname,
owner,
repo,
runId,
}: {
reRunWorkflow(options: {
hostname?: string;
owner: string;
repo: string;
@@ -21,15 +21,13 @@ export const githubActionsApiRef = createApiRef<GithubActionsApi>({
id: 'plugin.githubactions.service',
});
/**
* A client for fetching information about GitHub actions.
*
* @public
*/
export type GithubActionsApi = {
listWorkflowRuns: ({
hostname,
owner,
repo,
pageSize,
page,
branch,
}: {
listWorkflowRuns: (options: {
hostname?: string;
owner: string;
repo: string;
@@ -39,12 +37,8 @@ export type GithubActionsApi = {
}) => Promise<
RestEndpointMethodTypes['actions']['listWorkflowRuns']['response']['data']
>;
getWorkflow: ({
hostname,
owner,
repo,
id,
}: {
getWorkflow: (options: {
hostname?: string;
owner: string;
repo: string;
@@ -52,12 +46,8 @@ export type GithubActionsApi = {
}) => Promise<
RestEndpointMethodTypes['actions']['getWorkflow']['response']['data']
>;
getWorkflowRun: ({
hostname,
owner,
repo,
id,
}: {
getWorkflowRun: (options: {
hostname?: string;
owner: string;
repo: string;
@@ -65,25 +55,15 @@ export type GithubActionsApi = {
}) => Promise<
RestEndpointMethodTypes['actions']['getWorkflowRun']['response']['data']
>;
reRunWorkflow: ({
hostname,
owner,
repo,
runId,
}: {
reRunWorkflow: (options: {
hostname?: string;
owner: string;
repo: string;
runId: number;
}) => Promise<any>;
listJobsForWorkflowRun: ({
hostname,
owner,
repo,
id,
pageSize,
page,
}: {
listJobsForWorkflowRun: (options: {
hostname?: string;
owner: string;
repo: string;
@@ -93,12 +73,8 @@ export type GithubActionsApi = {
}) => Promise<
RestEndpointMethodTypes['actions']['listJobsForWorkflowRun']['response']['data']
>;
downloadJobLogsForWorkflowRun: ({
hostname,
owner,
repo,
runId,
}: {
downloadJobLogsForWorkflowRun: (options: {
hostname?: string;
owner: string;
repo: string;
@@ -19,6 +19,11 @@ import { GithubActionsApi } from './GithubActionsApi';
import { Octokit, RestEndpointMethodTypes } from '@octokit/rest';
import { ConfigApi, OAuthApi } from '@backstage/core-plugin-api';
/**
* A client for fetching information about GitHub actions.
*
* @public
*/
export class GithubActionsClient implements GithubActionsApi {
private readonly configApi: ConfigApi;
private readonly githubAuthApi: OAuthApi;
@@ -41,17 +46,14 @@ export class GithubActionsClient implements GithubActionsApi {
return new Octokit({ auth: token, baseUrl });
}
async reRunWorkflow({
hostname,
owner,
repo,
runId,
}: {
async reRunWorkflow(options: {
hostname?: string;
owner: string;
repo: string;
runId: number;
}): Promise<any> {
const { hostname, owner, repo, runId } = options;
const octokit = await this.getOctokit(hostname);
return octokit.actions.reRunWorkflow({
owner,
@@ -59,14 +61,8 @@ export class GithubActionsClient implements GithubActionsApi {
run_id: runId,
});
}
async listWorkflowRuns({
hostname,
owner,
repo,
pageSize = 100,
page = 0,
branch,
}: {
async listWorkflowRuns(options: {
hostname?: string;
owner: string;
repo: string;
@@ -76,6 +72,8 @@ export class GithubActionsClient implements GithubActionsApi {
}): Promise<
RestEndpointMethodTypes['actions']['listWorkflowRuns']['response']['data']
> {
const { hostname, owner, repo, pageSize = 100, page = 0, branch } = options;
const octokit = await this.getOctokit(hostname);
const workflowRuns = await octokit.actions.listWorkflowRunsForRepo({
owner,
@@ -84,14 +82,11 @@ export class GithubActionsClient implements GithubActionsApi {
page,
...(branch ? { branch } : {}),
});
return workflowRuns.data;
}
async getWorkflow({
hostname,
owner,
repo,
id,
}: {
async getWorkflow(options: {
hostname?: string;
owner: string;
repo: string;
@@ -99,20 +94,19 @@ export class GithubActionsClient implements GithubActionsApi {
}): Promise<
RestEndpointMethodTypes['actions']['getWorkflow']['response']['data']
> {
const { hostname, owner, repo, id } = options;
const octokit = await this.getOctokit(hostname);
const workflow = await octokit.actions.getWorkflow({
owner,
repo,
workflow_id: id,
});
return workflow.data;
}
async getWorkflowRun({
hostname,
owner,
repo,
id,
}: {
async getWorkflowRun(options: {
hostname?: string;
owner: string;
repo: string;
@@ -120,22 +114,19 @@ export class GithubActionsClient implements GithubActionsApi {
}): Promise<
RestEndpointMethodTypes['actions']['getWorkflowRun']['response']['data']
> {
const { hostname, owner, repo, id } = options;
const octokit = await this.getOctokit(hostname);
const run = await octokit.actions.getWorkflowRun({
owner,
repo,
run_id: id,
});
return run.data;
}
async listJobsForWorkflowRun({
hostname,
owner,
repo,
id,
pageSize = 100,
page = 0,
}: {
async listJobsForWorkflowRun(options: {
hostname?: string;
owner: string;
repo: string;
@@ -145,6 +136,8 @@ export class GithubActionsClient implements GithubActionsApi {
}): Promise<
RestEndpointMethodTypes['actions']['listJobsForWorkflowRun']['response']['data']
> {
const { hostname, owner, repo, id, pageSize = 100, page = 0 } = options;
const octokit = await this.getOctokit(hostname);
const jobs = await octokit.actions.listJobsForWorkflowRun({
owner,
@@ -153,14 +146,11 @@ export class GithubActionsClient implements GithubActionsApi {
per_page: pageSize,
page,
});
return jobs.data;
}
async downloadJobLogsForWorkflowRun({
hostname,
owner,
repo,
runId,
}: {
async downloadJobLogsForWorkflowRun(options: {
hostname?: string;
owner: string;
repo: string;
@@ -168,12 +158,15 @@ export class GithubActionsClient implements GithubActionsApi {
}): Promise<
RestEndpointMethodTypes['actions']['downloadJobLogsForWorkflowRun']['response']['data']
> {
const { hostname, owner, repo, runId } = options;
const octokit = await this.getOctokit(hostname);
const workflow = await octokit.actions.downloadJobLogsForWorkflowRun({
owner,
repo,
job_id: runId,
});
return workflow.data;
}
}