diff --git a/.changeset/wet-dolphins-act.md b/.changeset/wet-dolphins-act.md new file mode 100644 index 0000000000..b975f464cb --- /dev/null +++ b/.changeset/wet-dolphins-act.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-github-actions': patch +--- + +Minor cleanup of the API surface. diff --git a/plugins/github-actions/api-report.md b/plugins/github-actions/api-report.md index ee3e1d679d..08761bad56 100644 --- a/plugins/github-actions/api-report.md +++ b/plugins/github-actions/api-report.md @@ -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; - 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; -// 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; diff --git a/plugins/github-actions/src/api/GithubActionsApi.ts b/plugins/github-actions/src/api/GithubActionsApi.ts index fe516a0211..25bbf0b809 100644 --- a/plugins/github-actions/src/api/GithubActionsApi.ts +++ b/plugins/github-actions/src/api/GithubActionsApi.ts @@ -21,15 +21,13 @@ export const githubActionsApiRef = createApiRef({ 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; - 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; diff --git a/plugins/github-actions/src/api/GithubActionsClient.ts b/plugins/github-actions/src/api/GithubActionsClient.ts index 97ee1860a1..ebe3d92c4f 100644 --- a/plugins/github-actions/src/api/GithubActionsClient.ts +++ b/plugins/github-actions/src/api/GithubActionsClient.ts @@ -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 { + 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; } }