From 661e2d7db6bcc9fbe78626c69e5402f438a6bf81 Mon Sep 17 00:00:00 2001 From: Vardan Bansal Date: Thu, 7 Sep 2023 17:05:47 -0700 Subject: [PATCH] Create pipeline execution api update --- .../RunPipelineModal/RunPipelineModal.tsx | 16 +++++--- web/src/services/code/index.tsx | 39 ++++++++++++------- web/src/services/code/swagger.yaml | 35 ++++++++++------- 3 files changed, 56 insertions(+), 34 deletions(-) diff --git a/web/src/components/RunPipelineModal/RunPipelineModal.tsx b/web/src/components/RunPipelineModal/RunPipelineModal.tsx index 6cc83013b..2349d3c95 100644 --- a/web/src/components/RunPipelineModal/RunPipelineModal.tsx +++ b/web/src/components/RunPipelineModal/RunPipelineModal.tsx @@ -14,7 +14,7 @@ import { } from '@harnessio/uicore' import { useStrings } from 'framework/strings' import { useModalHook } from 'hooks/useModalHook' -import type { OpenapiCreateExecutionRequest, TypesExecution, TypesRepository } from 'services/code' +import type { CreateExecutionQueryParams, TypesExecution, TypesRepository } from 'services/code' import { useMutate } from 'restful-react' import { getErrorMessage } from 'utils/Utils' import { useHistory } from 'react-router' @@ -38,12 +38,16 @@ const useRunPipelineModal = () => { path: `/api/v1/repos/${repoPath}/+/pipelines/${pipeline}/executions` }) - const runPipeline = (_formData: FormData): void => { + const runPipeline = (formData: FormData): void => { + const { branch } = formData try { - const payload: OpenapiCreateExecutionRequest = { - status: '' - } - startExecution(payload, { pathParams: { path: `/api/v1/repos/${repoPath}/+/pipelines/${pipeline}/executions` } }) + startExecution( + {}, + { + pathParams: { path: `/api/v1/repos/${repoPath}/+/pipelines/${pipeline}/executions` }, + queryParams: { branch } as CreateExecutionQueryParams + } + ) .then(() => { history.push(routes.toCODEExecutions({ repoPath, pipeline })) hideModal() diff --git a/web/src/services/code/index.tsx b/web/src/services/code/index.tsx index 57d954a64..21f27d384 100644 --- a/web/src/services/code/index.tsx +++ b/web/src/services/code/index.tsx @@ -108,6 +108,12 @@ export interface GitrpcSignature { when?: string } +export interface LivelogLine { + out?: string + pos?: number + time?: number +} + export interface OpenapiAdminUsersCreateRequest { display_name?: string email?: string @@ -179,10 +185,6 @@ export interface OpenapiCreateConnectorRequest { uid?: string } -export interface OpenapiCreateExecutionRequest { - status?: string -} - export interface OpenapiCreatePathRequest { path?: string } @@ -790,7 +792,7 @@ export interface TypesSpace { export interface TypesStage { arch?: string - depends_on?: string[] | null + depends_on?: string[] errignore?: boolean error?: string execution_id?: number @@ -807,6 +809,7 @@ export interface TypesStage { on_failure?: boolean on_success?: boolean os?: string + repo_id?: number started?: number status?: string steps?: TypesStep[] @@ -817,7 +820,7 @@ export interface TypesStage { } export interface TypesStep { - depends_on?: string[] | null + depends_on?: string[] detached?: boolean errignore?: boolean error?: string @@ -2459,19 +2462,26 @@ export const useListExecutions = ({ repo_ref, pipeline_uid, ...props }: UseListE { base: getConfig('code/api/v1'), pathParams: { repo_ref, pipeline_uid }, ...props } ) +export interface CreateExecutionQueryParams { + /** + * Branch to run the execution for. + */ + branch?: string +} + export interface CreateExecutionPathParams { repo_ref: string pipeline_uid: string } export type CreateExecutionProps = Omit< - MutateProps, + MutateProps, 'path' | 'verb' > & CreateExecutionPathParams export const CreateExecution = ({ repo_ref, pipeline_uid, ...props }: CreateExecutionProps) => ( - + verb="POST" path={`/repos/${repo_ref}/pipelines/${pipeline_uid}/executions`} base={getConfig('code/api/v1')} @@ -2480,13 +2490,13 @@ export const CreateExecution = ({ repo_ref, pipeline_uid, ...props }: CreateExec ) export type UseCreateExecutionProps = Omit< - UseMutateProps, + UseMutateProps, 'path' | 'verb' > & CreateExecutionPathParams export const useCreateExecution = ({ repo_ref, pipeline_uid, ...props }: UseCreateExecutionProps) => - useMutate( + useMutate( 'POST', (paramsInPath: CreateExecutionPathParams) => `/repos/${paramsInPath.repo_ref}/pipelines/${paramsInPath.pipeline_uid}/executions`, @@ -2600,7 +2610,8 @@ export interface ViewLogsPathParams { step_number: string } -export type ViewLogsProps = Omit, 'path'> & ViewLogsPathParams +export type ViewLogsProps = Omit, 'path'> & + ViewLogsPathParams export const ViewLogs = ({ repo_ref, @@ -2610,14 +2621,14 @@ export const ViewLogs = ({ step_number, ...props }: ViewLogsProps) => ( - + path={`/repos/${repo_ref}/pipelines/${pipeline_uid}/executions/${execution_number}/logs/${stage_number}/${step_number}`} base={getConfig('code/api/v1')} {...props} /> ) -export type UseViewLogsProps = Omit, 'path'> & +export type UseViewLogsProps = Omit, 'path'> & ViewLogsPathParams export const useViewLogs = ({ @@ -2628,7 +2639,7 @@ export const useViewLogs = ({ step_number, ...props }: UseViewLogsProps) => - useGet( + useGet( (paramsInPath: ViewLogsPathParams) => `/repos/${paramsInPath.repo_ref}/pipelines/${paramsInPath.pipeline_uid}/executions/${paramsInPath.execution_number}/logs/${paramsInPath.stage_number}/${paramsInPath.step_number}`, { diff --git a/web/src/services/code/swagger.yaml b/web/src/services/code/swagger.yaml index 84eb98c18..bcf65cb46 100644 --- a/web/src/services/code/swagger.yaml +++ b/web/src/services/code/swagger.yaml @@ -2294,6 +2294,12 @@ paths: post: operationId: createExecution parameters: + - description: Branch to run the execution for. + in: query + name: branch + required: false + schema: + type: string - in: path name: repo_ref required: true @@ -2304,11 +2310,6 @@ paths: required: true schema: type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/OpenapiCreateExecutionRequest' responses: '201': content: @@ -2535,9 +2536,11 @@ paths: responses: '200': content: - text/plain: + application/json: schema: - type: string + items: + $ref: '#/components/schemas/LivelogLine' + type: array description: OK '401': content: @@ -6370,6 +6373,15 @@ components: format: date-time type: string type: object + LivelogLine: + properties: + out: + type: string + pos: + type: integer + time: + type: integer + type: object OpenapiAdminUsersCreateRequest: properties: display_name: @@ -6497,11 +6509,6 @@ components: uid: type: string type: object - OpenapiCreateExecutionRequest: - properties: - status: - type: string - type: object OpenapiCreatePathRequest: properties: path: @@ -7539,7 +7546,6 @@ components: depends_on: items: type: string - nullable: true type: array errignore: type: boolean @@ -7571,6 +7577,8 @@ components: type: boolean os: type: string + repo_id: + type: integer started: type: integer status: @@ -7593,7 +7601,6 @@ components: depends_on: items: type: string - nullable: true type: array detached: type: boolean