From 8bdf33c0d44a94862b5a5e41f2659618ed64c2ac Mon Sep 17 00:00:00 2001 From: ebarrios Date: Fri, 18 Sep 2020 11:51:11 +0200 Subject: [PATCH] Cleanup unused types --- plugins/cloudbuild/src/api/CloudbuildApi.ts | 3 +- .../cloudbuild/src/api/CloudbuildClient.ts | 11 +-- plugins/cloudbuild/src/api/types.ts | 57 ++--------- .../WorkflowRunDetails/WorkflowRunDetails.tsx | 96 ------------------- .../WorkflowRunDetails/useWorkflowRunJobs.ts | 8 +- .../src/components/useWorkflowRuns.ts | 2 +- 6 files changed, 18 insertions(+), 159 deletions(-) diff --git a/plugins/cloudbuild/src/api/CloudbuildApi.ts b/plugins/cloudbuild/src/api/CloudbuildApi.ts index a340246348..e9760677fb 100644 --- a/plugins/cloudbuild/src/api/CloudbuildApi.ts +++ b/plugins/cloudbuild/src/api/CloudbuildApi.ts @@ -18,7 +18,6 @@ import { createApiRef } from '@backstage/core'; import { ActionsListWorkflowRunsForRepoResponseData, ActionsGetWorkflowResponseData, - ActionsGetWorkflowRunResponseData, } from '../api/types'; export const cloudbuildApiRef = createApiRef({ @@ -51,7 +50,7 @@ export type CloudbuildApi = { token: string; projectId: string; id: string; - }) => Promise; + }) => Promise; reRunWorkflow: ({ token, projectId, diff --git a/plugins/cloudbuild/src/api/CloudbuildClient.ts b/plugins/cloudbuild/src/api/CloudbuildClient.ts index f2fedecacd..4219ecabc1 100644 --- a/plugins/cloudbuild/src/api/CloudbuildClient.ts +++ b/plugins/cloudbuild/src/api/CloudbuildClient.ts @@ -18,8 +18,7 @@ import { CloudbuildApi } from './CloudbuildApi'; import { ActionsListWorkflowRunsForRepoResponseData, ActionsGetWorkflowResponseData, - ActionsGetWorkflowRunResponseData, - Build, + Builds, } from '../api/types'; export class CloudbuildClient implements CloudbuildApi { @@ -59,11 +58,11 @@ export class CloudbuildClient implements CloudbuildApi { }, ); - const builds: Build[] = await workflowRuns.json(); + const builds: Builds = await workflowRuns.json(); const response: ActionsListWorkflowRunsForRepoResponseData = { - total_count: builds.length, - builds: builds, + total_count: builds.builds.length, + builds: builds.builds, }; return response; @@ -99,7 +98,7 @@ export class CloudbuildClient implements CloudbuildApi { token: string; projectId: string; id: string; - }): Promise { + }): Promise { const workflow = await fetch( `https://cloudbuild.googleapis.com/v1/projects/${projectId}/builds/${id}`, { diff --git a/plugins/cloudbuild/src/api/types.ts b/plugins/cloudbuild/src/api/types.ts index f3072bb98d..bcbde4df66 100644 --- a/plugins/cloudbuild/src/api/types.ts +++ b/plugins/cloudbuild/src/api/types.ts @@ -14,61 +14,16 @@ * limitations under the License. */ -export interface Build { - id: string; - status: string; - source: Source; - createTime: string; - startTime: string; - steps: Step[]; - timeout: string; - projectId: string; - logsBucket: string; - sourceProvenance: SourceProvenance; - buildTriggerId: string; - options: Options; - logUrl: string; - substitutions: Substitutions; - tags: string[]; - queueTtl: string; - name: string; - finishTime: any; - results: Results; - timing: Timing2; -} - -export type Jobs = { - total_count: number; - jobs: Build[]; -}; - export interface ActionsListWorkflowRunsForRepoResponseData { total_count: number; - builds: Build[]; + builds: ActionsGetWorkflowResponseData[]; } -export type ActionsGetWorkflowResponseData = { - id: string; - status: string; - source: Source; - createTime: string; - startTime: string; - steps: Step[]; - timeout: string; - projectId: string; - logsBucket: string; - sourceProvenance: SourceProvenance; - buildTriggerId: string; - options: Options; - logUrl: string; - substitutions: Substitutions; - tags: string[]; - queueTtl: string; - name: string; - finishTime: any; - results: Results; - timing: Timing2; + +export type Builds = { + builds: ActionsGetWorkflowResponseData[]; }; -export type ActionsGetWorkflowRunResponseData = { + +export type ActionsGetWorkflowResponseData = { id: string; status: string; source: Source; diff --git a/plugins/cloudbuild/src/components/WorkflowRunDetails/WorkflowRunDetails.tsx b/plugins/cloudbuild/src/components/WorkflowRunDetails/WorkflowRunDetails.tsx index 55623162e4..d3484ba707 100644 --- a/plugins/cloudbuild/src/components/WorkflowRunDetails/WorkflowRunDetails.tsx +++ b/plugins/cloudbuild/src/components/WorkflowRunDetails/WorkflowRunDetails.tsx @@ -60,97 +60,11 @@ const useStyles = makeStyles(theme => ({ }, })); -// const JobsList = ({ jobs, entity }: { jobs?: Jobs; entity: Entity }) => { -// const classes = useStyles(); -// return ( -// -// {jobs && -// jobs.total_count > 0 && -// jobs.jobs.map((job: Build) => ( -// -// ))} -// -// ); -// }; - -// const getElapsedTime = (start: string, end: string) => { -// const diff = moment(moment(end || moment()).diff(moment(start))); -// const timeElapsed = diff.format('m [minutes] s [seconds]'); -// return timeElapsed; -// }; - -// const StepView = ({ step }: { step: Step }) => { -// return ( -// -// -// -// -// -// -// -// -// ); -// }; - -// const JobListItem = ({ -// job, -// className, -// entity, -// }: { -// job: Build; -// className: string; -// entity: Entity; -// }) => { -// const classes = useStyles(); -// return ( -// -// } -// aria-controls={`panel-${name}-content`} -// id={`panel-${name}-header`} -// IconButtonProps={{ -// className: classes.button, -// }} -// > -// -// {job.name} ({getElapsedTime(job.startTime, job.finishTime)}) -// -// -// -// -// -// {job.steps.map((step: Step) => ( -// -// ))} -//
-//
-//
-// {job.status === 'QUEUED' || job.status === 'WORKING' ? ( -// -// ) : ( -// -// )} -//
-// ); -// }; - export const WorkflowRunDetails = ({ entity }: { entity: Entity }) => { - // const projectName = useProjectName(entity); const { value: projectName, loading, error } = useProjectName(entity); const [projectId] = (projectName ?? '/').split('/'); - // const [projectId] = projectName.value ? projectName.value : []; const details = useWorkflowRunsDetails(projectId); - // const steps = useWorkflowRunJobs(projectId) const classes = useStyles(); if (error) { @@ -216,16 +130,6 @@ export const WorkflowRunDetails = ({ entity }: { entity: Entity }) => { )} - {/* - - Jobs - {loading ? ( - - ) : ( - - )} - - */} diff --git a/plugins/cloudbuild/src/components/WorkflowRunDetails/useWorkflowRunJobs.ts b/plugins/cloudbuild/src/components/WorkflowRunDetails/useWorkflowRunJobs.ts index f471ce1875..2c3df61abe 100644 --- a/plugins/cloudbuild/src/components/WorkflowRunDetails/useWorkflowRunJobs.ts +++ b/plugins/cloudbuild/src/components/WorkflowRunDetails/useWorkflowRunJobs.ts @@ -14,14 +14,16 @@ * limitations under the License. */ import { useAsync } from 'react-use'; -import { Jobs } from '../../api/types'; +import { ActionsListWorkflowRunsForRepoResponseData } from '../../api/types'; export const useWorkflowRunJobs = (jobsUrl?: string) => { - const jobs = useAsync(async (): Promise => { + const jobs = useAsync(async (): Promise< + ActionsListWorkflowRunsForRepoResponseData + > => { if (jobsUrl === undefined) { return { total_count: 0, - jobs: [], + builds: [], }; } diff --git a/plugins/cloudbuild/src/components/useWorkflowRuns.ts b/plugins/cloudbuild/src/components/useWorkflowRuns.ts index 6e20ebbff1..bc887f9a1a 100644 --- a/plugins/cloudbuild/src/components/useWorkflowRuns.ts +++ b/plugins/cloudbuild/src/components/useWorkflowRuns.ts @@ -46,7 +46,7 @@ export function useWorkflowRuns({ projectId }: { projectId: string }) { ): WorkflowRun[] => { setTotal(workflowRunsData.total_count); // Transformation here - return workflowRunsData.builds.builds.map(run => ({ + return workflowRunsData.builds.map(run => ({ message: run.substitutions.REPO_NAME, id: `${run.id}`, onReRunClick: async () => {