feat(pipeline-tasks): 提交日志动作面板。

This commit is contained in:
Ivan Li 2021-03-15 13:29:48 +08:00
parent 11221ae8dd
commit 32421599ea
6 changed files with 594 additions and 33 deletions

View File

@ -606,6 +606,324 @@
"enumValues": null, "enumValues": null,
"possibleTypes": null "possibleTypes": null
}, },
{
"kind": "OBJECT",
"name": "PipelineTaskLogs",
"description": null,
"fields": [
{
"name": "unit",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "PipelineUnits",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "status",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "PipelineUnits",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "startedAt",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "DateTime",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "endedAt",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "DateTime",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "logs",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "SCALAR",
"name": "DateTime",
"description": "A date-time string at UTC, such as 2019-12-03T09:54:33Z, compliant with the date-time format.",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "PipelineTask",
"description": null,
"fields": [
{
"name": "id",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "pipeline",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "Pipeline",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "pipelineId",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "commit",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "units",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "PipelineUnits",
"ofType": null
}
}
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "logs",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "PipelineTaskLogs",
"ofType": null
}
}
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "status",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "TaskStatuses",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "startedAt",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "DateTime",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "endedAt",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "DateTime",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "ENUM",
"name": "TaskStatuses",
"description": "任务状态",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": [
{
"name": "success",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "failed",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "working",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "pending",
"description": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "PipelineTaskLogMessage",
"description": null,
"fields": [
{
"name": "unit",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "PipelineUnits",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{ {
"kind": "INPUT_OBJECT", "kind": "INPUT_OBJECT",
"name": "WorkUnitInput", "name": "WorkUnitInput",
@ -1092,6 +1410,39 @@
}, },
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
},
{
"name": "createPipelineTask",
"description": null,
"args": [
{
"name": "task",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "CreatePipelineTaskInput",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "PipelineTask",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
} }
], ],
"inputFields": null, "inputFields": null,
@ -1415,6 +1766,73 @@
"enumValues": null, "enumValues": null,
"possibleTypes": null "possibleTypes": null
}, },
{
"kind": "INPUT_OBJECT",
"name": "CreatePipelineTaskInput",
"description": null,
"fields": null,
"inputFields": [
{
"name": "pipelineId",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "commit",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "units",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "PipelineUnits",
"ofType": null
}
}
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{ {
"kind": "OBJECT", "kind": "OBJECT",
"name": "Subscription", "name": "Subscription",
@ -1452,6 +1870,39 @@
}, },
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
},
{
"name": "pipelineTaskLog",
"description": null,
"args": [
{
"name": "taskId",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "PipelineTaskLogMessage",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
} }
], ],
"inputFields": null, "inputFields": null,

View File

@ -4,7 +4,11 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { makeAutoObservable } from 'mobx'; import { makeAutoObservable } from 'mobx';
import { ActionButton } from './action-button'; import { ActionButton } from './action-button';
import { gql, useMutation } from '@apollo/client'; import { gql, useMutation } from '@apollo/client';
import { Project, Pipeline } from '../../generated/graphql'; import {
Project,
Pipeline,
CreatePipelineTaskInput
} from '../../generated/graphql';
import { import {
CommitActionsStoreProvider, CommitActionsStoreProvider,
CommitActionsStore CommitActionsStore
@ -16,12 +20,24 @@ import {
faVial faVial
} from '@fortawesome/free-solid-svg-icons'; } from '@fortawesome/free-solid-svg-icons';
import { useLocalObservable } from 'mobx-react'; import { useLocalObservable } from 'mobx-react';
import { PipelineTask, PipelineUnits } from '../../generated/graphql';
const CHECKOUT = ''; const CREATE_PIPELINE_TASK = gql`
mutation CreatePipelineTask($task: CreatePipelineTaskInput!) {
pipelineTask: createPipelineTask(task: $task) {
id
units
commit
status
startedAt
endedAt
}
}
`;
interface Props { interface Props {
pipeline: Pipeline; pipeline: Pipeline;
commitNumber: string; commit: string;
branch?: string; branch?: string;
} }
@ -32,13 +48,16 @@ class Store {
isTasksWorking = [false, false, false, false]; isTasksWorking = [false, false, false, false];
} }
export const CommitActions = ({ pipeline, commitNumber }: Props) => { export const CommitActions = ({ pipeline, commit }: Props) => {
const [checkout] = useMutation<CheckoutInput>(CHECKOUT); const [createTask] = useMutation<
PipelineTask,
{ task: CreatePipelineTaskInput }
>(CREATE_PIPELINE_TASK);
const onCheckoutBtnClick = async () => { const doWork = async (units: PipelineUnits[]) => {
await checkout({ await createTask({
variables: { variables: {
input: { projectId: project.id, commitNumber } as CheckoutInput task: { pipelineId: pipeline.id, commit, units }
} }
}); });
}; };
@ -47,16 +66,42 @@ export const CommitActions = ({ pipeline, commitNumber }: Props) => {
return ( return (
<section className={[styles.component, 'commit-actions'].join(' ')}> <section className={[styles.component, 'commit-actions'].join(' ')}>
<CommitActionsStoreProvider value={commitActionsStore}> <CommitActionsStoreProvider value={commitActionsStore}>
<ActionButton onClick={onCheckoutBtnClick}> <ActionButton onClick={() => doWork([PipelineUnits.Checkout])}>
<FontAwesomeIcon icon={faDownload}></FontAwesomeIcon> <FontAwesomeIcon icon={faDownload}></FontAwesomeIcon>
</ActionButton> </ActionButton>
<ActionButton> <ActionButton
onClick={() =>
doWork([
PipelineUnits.Checkout,
PipelineUnits.InstallDependencies,
PipelineUnits.CleanUp
])
}
>
<FontAwesomeIcon icon={faCloudDownloadAlt}></FontAwesomeIcon> <FontAwesomeIcon icon={faCloudDownloadAlt}></FontAwesomeIcon>
</ActionButton> </ActionButton>
<ActionButton> <ActionButton
onClick={() =>
doWork([
PipelineUnits.Checkout,
PipelineUnits.InstallDependencies,
PipelineUnits.Test,
PipelineUnits.CleanUp
])
}
>
<FontAwesomeIcon icon={faVial}></FontAwesomeIcon> <FontAwesomeIcon icon={faVial}></FontAwesomeIcon>
</ActionButton> </ActionButton>
<ActionButton> <ActionButton
onClick={() =>
doWork([
PipelineUnits.Checkout,
PipelineUnits.InstallDependencies,
PipelineUnits.Test,
PipelineUnits.Deploy
])
}
>
<FontAwesomeIcon icon={faGlobeAsia}></FontAwesomeIcon> <FontAwesomeIcon icon={faGlobeAsia}></FontAwesomeIcon>
</ActionButton> </ActionButton>
</CommitActionsStoreProvider> </CommitActionsStoreProvider>

View File

@ -8,6 +8,7 @@ import { h } from 'preact';
import { gql, useQuery, useSubscription } from '@apollo/client'; import { gql, useQuery, useSubscription } from '@apollo/client';
import styles from './commit-log-list.scss'; import styles from './commit-log-list.scss';
import { CommitActions } from '../commit-actions/commit-actions'; import { CommitActions } from '../commit-actions/commit-actions';
import { FIND_PIPELINE } from '../pipelines/pipeline-list.constants';
const LIST_LOGS = gql` const LIST_LOGS = gql`
subscription listLogsForPipeline($id: String!) { subscription listLogsForPipeline($id: String!) {
@ -28,7 +29,6 @@ interface Props {
} }
export const CommitLogList = ({ pipelineId }: Props) => { export const CommitLogList = ({ pipelineId }: Props) => {
console.log(pipelineId);
const { data, loading } = useSubscription< const { data, loading } = useSubscription<
{ listLogs: LogList }, { listLogs: LogList },
{ id: string } { id: string }
@ -37,13 +37,18 @@ export const CommitLogList = ({ pipelineId }: Props) => {
id: pipelineId! id: pipelineId!
} }
}); });
const queryResult = useQuery<{ pipeline: Pipeline }>(FIND_PIPELINE, {
variables: { id: pipelineId }
});
const pipeline = queryResult.data?.pipeline;
const list = data?.listLogs?.all?.map(log => { const list = data?.listLogs?.all?.map(log => {
return ( return (
<li className={styles.item} key={log.hash}> <li className={styles.item} key={log.hash}>
<h4>{log.message}</h4> <h4>{log.message}</h4>
<time dateTime={log.date}>{log.date}</time> <time dateTime={log.date}>{log.date}</time>
{/* <CommitActions pipeline={pipeline} commitNumber={log.hash} /> */} {pipeline ? (
<CommitActions pipeline={pipeline} commit={log.hash} />
) : null}
</li> </li>
); );
}); });

View File

@ -10,3 +10,21 @@ export const LIST_PIPELINES = gql`
} }
} }
`; `;
export const FIND_PIPELINE = gql`
query FindPipeline($id: String!) {
pipeline: findPipeline(id: $id) {
id
name
branch
projectId
workUnitMetadata {
version
units {
type
scripts
}
}
}
}
`;

View File

@ -10,6 +10,8 @@ export type Scalars = {
Boolean: boolean; Boolean: boolean;
Int: number; Int: number;
Float: number; Float: number;
/** A date-time string at UTC, such as 2019-12-03T09:54:33Z, compliant with the date-time format. */
DateTime: any;
}; };
export type Hello = { export type Hello = {
@ -76,6 +78,42 @@ export type LogList = {
latest: LogFields; latest: LogFields;
}; };
export type PipelineTaskLogs = {
__typename?: 'PipelineTaskLogs';
unit: PipelineUnits;
status: PipelineUnits;
startedAt?: Maybe<Scalars['DateTime']>;
endedAt?: Maybe<Scalars['DateTime']>;
logs: Scalars['String'];
};
export type PipelineTask = {
__typename?: 'PipelineTask';
id: Scalars['ID'];
pipeline: Pipeline;
pipelineId: Scalars['String'];
commit: Scalars['String'];
units: Array<PipelineUnits>;
logs: Array<PipelineTaskLogs>;
status: TaskStatuses;
startedAt?: Maybe<Scalars['DateTime']>;
endedAt?: Maybe<Scalars['DateTime']>;
};
/** 任务状态 */
export enum TaskStatuses {
Success = 'success',
Failed = 'failed',
Working = 'working',
Pending = 'pending'
}
export type PipelineTaskLogMessage = {
__typename?: 'PipelineTaskLogMessage';
unit: PipelineUnits;
};
export type WorkUnitInput = { export type WorkUnitInput = {
type: PipelineUnits; type: PipelineUnits;
scripts: Array<Scalars['String']>; scripts: Array<Scalars['String']>;
@ -118,6 +156,7 @@ export type Mutation = {
createPipeline: Pipeline; createPipeline: Pipeline;
modifyPipeline: Pipeline; modifyPipeline: Pipeline;
deletePipeline: Scalars['Float']; deletePipeline: Scalars['Float'];
createPipelineTask: PipelineTask;
}; };
@ -152,6 +191,11 @@ export type MutationDeletePipelineArgs = {
id: Scalars['String']; id: Scalars['String'];
}; };
export type MutationCreatePipelineTaskArgs = {
task: CreatePipelineTaskInput;
};
export type CreateProjectInput = { export type CreateProjectInput = {
name: Scalars['String']; name: Scalars['String'];
comment: Scalars['String']; comment: Scalars['String'];
@ -182,12 +226,24 @@ export type UpdatePipelineInput = {
workUnitMetadata: WorkUnitMetadataInput; workUnitMetadata: WorkUnitMetadataInput;
}; };
export type CreatePipelineTaskInput = {
pipelineId: Scalars['String'];
commit: Scalars['String'];
units: Array<PipelineUnits>;
};
export type Subscription = { export type Subscription = {
__typename?: 'Subscription'; __typename?: 'Subscription';
listLogsForPipeline: LogList; listLogsForPipeline: LogList;
pipelineTaskLog: PipelineTaskLogMessage;
}; };
export type SubscriptionListLogsForPipelineArgs = { export type SubscriptionListLogsForPipelineArgs = {
id: Scalars['String']; id: Scalars['String'];
}; };
export type SubscriptionPipelineTaskLogArgs = {
taskId: Scalars['String'];
};

View File

@ -14,7 +14,10 @@ import {
Pipeline Pipeline
} from '../../generated/graphql'; } from '../../generated/graphql';
import { Message } from '../../components/commons/message/index'; import { Message } from '../../components/commons/message/index';
import { LIST_PIPELINES } from '../../components/pipelines/pipeline-list.constants'; import {
FIND_PIPELINE,
LIST_PIPELINES
} from '../../components/pipelines/pipeline-list.constants';
const defaultWorkUnitMetadata: WorkUnitMetadata = { const defaultWorkUnitMetadata: WorkUnitMetadata = {
version: 1, version: 1,
@ -38,23 +41,6 @@ const defaultWorkUnitMetadata: WorkUnitMetadata = {
] ]
}; };
const FIND_PIPELINE = gql`
query FindPipeline($id: String!) {
pipeline: findPipeline(id: $id) {
name
branch
projectId
workUnitMetadata {
version
units {
type
scripts
}
}
}
}
`;
const CREATE_PIPELINE = gql` const CREATE_PIPELINE = gql`
mutation CreatePipeline($input: CreatePipelineInput!) { mutation CreatePipeline($input: CreatePipelineInput!) {
pipeline: createPipeline(pipeline: $input) { pipeline: createPipeline(pipeline: $input) {