Skip to content

Commit

Permalink
Merge pull request #57 from xuzhu-591/feat-approval
Browse files Browse the repository at this point in the history
feat: support checks for rollback and restart
  • Loading branch information
xuzhu-591 authored Dec 11, 2023
2 parents e2919ab + 3ccc661 commit db60605
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 50 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"lint:style": "stylelint --fix \"src/**/*.less\" --syntax less",
"prettier": "prettier -c --write \"src/**/*\"",
"start": "cross-env UMI_ENV=dev umi dev",
"start:new": "cross-env NODE_OPTIONS=--openssl-legacy-provider UMI_ENV=dev umi dev",
"start:dev": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=dev MOCK=true UMI_ENV=dev umi dev",
"start:no-mock": "cross-env MOCK=none UMI_ENV=dev umi dev",
"start:no-ui": "cross-env UMI_UI=none UMI_ENV=dev umi dev",
Expand Down
2 changes: 2 additions & 0 deletions src/const.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export enum ResourceType {
export enum PublishType {
BUILD_DEPLOY = 'builddeploy',
DEPLOY = 'deploy',
RESTART = 'restart',
ROLLBACK = 'rollback',
}

export enum MemberType {
Expand Down
10 changes: 6 additions & 4 deletions src/pages/instances/Detail/v1/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ export default () => {
templateSchema={templateSchema}
cluster={cluster}
/>
<AdminTag
clusterID={clusterID}
clusterFullPath={clusterFullPath}
/>
</TabPane>
<TabPane tab={intl.formatMessage({ id: 'pages.clusterDetail.output' })} key="2">
<Output clusterID={clusterID} />
Expand All @@ -79,6 +75,12 @@ export default () => {
clusterFullPath={clusterFullPath}
/>
</TabPane>
<TabPane tab={intl.formatMessage({ id: 'pages.tags.admin' })} key="4">
<AdminTag
clusterID={clusterID}
clusterFullPath={clusterFullPath}
/>
</TabPane>
</Tabs>
</PageWithBreadcrumb>
);
Expand Down
10 changes: 6 additions & 4 deletions src/pages/instances/Detail/v2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ export default () => {
templateSchema={templateSchema}
buildSchema={buildSchema}
/>
<AdminTag
clusterID={clusterID}
clusterFullPath={clusterFullPath}
/>
</TabPane>
<TabPane tab={intl.formatMessage({ id: 'pages.clusterDetail.output' })} key="2">
<Output clusterID={clusterID} />
Expand All @@ -120,6 +116,12 @@ export default () => {
clusterFullPath={clusterFullPath}
/>
</TabPane>
<TabPane tab={intl.formatMessage({ id: 'pages.tags.admin' })} key="4">
<AdminTag
clusterID={clusterID}
clusterFullPath={clusterFullPath}
/>
</TabPane>
</Tabs>
</MaxSpace>
</PageWithBreadcrumb>
Expand Down
17 changes: 12 additions & 5 deletions src/pages/instances/Pods/components/ButtonBar.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions src/pages/instances/Pods/components/ButtonBarV2.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 26 additions & 18 deletions src/pages/instances/pipelines/Detail/MergeBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,17 @@ const Status = (props: StatusProps) => {

interface ConfirmButtonProps extends Omit<ButtonProps, 'type'> {
pipelinerunID: number;
pipelinerunAction: string;
forceRun: boolean;
}

const ConfirmButton = (props: ConfirmButtonProps) => {
const { pipelinerunID, forceRun: forceRunFlag, disabled } = props;
const {
pipelinerunID, pipelinerunAction, forceRun: forceRunFlag, disabled,
} = props;
const intl = useIntl();
const history = useHistory();
const { successAlert } = useModel('alert');
const { initialState } = useModel('@@initialState');
const { fullPath } = initialState?.resource || {};

Expand All @@ -109,32 +113,35 @@ const ConfirmButton = (props: ConfirmButtonProps) => {
};
}, [forceRunFlag, intl, disabled]);

const { run } = useRequest(() => runPipelineRun(pipelinerunID), {
onSuccess: () => {
history.push(`${fullPath}`);
},
manual: true,
});
const doRun = useCallback(() => {
if (forceRunFlag) {
return forceRunPipelineRun(pipelinerunID);
}
return runPipelineRun(pipelinerunID);
}, [forceRunFlag, pipelinerunID]);

const { run: forceRun } = useRequest(() => forceRunPipelineRun(pipelinerunID), {
const { run, loading } = useRequest(() => doRun(), {
onSuccess: () => {
switch (pipelinerunAction) {
case 'restart':
successAlert(intl.formatMessage({ id: 'pages.message.cluster.restart.success' }));
break;
case 'rollback':
successAlert(intl.formatMessage({ id: 'pages.message.cluster.rollback.submitted' }));
break;
default:
break;
}
history.push(`${fullPath}`);
},
manual: true,
});

const onClick = useCallback(() => {
if (forceRunFlag) {
forceRun();
} else {
run();
}
}, [forceRunFlag, forceRun, run]);

return (
<Button
type="primary"
onClick={onClick}
loading={loading}
onClick={run}
style={{ backgroundColor: params.color, borderColor: params.color }}
{...props}
>
Expand Down Expand Up @@ -233,7 +240,7 @@ const CheckRunItem = (props: { checkrun: PIPELINES.CheckRun }) => {
};

const MergeBox = (props: { pipelinerun: PIPELINES.Pipeline, checkruns?: PIPELINES.CheckRun[] }) => {
const { pipelinerun: { status, id }, checkruns = [] } = props;
const { pipelinerun: { status, id, action }, checkruns = [] } = props;
const needButton = useMemo(() => status === 'ready' || status === 'pending', [status]);
return (
<Row>
Expand All @@ -249,6 +256,7 @@ const MergeBox = (props: { pipelinerun: PIPELINES.Pipeline, checkruns?: PIPELINE
<ConfirmButton
forceRun={status === 'pending' && rbac.Permissions.forceRunPipelineRun.allowed}
pipelinerunID={id}
pipelinerunAction={action}
disabled={status === 'pending' && !rbac.Permissions.forceRunPipelineRun.allowed}
/>
<CancelButton pipelinerunID={id} />
Expand Down
30 changes: 18 additions & 12 deletions src/pages/instances/pipelines/Detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { useParams } from 'umi';
import { useRequest } from '@@/plugin-request/request';
import copy from 'copy-to-clipboard';
import { useMemo, useState } from 'react';
import {
Button, Card, Modal,
} from 'antd';
import { Button, Card, Modal } from 'antd';
import { CopyOutlined, FullscreenOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
import PageWithBreadcrumb from '@/components/PageWithBreadcrumb';
import type { Param } from '@/components/DetailCard';
Expand All @@ -29,7 +27,7 @@ import {
import Utils from '@/utils';
import { PublishType } from '@/const';
import FullscreenModal from '@/components/FullscreenModal';
import { rollback } from '@/services/clusters/clusters';
import { createPipelineRun } from '@/services/clusters/clusters';
import { GitRefType } from '@/services/code/code';
import ButtonWithoutPadding from '@/components/Widget/ButtonWithoutPadding';
import MergeBox from './MergeBox';
Expand All @@ -49,15 +47,21 @@ export default (props: any) => {
const { initialState } = useModel('@@initialState');
const { id, fullPath } = initialState!.resource;

const pollingInterval = 6000;
const pollingInterval = 3000;

const { data: pipeline } = useRequest(() => getPipeline(pipelineID), {
const { data: checkruns, cancel: cancelListCheckRuns } = useRequest(() => listCheckRuns(pipelineID), {
pollingInterval,
pollingWhenHidden: false,
});
const { data: checkruns } = useRequest(() => listCheckRuns(pipelineID), {
const { data: pipeline, cancel: cancelGetPipeline } = useRequest(() => getPipeline(pipelineID), {
pollingInterval,
pollingWhenHidden: false,
onSuccess: (data) => {
if (data?.status && data?.status !== 'pending') {
cancelListCheckRuns();
cancelGetPipeline();
}
},
});
const { data: diff } = useRequest(() => getPipelineDiffs(pipelineID));
const { data: buildLog } = useRequest(() => queryPipelineLog(pipelineID), {
Expand Down Expand Up @@ -160,11 +164,13 @@ export default (props: any) => {
setFullscreen(true);
};

const { run: runRollback, loading } = useRequest((prID: number) => rollback(id, { pipelinerunID: prID }), {
onSuccess: () => {
// jump to pods' url
successAlert(intl.formatMessage({ id: 'pages.message.cluster.rollback.submitted' }));
history.push(`${fullPath}`);
const { run: runRollback, loading } = useRequest((prID: number) => createPipelineRun(id, {
action: 'rollback',
pipelinerunID: prID,
}), {
onSuccess: (pr: PIPELINES.Pipeline) => {
history.push(`/instances${fullPath}/-/pipelines/${pr.id}`);
window.location.reload();
},
manual: true,
});
Expand Down
4 changes: 2 additions & 2 deletions src/services/clusters.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ declare namespace CLUSTER {
};

type PipelineRunCreate = {
action: 'builddeploy' | 'deploy' | 'rollback'
title: string,
action: 'builddeploy' | 'deploy' | 'rollback' | 'restart'
title?: string,
description?: string;
git?: {
branch: string;
Expand Down

0 comments on commit db60605

Please sign in to comment.