Removed unused types

This commit is contained in:
ebarrios
2020-09-18 10:50:50 +02:00
parent d139cf6a28
commit 0d1695715e
8 changed files with 5 additions and 306 deletions
@@ -19,7 +19,6 @@ import {
ActionsListWorkflowRunsForRepoResponseData,
ActionsGetWorkflowResponseData,
ActionsGetWorkflowRunResponseData,
EndpointInterface,
} from '../api/types';
export const cloudbuildApiRef = createApiRef<CloudbuildApi>({
@@ -62,13 +61,4 @@ export type CloudbuildApi = {
projectId: string;
runId: string;
}) => Promise<any>;
downloadJobLogsForWorkflowRun: ({
token,
projectId,
runId,
}: {
token: string;
projectId: string;
runId: string;
}) => Promise<EndpointInterface>;
};
+2 -20
View File
@@ -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<EndpointInterface> {
// console.log("Token: ",token," projectId: ", projectId," runId: ",runId)
// const workflow = await new Octokit({
// auth: token,
// }).actions.downloadJobLogsForWorkflowRun({
// owner,
// repo,
// job_id: runId,
// });
return [];
}
}
+1 -49
View File
@@ -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;
@@ -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<Theme>(() => ({
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 (
<Suspense fallback={<LinearProgress />}>
<div className={className}>
<LazyLog
text={jobLogs ?? 'No Values Found'}
extraLines={1}
caseInsensitive
enableSearch
formatPart={line => {
if (
line.toLocaleLowerCase().includes('error') ||
line.toLocaleLowerCase().includes('failed') ||
line.toLocaleLowerCase().includes('failure')
) {
return (
<LinePart style={{ color: 'red' }} part={{ text: line }} />
);
}
return line;
}}
/>
</div>
</Suspense>
);
};
/**
* 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 (
<Accordion TransitionProps={{ unmountOnExit: true }} disabled={inProgress}>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls={`panel-${name}-content`}
id={`panel-${name}-header`}
IconButtonProps={{
className: classes.button,
}}
>
<Typography variant="button">
{jobLogs.loading ? <CircularProgress /> : 'Job Log'}
</Typography>
<Tooltip title="Open Log" TransitionComponent={Zoom} arrow>
<DescriptionIcon
onClick={event => {
event.stopPropagation();
handleOpen();
}}
style={{ marginLeft: 'auto' }}
/>
</Tooltip>
<Modal
className={classes.modal}
onClick={event => event.stopPropagation()}
open={open}
onClose={handleClose}
>
<Fade in={open}>
<DisplayLog
jobLogs={jobLogs.value || undefined}
className={classes.modalLog}
/>
</Fade>
</Modal>
</AccordionSummary>
{jobLogs.value && (
<DisplayLog
jobLogs={jobLogs.value || undefined}
className={classes.normalLog}
/>
)}
</Accordion>
);
};
@@ -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';
@@ -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;
};
@@ -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}
</Link>
),
},
@@ -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,
}));
},