Skip to content

Commit

Permalink
feat: update webhook url (#7554)
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsweet committed May 31, 2024
1 parent afd1763 commit 18009e2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
56 changes: 56 additions & 0 deletions config-ui/src/plugins/register/webhook/components/utils.ts
Original file line number Diff line number Diff line change
@@ -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"
}
]
}'`,
};
};
30 changes: 2 additions & 28 deletions config-ui/src/plugins/register/webhook/components/view-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,15 @@ import { selectWebhook, renewWebhookApiKey } from '@/features';
import { IWebhook } from '@/types';
import { operator } from '@/utils';

import { transformURI } from './utils';

import * as S from '../styled';

interface Props {
initialId: ID;
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);
Expand Down

0 comments on commit 18009e2

Please sign in to comment.