Create pipeline execution api update

This commit is contained in:
Vardan Bansal 2023-09-07 17:05:47 -07:00
parent 0d46d2a587
commit 661e2d7db6
3 changed files with 56 additions and 34 deletions

View File

@ -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()

View File

@ -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<TypesExecution, UsererrorError, void, OpenapiCreateExecutionRequest, CreateExecutionPathParams>,
MutateProps<TypesExecution, UsererrorError, CreateExecutionQueryParams, void, CreateExecutionPathParams>,
'path' | 'verb'
> &
CreateExecutionPathParams
export const CreateExecution = ({ repo_ref, pipeline_uid, ...props }: CreateExecutionProps) => (
<Mutate<TypesExecution, UsererrorError, void, OpenapiCreateExecutionRequest, CreateExecutionPathParams>
<Mutate<TypesExecution, UsererrorError, CreateExecutionQueryParams, void, CreateExecutionPathParams>
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<TypesExecution, UsererrorError, void, OpenapiCreateExecutionRequest, CreateExecutionPathParams>,
UseMutateProps<TypesExecution, UsererrorError, CreateExecutionQueryParams, void, CreateExecutionPathParams>,
'path' | 'verb'
> &
CreateExecutionPathParams
export const useCreateExecution = ({ repo_ref, pipeline_uid, ...props }: UseCreateExecutionProps) =>
useMutate<TypesExecution, UsererrorError, void, OpenapiCreateExecutionRequest, CreateExecutionPathParams>(
useMutate<TypesExecution, UsererrorError, CreateExecutionQueryParams, void, CreateExecutionPathParams>(
'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<GetProps<void, UsererrorError, void, ViewLogsPathParams>, 'path'> & ViewLogsPathParams
export type ViewLogsProps = Omit<GetProps<LivelogLine[], UsererrorError, void, ViewLogsPathParams>, 'path'> &
ViewLogsPathParams
export const ViewLogs = ({
repo_ref,
@ -2610,14 +2621,14 @@ export const ViewLogs = ({
step_number,
...props
}: ViewLogsProps) => (
<Get<void, UsererrorError, void, ViewLogsPathParams>
<Get<LivelogLine[], UsererrorError, void, ViewLogsPathParams>
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<UseGetProps<void, UsererrorError, void, ViewLogsPathParams>, 'path'> &
export type UseViewLogsProps = Omit<UseGetProps<LivelogLine[], UsererrorError, void, ViewLogsPathParams>, 'path'> &
ViewLogsPathParams
export const useViewLogs = ({
@ -2628,7 +2639,7 @@ export const useViewLogs = ({
step_number,
...props
}: UseViewLogsProps) =>
useGet<void, UsererrorError, void, ViewLogsPathParams>(
useGet<LivelogLine[], UsererrorError, void, ViewLogsPathParams>(
(paramsInPath: ViewLogsPathParams) =>
`/repos/${paramsInPath.repo_ref}/pipelines/${paramsInPath.pipeline_uid}/executions/${paramsInPath.execution_number}/logs/${paramsInPath.stage_number}/${paramsInPath.step_number}`,
{

View File

@ -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