feat: retry
This commit is contained in:
@@ -93,6 +93,10 @@ export class CircleCIApi {
|
||||
return new CircleCI({ ...this.options, token: this.token });
|
||||
}
|
||||
|
||||
async retry(buildId: string) {
|
||||
return this.api.retry(Number(buildId));
|
||||
}
|
||||
|
||||
async getBuilds() {
|
||||
return this.api.builds();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,15 @@ import TableCell from '@material-ui/core/TableCell';
|
||||
import TableContainer from '@material-ui/core/TableContainer';
|
||||
import TableHead from '@material-ui/core/TableHead';
|
||||
import TableRow from '@material-ui/core/TableRow';
|
||||
import Button from '@material-ui/core/Button';
|
||||
import {
|
||||
StatusRunning,
|
||||
StatusFailed,
|
||||
StatusOK,
|
||||
StatusPending,
|
||||
StatusNA,
|
||||
} from '@backstage/core';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
table: {
|
||||
minWidth: 650,
|
||||
@@ -36,7 +45,25 @@ export type CITableBuildInfo = {
|
||||
failed: number;
|
||||
testUrl: string; //fixme better name
|
||||
};
|
||||
onRetriggerClick: () => void;
|
||||
onRetryClick: () => void;
|
||||
};
|
||||
|
||||
// :retried, :canceled, :infrastructure_fail, :timedout, :not_run, :running, :failed, :queued, :scheduled, :not_running, :no_tests, :fixed, :success
|
||||
const getStatusComponent = (status: string) => {
|
||||
switch (status.toLowerCase()) {
|
||||
case 'queued':
|
||||
case 'scheduled':
|
||||
return <StatusPending />;
|
||||
case 'running':
|
||||
return <StatusRunning />;
|
||||
case 'failed':
|
||||
return <StatusFailed />;
|
||||
case 'success':
|
||||
return <StatusOK />;
|
||||
case 'canceled':
|
||||
default:
|
||||
return <StatusNA />;
|
||||
}
|
||||
};
|
||||
|
||||
export const CITable: FC<{
|
||||
@@ -54,7 +81,7 @@ export const CITable: FC<{
|
||||
<TableCell>Source</TableCell>
|
||||
<TableCell>Status</TableCell>
|
||||
<TableCell>Tests</TableCell>
|
||||
<TableCell>Retrigger</TableCell>
|
||||
<TableCell>Actions</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
@@ -68,7 +95,7 @@ export const CITable: FC<{
|
||||
<div>{build.source.commit.hash}</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>{build.status}</TableCell>
|
||||
<TableCell>{getStatusComponent(build.status)}</TableCell>
|
||||
<TableCell>
|
||||
{build.tests && (
|
||||
<>
|
||||
@@ -78,7 +105,9 @@ export const CITable: FC<{
|
||||
</>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>Retrigger</TableCell>
|
||||
<TableCell>
|
||||
<Button onClick={build.onRetryClick}>Retry</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
|
||||
@@ -47,12 +47,15 @@ const makeReadableStatus = (status: string | undefined) => {
|
||||
} as Record<string, string>)[status];
|
||||
};
|
||||
|
||||
const transform = (buildsData: BuildSummary[]): CITableBuildInfo[] => {
|
||||
const transform = (
|
||||
buildsData: BuildSummary[],
|
||||
api: typeof circleCIApiRef.T,
|
||||
): CITableBuildInfo[] => {
|
||||
return buildsData.map(buildData => {
|
||||
const tableBuildInfo: CITableBuildInfo = {
|
||||
id: String(buildData.build_num),
|
||||
buildName: buildData.subject ? String(buildData.subject) : '',
|
||||
onRetriggerClick: () => null,
|
||||
onRetryClick: () => api.retry(String(buildData.build_num)),
|
||||
source: {
|
||||
branchName: String(buildData.branch),
|
||||
commit: {
|
||||
@@ -73,7 +76,6 @@ const transform = (buildsData: BuildSummary[]): CITableBuildInfo[] => {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
export const CircleCIFetch: FC<{}> = () => {
|
||||
const [authed, setAuthed] = React.useState(false);
|
||||
const [builds, setBuilds] = React.useState<BuildSummary[]>([]);
|
||||
@@ -96,8 +98,14 @@ export const CircleCIFetch: FC<{}> = () => {
|
||||
}, [authed]);
|
||||
|
||||
if (!authed) return <div>Not authenticated</div>;
|
||||
const transformedBuilds = transform(builds || []);
|
||||
return <>
|
||||
|
||||
{!api.authed ? <div>Not authenticated</div> : <CITable builds={transformedBuilds} />}</>;
|
||||
const transformedBuilds = transform(builds || [], api);
|
||||
return (
|
||||
<>
|
||||
{!api.authed ? (
|
||||
<div>Not authenticated</div>
|
||||
) : (
|
||||
<CITable builds={transformedBuilds} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user