From 0d1695715e2e71df085bf29317706f5cfd0f9644 Mon Sep 17 00:00:00 2001 From: ebarrios Date: Fri, 18 Sep 2020 10:50:50 +0200 Subject: [PATCH] Removed unused types --- plugins/cloudbuild/src/api/CloudbuildApi.ts | 10 -- .../cloudbuild/src/api/CloudbuildClient.ts | 22 +-- plugins/cloudbuild/src/api/types.ts | 50 +----- .../WorkflowRunLogs/WorkflowRunLogs.tsx | 169 ------------------ .../src/components/WorkflowRunLogs/index.ts | 16 -- .../useDownloadWorkflowRunLogs.ts | 38 ---- .../WorkflowRunsTable/WorkflowRunsTable.tsx | 3 +- .../src/components/useWorkflowRuns.ts | 3 +- 8 files changed, 5 insertions(+), 306 deletions(-) delete mode 100644 plugins/cloudbuild/src/components/WorkflowRunLogs/WorkflowRunLogs.tsx delete mode 100644 plugins/cloudbuild/src/components/WorkflowRunLogs/index.ts delete mode 100644 plugins/cloudbuild/src/components/WorkflowRunLogs/useDownloadWorkflowRunLogs.ts diff --git a/plugins/cloudbuild/src/api/CloudbuildApi.ts b/plugins/cloudbuild/src/api/CloudbuildApi.ts index d5f5448b59..a340246348 100644 --- a/plugins/cloudbuild/src/api/CloudbuildApi.ts +++ b/plugins/cloudbuild/src/api/CloudbuildApi.ts @@ -19,7 +19,6 @@ import { ActionsListWorkflowRunsForRepoResponseData, ActionsGetWorkflowResponseData, ActionsGetWorkflowRunResponseData, - EndpointInterface, } from '../api/types'; export const cloudbuildApiRef = createApiRef({ @@ -62,13 +61,4 @@ export type CloudbuildApi = { projectId: string; runId: string; }) => Promise; - downloadJobLogsForWorkflowRun: ({ - token, - projectId, - runId, - }: { - token: string; - projectId: string; - runId: string; - }) => Promise; }; diff --git a/plugins/cloudbuild/src/api/CloudbuildClient.ts b/plugins/cloudbuild/src/api/CloudbuildClient.ts index 4e27eddd76..f2fedecacd 100644 --- a/plugins/cloudbuild/src/api/CloudbuildClient.ts +++ b/plugins/cloudbuild/src/api/CloudbuildClient.ts @@ -19,7 +19,6 @@ import { ActionsListWorkflowRunsForRepoResponseData, ActionsGetWorkflowResponseData, ActionsGetWorkflowRunResponseData, - EndpointInterface, Build, } from '../api/types'; @@ -59,11 +58,12 @@ export class CloudbuildClient implements CloudbuildApi { }), }, ); + const builds: Build[] = await workflowRuns.json(); const response: ActionsListWorkflowRunsForRepoResponseData = { total_count: builds.length, - workflow_runs: builds, + builds: builds, }; return response; @@ -113,22 +113,4 @@ export class CloudbuildClient implements CloudbuildApi { return build; } - async downloadJobLogsForWorkflowRun({}: // token, - // projectId, - // runId, - { - // token: string; - // projectId: string; - // runId: string; - }): Promise { - // console.log("Token: ",token," projectId: ", projectId," runId: ",runId) - // const workflow = await new Octokit({ - // auth: token, - // }).actions.downloadJobLogsForWorkflowRun({ - // owner, - // repo, - // job_id: runId, - // }); - return []; - } } diff --git a/plugins/cloudbuild/src/api/types.ts b/plugins/cloudbuild/src/api/types.ts index 74ac89ee11..f3072bb98d 100644 --- a/plugins/cloudbuild/src/api/types.ts +++ b/plugins/cloudbuild/src/api/types.ts @@ -14,25 +14,6 @@ * limitations under the License. */ -// export type Step = { -// name: string; -// status: string; -// conclusion: string; -// number: number; // starts from 1 -// started_at: string; -// completed_at: string; -// }; - -// export type Job = { -// html_url: string; -// status: string; -// conclusion: string; -// started_at: string; -// completed_at: string; -// id: string; -// name: string; -// steps: Step[]; -// }; export interface Build { id: string; status: string; @@ -61,37 +42,9 @@ export type Jobs = { jobs: Build[]; }; -// export enum BuildStatus { -// 'success', -// 'failure', -// 'pending', -// 'running', -// } - export interface ActionsListWorkflowRunsForRepoResponseData { total_count: number; - workflow_runs: { - 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; - }[]; + builds: Build[]; } export type ActionsGetWorkflowResponseData = { id: string; @@ -137,7 +90,6 @@ export type ActionsGetWorkflowRunResponseData = { results: Results; timing: Timing2; }; -export type EndpointInterface = {}; export interface Step { name: string; diff --git a/plugins/cloudbuild/src/components/WorkflowRunLogs/WorkflowRunLogs.tsx b/plugins/cloudbuild/src/components/WorkflowRunLogs/WorkflowRunLogs.tsx deleted file mode 100644 index 36abf8180e..0000000000 --- a/plugins/cloudbuild/src/components/WorkflowRunLogs/WorkflowRunLogs.tsx +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { - Accordion, - AccordionSummary, - CircularProgress, - Fade, - LinearProgress, - makeStyles, - Modal, - Theme, - Tooltip, - Typography, - Zoom, -} from '@material-ui/core'; - -import React, { Suspense } from 'react'; -import { useDownloadWorkflowRunLogs } from './useDownloadWorkflowRunLogs'; -import LinePart from 'react-lazylog/build/LinePart'; -import { useProjectName } from '../useProjectName'; -import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; -import DescriptionIcon from '@material-ui/icons/Description'; -import { Entity } from '@backstage/catalog-model'; - -const LazyLog = React.lazy(() => import('react-lazylog/build/LazyLog')); - -const useStyles = makeStyles(() => ({ - button: { - order: -1, - marginRight: 0, - marginLeft: '-20px', - }, - modal: { - display: 'flex', - alignItems: 'center', - width: '85%', - height: '85%', - justifyContent: 'center', - margin: 'auto', - }, - normalLog: { - height: '75vh', - width: '100%', - }, - modalLog: { - height: '100%', - width: '100%', - }, -})); - -const DisplayLog = ({ - jobLogs, - className, -}: { - jobLogs: any; - className: string; -}) => { - return ( - }> -
- { - if ( - line.toLocaleLowerCase().includes('error') || - line.toLocaleLowerCase().includes('failed') || - line.toLocaleLowerCase().includes('failure') - ) { - return ( - - ); - } - return line; - }} - /> -
-
- ); -}; - -/** - * A component for Run Logs visualization. - */ -export const WorkflowRunLogs = ({ - entity, - runId, - inProgress, -}: { - entity: Entity; - runId: string; - inProgress: boolean; -}) => { - const classes = useStyles(); - const projectName = useProjectName(entity); - - const repo = projectName.value || ''; - const jobLogs = useDownloadWorkflowRunLogs(repo, runId); - const [open, setOpen] = React.useState(false); - - const handleOpen = () => { - setOpen(true); - }; - - const handleClose = () => { - setOpen(false); - }; - - return ( - - } - aria-controls={`panel-${name}-content`} - id={`panel-${name}-header`} - IconButtonProps={{ - className: classes.button, - }} - > - - {jobLogs.loading ? : 'Job Log'} - - - { - event.stopPropagation(); - handleOpen(); - }} - style={{ marginLeft: 'auto' }} - /> - - event.stopPropagation()} - open={open} - onClose={handleClose} - > - - - - - - {jobLogs.value && ( - - )} - - ); -}; diff --git a/plugins/cloudbuild/src/components/WorkflowRunLogs/index.ts b/plugins/cloudbuild/src/components/WorkflowRunLogs/index.ts deleted file mode 100644 index 0fcffd4dec..0000000000 --- a/plugins/cloudbuild/src/components/WorkflowRunLogs/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -export { WorkflowRunLogs } from './WorkflowRunLogs'; diff --git a/plugins/cloudbuild/src/components/WorkflowRunLogs/useDownloadWorkflowRunLogs.ts b/plugins/cloudbuild/src/components/WorkflowRunLogs/useDownloadWorkflowRunLogs.ts deleted file mode 100644 index 98ff3a974e..0000000000 --- a/plugins/cloudbuild/src/components/WorkflowRunLogs/useDownloadWorkflowRunLogs.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { useApi, googleAuthApiRef } from '@backstage/core'; -import { useAsync } from 'react-use'; -import { cloudbuildApiRef } from '../../api'; - -export const useDownloadWorkflowRunLogs = (projectId: string, id: string) => { - const api = useApi(cloudbuildApiRef); - const auth = useApi(googleAuthApiRef); - const details = useAsync(async () => { - const token = await auth.getAccessToken([ - 'https://www.googleapis.com/auth/cloud-platform', - ]); - const runId = id; - return projectId - ? api.downloadJobLogsForWorkflowRun({ - token, - projectId, - runId, - }) - : Promise.reject('No repo/owner provided'); - }, [projectId, id]); - return details; -}; diff --git a/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx b/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx index a97bec3650..7c361f7fc4 100644 --- a/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx +++ b/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx @@ -35,7 +35,6 @@ export type WorkflowRun = { status: string; substitutions: Substitutions; createTime: string; - org: string; onReRunClick: () => void; }; @@ -73,7 +72,7 @@ const generatedColumns: TableColumn[] = [ // to={`https://www.github.com/trivago/${row.message}`} to={generatePath(buildRouteRef.path, { id: row.id! })} > - {row.org}/{row.message} + {row.message} ), }, diff --git a/plugins/cloudbuild/src/components/useWorkflowRuns.ts b/plugins/cloudbuild/src/components/useWorkflowRuns.ts index 7e6affb137..6e20ebbff1 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.workflow_runs.builds.map(run => ({ + return workflowRunsData.builds.builds.map(run => ({ message: run.substitutions.REPO_NAME, id: `${run.id}`, onReRunClick: async () => { @@ -71,7 +71,6 @@ export function useWorkflowRuns({ projectId }: { projectId: string }) { status: run.status, url: run.logUrl, googleUrl: run.logUrl, - org: 'trivago', createTime: run.createTime, })); },