fix: add missing token on job list call to Github API
Signed-off-by: yafanasiev <y.afanasiev@easygenerator.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-github-actions': patch
|
||||
---
|
||||
|
||||
Add missing token on job list call to Github API
|
||||
@@ -44,6 +44,7 @@ describe('EntityPage Test', () => {
|
||||
getWorkflow: jest.fn(),
|
||||
getWorkflowRun: jest.fn(),
|
||||
reRunWorkflow: jest.fn(),
|
||||
listJobsForWorkflowRun: jest.fn(),
|
||||
downloadJobLogsForWorkflowRun: jest.fn(),
|
||||
} as jest.Mocked<typeof githubActionsApiRef.T>;
|
||||
|
||||
|
||||
@@ -77,6 +77,23 @@ export type GithubActionsApi = {
|
||||
repo: string;
|
||||
runId: number;
|
||||
}) => Promise<any>;
|
||||
listJobsForWorkflowRun: ({
|
||||
hostname,
|
||||
owner,
|
||||
repo,
|
||||
id,
|
||||
pageSize,
|
||||
page,
|
||||
}: {
|
||||
hostname?: string;
|
||||
owner: string;
|
||||
repo: string;
|
||||
id: number;
|
||||
pageSize?: number;
|
||||
page?: number;
|
||||
}) => Promise<
|
||||
RestEndpointMethodTypes['actions']['listJobsForWorkflowRun']['response']['data']
|
||||
>;
|
||||
downloadJobLogsForWorkflowRun: ({
|
||||
hostname,
|
||||
owner,
|
||||
|
||||
@@ -128,6 +128,33 @@ export class GithubActionsClient implements GithubActionsApi {
|
||||
});
|
||||
return run.data;
|
||||
}
|
||||
async listJobsForWorkflowRun({
|
||||
hostname,
|
||||
owner,
|
||||
repo,
|
||||
id,
|
||||
pageSize = 100,
|
||||
page = 0,
|
||||
}: {
|
||||
hostname?: string;
|
||||
owner: string;
|
||||
repo: string;
|
||||
id: number;
|
||||
pageSize?: number;
|
||||
page?: number;
|
||||
}): Promise<
|
||||
RestEndpointMethodTypes['actions']['listJobsForWorkflowRun']['response']['data']
|
||||
> {
|
||||
const octokit = await this.getOctokit(hostname);
|
||||
const jobs = await octokit.actions.listJobsForWorkflowRun({
|
||||
owner,
|
||||
repo,
|
||||
run_id: id,
|
||||
per_page: pageSize,
|
||||
page,
|
||||
});
|
||||
return jobs.data;
|
||||
}
|
||||
async downloadJobLogsForWorkflowRun({
|
||||
hostname,
|
||||
owner,
|
||||
|
||||
@@ -29,7 +29,7 @@ export type Job = {
|
||||
conclusion: string;
|
||||
started_at: string;
|
||||
completed_at: string;
|
||||
id: string;
|
||||
id: number;
|
||||
name: string;
|
||||
steps: Step[];
|
||||
};
|
||||
|
||||
@@ -168,7 +168,7 @@ export const WorkflowRunDetails = ({ entity }: { entity: Entity }) => {
|
||||
)[0].host;
|
||||
const [owner, repo] = projectName.value ? projectName.value.split('/') : [];
|
||||
const details = useWorkflowRunsDetails({ hostname, owner, repo });
|
||||
const jobs = useWorkflowRunJobs(details.value?.jobs_url);
|
||||
const jobs = useWorkflowRunJobs({ hostname, owner, repo });
|
||||
|
||||
const error = projectName.error || (projectName.value && details.error);
|
||||
const classes = useStyles();
|
||||
|
||||
@@ -14,19 +14,30 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { useAsync } from 'react-use';
|
||||
import { Jobs } from '../../api/types';
|
||||
import { useApi, useRouteRefParams } from '@backstage/core-api';
|
||||
import { githubActionsApiRef } from '../../api';
|
||||
import { buildRouteRef } from '../../routes';
|
||||
|
||||
export const useWorkflowRunJobs = (jobsUrl?: string) => {
|
||||
const jobs = useAsync(async (): Promise<Jobs> => {
|
||||
if (jobsUrl === undefined) {
|
||||
return {
|
||||
total_count: 0,
|
||||
jobs: [],
|
||||
};
|
||||
}
|
||||
|
||||
const data = await fetch(jobsUrl).then(d => d.json());
|
||||
return data;
|
||||
}, [jobsUrl]);
|
||||
export const useWorkflowRunJobs = ({
|
||||
hostname,
|
||||
owner,
|
||||
repo,
|
||||
}: {
|
||||
hostname?: string;
|
||||
owner: string;
|
||||
repo: string;
|
||||
}) => {
|
||||
const api = useApi(githubActionsApiRef);
|
||||
const { id } = useRouteRefParams(buildRouteRef);
|
||||
const jobs = useAsync(async () => {
|
||||
return repo && owner
|
||||
? api.listJobsForWorkflowRun({
|
||||
hostname,
|
||||
owner,
|
||||
repo,
|
||||
id: parseInt(id, 10),
|
||||
})
|
||||
: Promise.reject('No repo/owner provided');
|
||||
}, [repo, owner, id]);
|
||||
return jobs;
|
||||
};
|
||||
|
||||
@@ -106,7 +106,7 @@ export const WorkflowRunLogs = ({
|
||||
inProgress,
|
||||
}: {
|
||||
entity: Entity;
|
||||
runId: string;
|
||||
runId: number;
|
||||
inProgress: boolean;
|
||||
}) => {
|
||||
const config = useApi(configApiRef);
|
||||
|
||||
@@ -27,7 +27,7 @@ export const useDownloadWorkflowRunLogs = ({
|
||||
hostname?: string;
|
||||
owner: string;
|
||||
repo: string;
|
||||
id: string;
|
||||
id: number;
|
||||
}) => {
|
||||
const api = useApi(githubActionsApiRef);
|
||||
const details = useAsync(async () => {
|
||||
@@ -36,7 +36,7 @@ export const useDownloadWorkflowRunLogs = ({
|
||||
hostname,
|
||||
owner,
|
||||
repo,
|
||||
runId: parseInt(id, 10),
|
||||
runId: id,
|
||||
})
|
||||
: Promise.reject('No repo/owner provided');
|
||||
}, [repo, owner, id]);
|
||||
|
||||
Reference in New Issue
Block a user