From 9d1a4c5d31dc1b1b949d878b7cfe0b175165b4c2 Mon Sep 17 00:00:00 2001 From: mintsweet <0x1304570@gmail.com> Date: Fri, 31 May 2024 18:58:46 +1200 Subject: [PATCH] feat: update webhook url --- .../webhook/components/create-dialog.tsx | 20 +------ .../register/webhook/components/utils.ts | 56 +++++++++++++++++++ .../webhook/components/view-dialog.tsx | 30 +--------- 3 files changed, 61 insertions(+), 45 deletions(-) create mode 100644 config-ui/src/plugins/register/webhook/components/utils.ts diff --git a/config-ui/src/plugins/register/webhook/components/create-dialog.tsx b/config-ui/src/plugins/register/webhook/components/create-dialog.tsx index 3f3c9ca58da..0e25793461d 100644 --- a/config-ui/src/plugins/register/webhook/components/create-dialog.tsx +++ b/config-ui/src/plugins/register/webhook/components/create-dialog.tsx @@ -25,6 +25,8 @@ import { Block, CopyText, ExternalLink } from '@/components'; import { addWebhook } from '@/features'; import { operator } from '@/utils'; +import { transformURI } from './utils'; + import * as S from '../styled'; interface Props { @@ -75,24 +77,8 @@ export const CreateDialog = ({ open, onCancel, onSubmitAfter }: Props) => { setStep(2); setRecord({ id: res.id, - postIssuesEndpoint: `curl ${prefix}${res.postIssuesEndpoint} -X 'POST' -H 'Authorization: Bearer ${res.apiKey}' -d '{ - "issue_key":"DLK-1234", - "title":"a feature from DLK", - "type":"INCIDENT", - "original_status":"TODO", - "status":"TODO", - "created_date":"2020-01-01T12:00:00+00:00", - "updated_date":"2020-01-01T12:00:00+00:00" -}'`, - closeIssuesEndpoint: `curl ${prefix}${res.closeIssuesEndpoint} -X 'POST' -H 'Authorization: Bearer ${res.apiKey}'`, - postDeploymentsCurl: `curl ${prefix}${res.postPipelineDeployTaskEndpoint} -X 'POST' -H 'Authorization: Bearer ${res.apiKey}' -d '{ - "pipeline_id": "Required. This will be the unique id of the deployment", - "repo_url":"e.g. GitHub - apache/incubator-devlake: Apache DevLake is an open-source dev data platform to ingest, ana", - "display_title":"optional-custom-deploy-display-title", - "commit_sha":"e.g. 015e3d3b480e417aede5a1293bd61de9b0fd051d", - "start_time":"Optional, e.g. 2020-01-01T12:00:00+00:00" - }'`, apiKey: res.apiKey, + ...transformURI(prefix, res, res.apiKey), }); onSubmitAfter?.(res.id); } diff --git a/config-ui/src/plugins/register/webhook/components/utils.ts b/config-ui/src/plugins/register/webhook/components/utils.ts new file mode 100644 index 00000000000..73824d14883 --- /dev/null +++ b/config-ui/src/plugins/register/webhook/components/utils.ts @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import { IWebhook } from '@/types'; + +export const transformURI = (prefix: string, webhook: IWebhook, apiKey: string) => { + return { + postIssuesEndpoint: `curl ${prefix}${webhook.postIssuesEndpoint} -X 'POST' -H 'Authorization: Bearer ${ + apiKey ?? '{API_KEY}' + }' -d '{ + "issueKey":"DLK-1234", + "title":"an incident from DLK", + "type":"INCIDENT", + "originalStatus":"TODO", + "status":"TODO", + "createdDate":"2020-01-01T12:00:00+00:00", + "updatedDate":"2020-01-01T12:00:00+00:00" + }'`, + closeIssuesEndpoint: `curl ${prefix}${webhook.closeIssuesEndpoint} -X 'POST' -H 'Authorization: Bearer ${ + apiKey ?? '{API_KEY}' + }'`, + postDeploymentsCurl: `curl ${prefix}${webhook.postPipelineDeployTaskEndpoint} -X 'POST' -H 'Authorization: Bearer ${ + apiKey ?? '{API_KEY}' + }' -d '{ + "id": "Required. This will be the unique ID of the deployment", + "startedDate": "2023-01-01T12:00:00+00:00", + "finishedDate": "2023-01-01T12:00:00+00:00", + "result": "SUCCESS", + "deploymentCommits":[ + { + "repoUrl": "your-git-url", + "refName": "your-branch-name", + "startedDate": "2023-01-01T12:00:00+00:00", + "finishedDate": "2023-01-01T12:00:00+00:00", + "commitSha": "e.g. 015e3d3b480e417aede5a1293bd61de9b0fd051d", + "commitMsg": "optional-commit-message" + } + ] + }'`, + }; +}; diff --git a/config-ui/src/plugins/register/webhook/components/view-dialog.tsx b/config-ui/src/plugins/register/webhook/components/view-dialog.tsx index d2f80a181eb..e1d45aedef2 100644 --- a/config-ui/src/plugins/register/webhook/components/view-dialog.tsx +++ b/config-ui/src/plugins/register/webhook/components/view-dialog.tsx @@ -25,6 +25,8 @@ import { selectWebhook, renewWebhookApiKey } from '@/features'; import { IWebhook } from '@/types'; import { operator } from '@/utils'; +import { transformURI } from './utils'; + import * as S from '../styled'; interface Props { @@ -32,34 +34,6 @@ interface Props { onCancel: () => void; } -const transformURI = (prefix: string, webhook: IWebhook, apiKey: string) => { - return { - postIssuesEndpoint: `curl ${prefix}${webhook.postIssuesEndpoint} -X 'POST' -H 'Authorization: Bearer ${ - apiKey ?? '{API_KEY}' - }' -d '{ - "issue_key":"DLK-1234", - "title":"a feature from DLK", - "type":"INCIDENT", - "original_status":"TODO", - "status":"TODO", - "created_date":"2020-01-01T12:00:00+00:00", - "updated_date":"2020-01-01T12:00:00+00:00" - }'`, - closeIssuesEndpoint: `curl ${prefix}${webhook.closeIssuesEndpoint} -X 'POST' -H 'Authorization: Bearer ${ - apiKey ?? '{API_KEY}' - }'`, - postDeploymentsCurl: `curl ${prefix}${webhook.postPipelineDeployTaskEndpoint} -X 'POST' -H 'Authorization: Bearer ${ - apiKey ?? '{API_KEY}' - }' -d '{ - "pipeline_id": "Required. This will be the unique id of the deployment", - "repo_url":"e.g. GitHub - apache/incubator-devlake: Apache DevLake is an open-source dev data platform to ingest, ana", - "display_title":"optional-custom-deploy-display-title", - "commit_sha":"e.g. 015e3d3b480e417aede5a1293bd61de9b0fd051d", - "start_time":"Optional, e.g. 2020-01-01T12:00:00+00:00" - }'`, - }; -}; - export const ViewDialog = ({ initialId, onCancel }: Props) => { const [open, setOpen] = useState(false); const [operating, setOperating] = useState(false);