You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by kl...@apache.org on 2024/05/31 07:04:40 UTC

(incubator-devlake) branch main updated: feat: update webhook url (#7554)

This is an automated email from the ASF dual-hosted git repository.

klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 18009e2d3 feat: update webhook url (#7554)
18009e2d3 is described below

commit 18009e2d3b2065a09778cf7c0ee60944733bd77a
Author: 青湛 <0x...@gmail.com>
AuthorDate: Fri May 31 19:04:36 2024 +1200

    feat: update webhook url (#7554)
---
 .../register/webhook/components/create-dialog.tsx  | 20 ++------
 .../plugins/register/webhook/components/utils.ts   | 56 ++++++++++++++++++++++
 .../register/webhook/components/view-dialog.tsx    | 30 +-----------
 3 files changed, 61 insertions(+), 45 deletions(-)

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 3f3c9ca58..0e2579346 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 000000000..73824d148
--- /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 d2f80a181..e1d45aede 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);