From d4d74f0f448cd0f0efb3722dbfd53454ed8dd565 Mon Sep 17 00:00:00 2001 From: Johannes Batzill Date: Wed, 11 Jan 2023 17:41:01 -0800 Subject: [PATCH] [SWAGGER] update swagger with latest webhook changes and re-render web services (#184) --- internal/api/openapi/webhook.go | 6 +- .../pages/PullRequest/PullRequestMetaLine.tsx | 6 +- web/src/services/code/index.tsx | 173 +++++++++++- web/src/services/code/swagger.yaml | 262 +++++++++++++++++- 4 files changed, 421 insertions(+), 26 deletions(-) diff --git a/internal/api/openapi/webhook.go b/internal/api/openapi/webhook.go index 35d3a8a6d..aec5dff7d 100644 --- a/internal/api/openapi/webhook.go +++ b/internal/api/openapi/webhook.go @@ -38,8 +38,10 @@ func (webhookParent) Enum() []interface{} { // webhookType is used to overshadow fields Parent & Triggers of types.Webhook. type webhookType struct { types.Webhook - ParentType webhookParent `json:"parent_type"` - Triggers []webhookTrigger `json:"triggers"` + ParentType webhookParent `json:"parent_type"` + Triggers []webhookTrigger `json:"triggers"` + LatestExecutionResult *webhookExecutionResult `json:"latest_execution_result,omitempty"` + HasSecret bool `json:"has_secret"` } type createWebhookRequest struct { diff --git a/web/src/pages/PullRequest/PullRequestMetaLine.tsx b/web/src/pages/PullRequest/PullRequestMetaLine.tsx index f46b83162..ba85491c6 100644 --- a/web/src/pages/PullRequest/PullRequestMetaLine.tsx +++ b/web/src/pages/PullRequest/PullRequestMetaLine.tsx @@ -15,14 +15,14 @@ export const PullRequestMetaLine: React.FC { const { getString } = useStrings() const { routes } = useAppContext() const vars = { - user: {author?.name}, + user: {author?.display_name}, number: 5, // TODO: No data from backend now target: ( - + diff --git a/web/src/services/code/index.tsx b/web/src/services/code/index.tsx index 05e00b354..6b8b6dee3 100644 --- a/web/src/services/code/index.tsx +++ b/web/src/services/code/index.tsx @@ -7,6 +7,8 @@ import { getConfig } from '../config' export const SPEC_VERSION = '1.0.0' export type EnumAccessGrant = number +export type EnumMergeMethod = string + export type EnumParentResourceType = string export type EnumPathTargetType = string @@ -19,7 +21,7 @@ export type EnumPullReqState = string export type EnumTokenType = string -export type EnumWebhookExecutionResult = string +export type EnumWebhookExecutionResult = string | null export type EnumWebhookParent = string @@ -114,6 +116,8 @@ export interface OpenapiCreateSpaceRequest { } export interface OpenapiCreateWebhookRequest { + description?: string + display_name?: string enabled?: boolean insecure?: boolean secret?: string @@ -134,6 +138,12 @@ export interface OpenapiGetContentOutput { type?: OpenapiContentType } +export interface OpenapiMergePullReq { + delete_branch?: boolean + force?: boolean + method?: EnumMergeMethod +} + export interface OpenapiMoveRepoRequest { keep_as_alias?: boolean parent_id?: number | null @@ -146,6 +156,15 @@ export interface OpenapiMoveSpaceRequest { uid?: string | null } +export interface OpenapiReviewSubmitPullReqRequest { + decision?: string + message?: string +} + +export interface OpenapiReviewerAddPullReqRequest { + reviewer_id?: number +} + export interface OpenapiUpdatePullReqRequest { description?: string title?: string @@ -162,6 +181,8 @@ export interface OpenapiUpdateSpaceRequest { } export interface OpenapiUpdateWebhookRequest { + description?: string | null + display_name?: string | null enabled?: boolean | null insecure?: boolean | null secret?: string | null @@ -169,7 +190,7 @@ export interface OpenapiUpdateWebhookRequest { url?: string | null } -export type OpenapiWebhookExecutionResult = 'success' | 'retriable_error' | 'fatal_error' +export type OpenapiWebhookExecutionResult = 'success' | 'retriable_error' | 'fatal_error' | null export interface OpenapiWebhookExecutionType { created?: number @@ -192,9 +213,13 @@ export type OpenapiWebhookTrigger = 'branch_created' | 'branch_updated' | 'branc export interface OpenapiWebhookType { created?: number created_by?: number + description?: string + display_name?: string enabled?: boolean + has_secret?: boolean id?: number insecure?: boolean + latest_execution_result?: OpenapiWebhookExecutionResult parent_id?: number parent_type?: OpenapiWebhookParent triggers?: OpenapiWebhookTrigger[] | null @@ -314,7 +339,7 @@ export interface TypesPullReq { description?: string edited?: number id?: number - merge_strategy?: string | null + merge_strategy?: EnumMergeMethod merged?: number | null merger?: TypesPrincipalInfo number?: number @@ -324,8 +349,6 @@ export interface TypesPullReq { target_branch?: string target_repo_id?: number title?: string - updated?: number - version?: number } export interface TypesPullReqActivity { @@ -346,8 +369,6 @@ export interface TypesPullReqActivity { sub_order?: number text?: string type?: EnumPullReqActivityType - updated?: number - version?: number } export interface TypesRepository { @@ -435,8 +456,8 @@ export interface TypesWebhookExecutionRequest { export interface TypesWebhookExecutionResponse { body?: string headers?: string - status?: number - status_code?: string + status?: string + status_code?: number } export interface UserUpdateInput { @@ -1445,6 +1466,140 @@ export const useCommentUpdatePullReq = ({ { base: getConfig('code'), pathParams: { repo_ref, pullreq_number, pullreq_comment_id }, ...props } ) +export interface MergePullReqOpPathParams { + repo_ref: string + pullreq_number: number +} + +export type MergePullReqOpProps = Omit< + MutateProps, + 'path' | 'verb' +> & + MergePullReqOpPathParams + +export const MergePullReqOp = ({ repo_ref, pullreq_number, ...props }: MergePullReqOpProps) => ( + + verb="POST" + path={`/repos/${repo_ref}/pullreq/${pullreq_number}/merge`} + base={getConfig('code')} + {...props} + /> +) + +export type UseMergePullReqOpProps = Omit< + UseMutateProps, + 'path' | 'verb' +> & + MergePullReqOpPathParams + +export const useMergePullReqOp = ({ repo_ref, pullreq_number, ...props }: UseMergePullReqOpProps) => + useMutate( + 'POST', + (paramsInPath: MergePullReqOpPathParams) => + `/repos/${paramsInPath.repo_ref}/pullreq/${paramsInPath.pullreq_number}/merge`, + { base: getConfig('code'), pathParams: { repo_ref, pullreq_number }, ...props } + ) + +export interface ReviewSubmitPullReqPathParams { + repo_ref: string + pullreq_number: number +} + +export type ReviewSubmitPullReqProps = Omit< + MutateProps, + 'path' | 'verb' +> & + ReviewSubmitPullReqPathParams + +export const ReviewSubmitPullReq = ({ repo_ref, pullreq_number, ...props }: ReviewSubmitPullReqProps) => ( + + verb="POST" + path={`/repos/${repo_ref}/pullreq/${pullreq_number}/review`} + base={getConfig('code')} + {...props} + /> +) + +export type UseReviewSubmitPullReqProps = Omit< + UseMutateProps, + 'path' | 'verb' +> & + ReviewSubmitPullReqPathParams + +export const useReviewSubmitPullReq = ({ repo_ref, pullreq_number, ...props }: UseReviewSubmitPullReqProps) => + useMutate( + 'POST', + (paramsInPath: ReviewSubmitPullReqPathParams) => + `/repos/${paramsInPath.repo_ref}/pullreq/${paramsInPath.pullreq_number}/review`, + { base: getConfig('code'), pathParams: { repo_ref, pullreq_number }, ...props } + ) + +export interface ReviewerListPullReqPathParams { + repo_ref: string + pullreq_number: number +} + +export type ReviewerListPullReqProps = Omit< + GetProps, + 'path' +> & + ReviewerListPullReqPathParams + +export const ReviewerListPullReq = ({ repo_ref, pullreq_number, ...props }: ReviewerListPullReqProps) => ( + + path={`/repos/${repo_ref}/pullreq/${pullreq_number}/reviewers`} + base={getConfig('code')} + {...props} + /> +) + +export type UseReviewerListPullReqProps = Omit< + UseGetProps, + 'path' +> & + ReviewerListPullReqPathParams + +export const useReviewerListPullReq = ({ repo_ref, pullreq_number, ...props }: UseReviewerListPullReqProps) => + useGet( + (paramsInPath: ReviewerListPullReqPathParams) => + `/repos/${paramsInPath.repo_ref}/pullreq/${paramsInPath.pullreq_number}/reviewers`, + { base: getConfig('code'), pathParams: { repo_ref, pullreq_number }, ...props } + ) + +export interface ReviewerAddPullReqPathParams { + repo_ref: string + pullreq_number: number +} + +export type ReviewerAddPullReqProps = Omit< + MutateProps, + 'path' | 'verb' +> & + ReviewerAddPullReqPathParams + +export const ReviewerAddPullReq = ({ repo_ref, pullreq_number, ...props }: ReviewerAddPullReqProps) => ( + + verb="PUT" + path={`/repos/${repo_ref}/pullreq/${pullreq_number}/reviewers`} + base={getConfig('code')} + {...props} + /> +) + +export type UseReviewerAddPullReqProps = Omit< + UseMutateProps, + 'path' | 'verb' +> & + ReviewerAddPullReqPathParams + +export const useReviewerAddPullReq = ({ repo_ref, pullreq_number, ...props }: UseReviewerAddPullReqProps) => + useMutate( + 'PUT', + (paramsInPath: ReviewerAddPullReqPathParams) => + `/repos/${paramsInPath.repo_ref}/pullreq/${paramsInPath.pullreq_number}/reviewers`, + { base: getConfig('code'), pathParams: { repo_ref, pullreq_number }, ...props } + ) + export interface ListRepositoryServiceAccountsPathParams { repo_ref: string } diff --git a/web/src/services/code/swagger.yaml b/web/src/services/code/swagger.yaml index 157d98804..d54dbfb87 100644 --- a/web/src/services/code/swagger.yaml +++ b/web/src/services/code/swagger.yaml @@ -1440,6 +1440,210 @@ paths: description: Internal Server Error tags: - pullreq + /repos/{repo_ref}/pullreq/{pullreq_number}/merge: + post: + operationId: mergePullReqOp + parameters: + - in: path + name: repo_ref + required: true + schema: + type: string + - in: path + name: pullreq_number + required: true + schema: + type: integer + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/OpenapiMergePullReq' + responses: + '200': + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Bad Request + '401': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Unauthorized + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Forbidden + '404': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Not Found + '405': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Method Not Allowed + '409': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Conflict + '422': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Unprocessable Entity + tags: + - pullreq + /repos/{repo_ref}/pullreq/{pullreq_number}/review: + post: + operationId: reviewSubmitPullReq + parameters: + - in: path + name: repo_ref + required: true + schema: + type: string + - in: path + name: pullreq_number + required: true + schema: + type: integer + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/OpenapiReviewSubmitPullReqRequest' + responses: + '204': + description: No Content + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Bad Request + '401': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Unauthorized + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Forbidden + '500': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Internal Server Error + tags: + - pullreq + /repos/{repo_ref}/pullreq/{pullreq_number}/reviewers: + get: + operationId: reviewerListPullReq + parameters: + - in: path + name: repo_ref + required: true + schema: + type: string + - in: path + name: pullreq_number + required: true + schema: + type: integer + responses: + '204': + description: No Content + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Bad Request + '401': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Unauthorized + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Forbidden + '500': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Internal Server Error + tags: + - pullreq + put: + operationId: reviewerAddPullReq + parameters: + - in: path + name: repo_ref + required: true + schema: + type: string + - in: path + name: pullreq_number + required: true + schema: + type: integer + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/OpenapiReviewerAddPullReqRequest' + responses: + '204': + description: No Content + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Bad Request + '401': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Unauthorized + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Forbidden + '500': + content: + application/json: + schema: + $ref: '#/components/schemas/UsererrorError' + description: Internal Server Error + tags: + - pullreq /repos/{repo_ref}/service-accounts: get: operationId: listRepositoryServiceAccounts @@ -2844,6 +3048,8 @@ components: schemas: EnumAccessGrant: type: integer + EnumMergeMethod: + type: string EnumParentResourceType: type: string EnumPathTargetType: @@ -2857,6 +3063,7 @@ components: EnumTokenType: type: string EnumWebhookExecutionResult: + nullable: true type: string EnumWebhookParent: type: string @@ -3021,6 +3228,10 @@ components: type: object OpenapiCreateWebhookRequest: properties: + description: + type: string + display_name: + type: string enabled: type: boolean insecure: @@ -3058,6 +3269,15 @@ components: type: $ref: '#/components/schemas/OpenapiContentType' type: object + OpenapiMergePullReq: + properties: + delete_branch: + type: boolean + force: + type: boolean + method: + $ref: '#/components/schemas/EnumMergeMethod' + type: object OpenapiMoveRepoRequest: properties: keep_as_alias: @@ -3080,6 +3300,18 @@ components: nullable: true type: string type: object + OpenapiReviewSubmitPullReqRequest: + properties: + decision: + type: string + message: + type: string + type: object + OpenapiReviewerAddPullReqRequest: + properties: + reviewer_id: + type: integer + type: object OpenapiUpdatePullReqRequest: properties: description: @@ -3107,6 +3339,12 @@ components: type: object OpenapiUpdateWebhookRequest: properties: + description: + nullable: true + type: string + display_name: + nullable: true + type: string enabled: nullable: true type: boolean @@ -3130,6 +3368,7 @@ components: - success - retriable_error - fatal_error + nullable: true type: string OpenapiWebhookExecutionType: properties: @@ -3174,12 +3413,20 @@ components: type: integer created_by: type: integer + description: + type: string + display_name: + type: string enabled: type: boolean + has_secret: + type: boolean id: type: integer insecure: type: boolean + latest_execution_result: + $ref: '#/components/schemas/OpenapiWebhookExecutionResult' parent_id: type: integer parent_type: @@ -3367,8 +3614,7 @@ components: id: type: integer merge_strategy: - nullable: true - type: string + $ref: '#/components/schemas/EnumMergeMethod' merged: nullable: true type: integer @@ -3388,10 +3634,6 @@ components: type: integer title: type: string - updated: - type: integer - version: - type: integer type: object TypesPullReqActivity: properties: @@ -3436,10 +3678,6 @@ components: type: string type: $ref: '#/components/schemas/EnumPullReqActivityType' - updated: - type: integer - version: - type: integer type: object TypesRepository: properties: @@ -3592,9 +3830,9 @@ components: headers: type: string status: - type: integer - status_code: type: string + status_code: + type: integer type: object UserUpdateInput: properties: