From 32421599eaa935b3bb48ede7850e0ce2bdf2c3dd Mon Sep 17 00:00:00 2001 From: Ivan Li Date: Mon, 15 Mar 2021 13:29:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(pipeline-tasks):=20=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=8A=A8=E4=BD=9C=E9=9D=A2=E6=9D=BF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- graphql.schema.json | 451 ++++++++++++++++++ .../commit-actions/commit-actions.tsx | 69 ++- .../commit-logs/commit-log-list.tsx | 11 +- .../pipelines/pipeline-list.constants.ts | 18 + src/generated/graphql.tsx | 56 +++ src/routes/pipelines/pipeline-editor.tsx | 22 +- 6 files changed, 594 insertions(+), 33 deletions(-) diff --git a/graphql.schema.json b/graphql.schema.json index 0a32f57..26fd76e 100644 --- a/graphql.schema.json +++ b/graphql.schema.json @@ -606,6 +606,324 @@ "enumValues": 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", "name": "WorkUnitInput", @@ -1092,6 +1410,39 @@ }, "isDeprecated": false, "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, @@ -1415,6 +1766,73 @@ "enumValues": 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", "name": "Subscription", @@ -1452,6 +1870,39 @@ }, "isDeprecated": false, "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, diff --git a/src/components/commit-actions/commit-actions.tsx b/src/components/commit-actions/commit-actions.tsx index 4ce0b3b..8c149e4 100644 --- a/src/components/commit-actions/commit-actions.tsx +++ b/src/components/commit-actions/commit-actions.tsx @@ -4,7 +4,11 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { makeAutoObservable } from 'mobx'; import { ActionButton } from './action-button'; import { gql, useMutation } from '@apollo/client'; -import { Project, Pipeline } from '../../generated/graphql'; +import { + Project, + Pipeline, + CreatePipelineTaskInput +} from '../../generated/graphql'; import { CommitActionsStoreProvider, CommitActionsStore @@ -16,12 +20,24 @@ import { faVial } from '@fortawesome/free-solid-svg-icons'; 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 { pipeline: Pipeline; - commitNumber: string; + commit: string; branch?: string; } @@ -32,13 +48,16 @@ class Store { isTasksWorking = [false, false, false, false]; } -export const CommitActions = ({ pipeline, commitNumber }: Props) => { - const [checkout] = useMutation(CHECKOUT); +export const CommitActions = ({ pipeline, commit }: Props) => { + const [createTask] = useMutation< + PipelineTask, + { task: CreatePipelineTaskInput } + >(CREATE_PIPELINE_TASK); - const onCheckoutBtnClick = async () => { - await checkout({ + const doWork = async (units: PipelineUnits[]) => { + await createTask({ 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 (
- + doWork([PipelineUnits.Checkout])}> - + + doWork([ + PipelineUnits.Checkout, + PipelineUnits.InstallDependencies, + PipelineUnits.CleanUp + ]) + } + > - + + doWork([ + PipelineUnits.Checkout, + PipelineUnits.InstallDependencies, + PipelineUnits.Test, + PipelineUnits.CleanUp + ]) + } + > - + + doWork([ + PipelineUnits.Checkout, + PipelineUnits.InstallDependencies, + PipelineUnits.Test, + PipelineUnits.Deploy + ]) + } + > diff --git a/src/components/commit-logs/commit-log-list.tsx b/src/components/commit-logs/commit-log-list.tsx index acc9c79..bbf74c8 100644 --- a/src/components/commit-logs/commit-log-list.tsx +++ b/src/components/commit-logs/commit-log-list.tsx @@ -8,6 +8,7 @@ import { h } from 'preact'; import { gql, useQuery, useSubscription } from '@apollo/client'; import styles from './commit-log-list.scss'; import { CommitActions } from '../commit-actions/commit-actions'; +import { FIND_PIPELINE } from '../pipelines/pipeline-list.constants'; const LIST_LOGS = gql` subscription listLogsForPipeline($id: String!) { @@ -28,7 +29,6 @@ interface Props { } export const CommitLogList = ({ pipelineId }: Props) => { - console.log(pipelineId); const { data, loading } = useSubscription< { listLogs: LogList }, { id: string } @@ -37,13 +37,18 @@ export const CommitLogList = ({ pipelineId }: Props) => { id: pipelineId! } }); - + const queryResult = useQuery<{ pipeline: Pipeline }>(FIND_PIPELINE, { + variables: { id: pipelineId } + }); + const pipeline = queryResult.data?.pipeline; const list = data?.listLogs?.all?.map(log => { return (
  • {log.message}

    - {/* */} + {pipeline ? ( + + ) : null}
  • ); }); diff --git a/src/components/pipelines/pipeline-list.constants.ts b/src/components/pipelines/pipeline-list.constants.ts index 317ea3f..b4e6e68 100644 --- a/src/components/pipelines/pipeline-list.constants.ts +++ b/src/components/pipelines/pipeline-list.constants.ts @@ -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 + } + } + } + } +`; diff --git a/src/generated/graphql.tsx b/src/generated/graphql.tsx index a8a264c..26bf553 100644 --- a/src/generated/graphql.tsx +++ b/src/generated/graphql.tsx @@ -10,6 +10,8 @@ export type Scalars = { Boolean: boolean; Int: 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 = { @@ -76,6 +78,42 @@ export type LogList = { latest: LogFields; }; +export type PipelineTaskLogs = { + __typename?: 'PipelineTaskLogs'; + unit: PipelineUnits; + status: PipelineUnits; + startedAt?: Maybe; + endedAt?: Maybe; + logs: Scalars['String']; +}; + + +export type PipelineTask = { + __typename?: 'PipelineTask'; + id: Scalars['ID']; + pipeline: Pipeline; + pipelineId: Scalars['String']; + commit: Scalars['String']; + units: Array; + logs: Array; + status: TaskStatuses; + startedAt?: Maybe; + endedAt?: Maybe; +}; + +/** 任务状态 */ +export enum TaskStatuses { + Success = 'success', + Failed = 'failed', + Working = 'working', + Pending = 'pending' +} + +export type PipelineTaskLogMessage = { + __typename?: 'PipelineTaskLogMessage'; + unit: PipelineUnits; +}; + export type WorkUnitInput = { type: PipelineUnits; scripts: Array; @@ -118,6 +156,7 @@ export type Mutation = { createPipeline: Pipeline; modifyPipeline: Pipeline; deletePipeline: Scalars['Float']; + createPipelineTask: PipelineTask; }; @@ -152,6 +191,11 @@ export type MutationDeletePipelineArgs = { id: Scalars['String']; }; + +export type MutationCreatePipelineTaskArgs = { + task: CreatePipelineTaskInput; +}; + export type CreateProjectInput = { name: Scalars['String']; comment: Scalars['String']; @@ -182,12 +226,24 @@ export type UpdatePipelineInput = { workUnitMetadata: WorkUnitMetadataInput; }; +export type CreatePipelineTaskInput = { + pipelineId: Scalars['String']; + commit: Scalars['String']; + units: Array; +}; + export type Subscription = { __typename?: 'Subscription'; listLogsForPipeline: LogList; + pipelineTaskLog: PipelineTaskLogMessage; }; export type SubscriptionListLogsForPipelineArgs = { id: Scalars['String']; }; + + +export type SubscriptionPipelineTaskLogArgs = { + taskId: Scalars['String']; +}; diff --git a/src/routes/pipelines/pipeline-editor.tsx b/src/routes/pipelines/pipeline-editor.tsx index ec98ab1..538ce33 100644 --- a/src/routes/pipelines/pipeline-editor.tsx +++ b/src/routes/pipelines/pipeline-editor.tsx @@ -14,7 +14,10 @@ import { Pipeline } from '../../generated/graphql'; 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 = { 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` mutation CreatePipeline($input: CreatePipelineInput!) { pipeline: createPipeline(pipeline: $input) {