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 ffb28c3de fix(config-ui): handle webhook apiKey error (#6417)
ffb28c3de is described below
commit ffb28c3de7f52c68f3dfcbc42e5c73170bef9e93
Author: 青湛 <[email protected]>
AuthorDate: Wed Nov 8 21:29:52 2023 +1300
fix(config-ui): handle webhook apiKey error (#6417)
---
config-ui/src/features/connections/slice.ts | 12 +++++-------
config-ui/src/features/connections/utils.ts | 1 -
.../register/webhook/components/create-dialog.tsx | 7 ++++---
.../register/webhook/components/view-dialog.tsx | 18 ++++++++++--------
config-ui/src/types/webhook.ts | 1 -
5 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/config-ui/src/features/connections/slice.ts
b/config-ui/src/features/connections/slice.ts
index 40c8076d6..6e05d01d5 100644
--- a/config-ui/src/features/connections/slice.ts
+++ b/config-ui/src/features/connections/slice.ts
@@ -111,7 +111,10 @@ export const testConnection = createAsyncThunk(
export const addWebhook = createAsyncThunk('connections/addWebhook', async
(payload: any) => {
const webhook = await API.plugin.webhook.create(payload);
- return transformWebhook(webhook);
+ return {
+ webhook: transformWebhook(webhook),
+ apiKey: webhook.apiKey.apiKey,
+ };
});
export const removeWebhook = createAsyncThunk('connections/removeWebhook',
async (id: ID) => {
@@ -175,7 +178,7 @@ export const connectionsSlice = createSlice({
}
})
.addCase(addWebhook.fulfilled, (state, action) => {
- state.webhooks.push(action.payload);
+ state.webhooks.push(action.payload.webhook);
})
.addCase(removeWebhook.fulfilled, (state, action) => {
state.webhooks = state.webhooks.filter((wh) => wh.id !==
action.payload);
@@ -184,11 +187,6 @@ export const connectionsSlice = createSlice({
state.webhooks = state.webhooks.map((wh) =>
wh.id === action.payload.id ? { ...wh, name: action.payload.name } :
wh,
);
- })
- .addCase(renewWebhookApiKey.fulfilled, (state, action) => {
- state.webhooks = state.webhooks.map((wh) =>
- wh.id === action.payload.id ? { ...wh, apiKey: action.payload.apiKey
} : wh,
- );
});
},
});
diff --git a/config-ui/src/features/connections/utils.ts
b/config-ui/src/features/connections/utils.ts
index 118e501b6..320c936a3 100644
--- a/config-ui/src/features/connections/utils.ts
+++ b/config-ui/src/features/connections/utils.ts
@@ -51,7 +51,6 @@ export const transformWebhook = (connection: IWebhookAPI):
IWebhook => {
postIssuesEndpoint: connection.postIssuesEndpoint,
closeIssuesEndpoint: connection.closeIssuesEndpoint,
postPipelineDeployTaskEndpoint: connection.postPipelineDeployTaskEndpoint,
- apiKey: connection.apiKey.apiKey,
apiKeyId: connection.apiKey.id,
};
};
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 6f45f6abf..b148f9267 100644
--- a/config-ui/src/plugins/register/webhook/components/create-dialog.tsx
+++ b/config-ui/src/plugins/register/webhook/components/create-dialog.tsx
@@ -51,9 +51,10 @@ export const CreateDialog = ({ isOpen, onCancel,
onSubmitAfter }: Props) => {
const handleSubmit = async () => {
const [success, res] = await operator(
async () => {
- const { id, apiKey, postIssuesEndpoint, closeIssuesEndpoint,
postPipelineDeployTaskEndpoint } = await dispatch(
- addWebhook({ name }),
- ).unwrap();
+ const {
+ webhook: { id, postIssuesEndpoint, closeIssuesEndpoint,
postPipelineDeployTaskEndpoint },
+ apiKey,
+ } = await dispatch(addWebhook({ name })).unwrap();
return {
id,
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 e3c89a36e..10c4604bc 100644
--- a/config-ui/src/plugins/register/webhook/components/view-dialog.tsx
+++ b/config-ui/src/plugins/register/webhook/components/view-dialog.tsx
@@ -32,10 +32,10 @@ interface Props {
onCancel: () => void;
}
-const transformURI = (prefix: string, webhook: IWebhook) => {
+const transformURI = (prefix: string, webhook: IWebhook, apiKey: string) => {
return {
postIssuesEndpoint: `curl ${prefix}${webhook.postIssuesEndpoint} -X 'POST'
-H 'Authorization: Bearer ${
- webhook.apiKey ?? '{API_KEY}'
+ apiKey ?? '{API_KEY}'
}' -d '{
"issue_key":"DLK-1234",
"title":"a feature from DLK",
@@ -46,10 +46,10 @@ const transformURI = (prefix: string, webhook: IWebhook) =>
{
"updated_date":"2020-01-01T12:00:00+00:00"
}'`,
closeIssuesEndpoint: `curl ${prefix}${webhook.closeIssuesEndpoint} -X
'POST' -H 'Authorization: Bearer ${
- webhook.apiKey ?? '{API_KEY}'
+ apiKey ?? '{API_KEY}'
}'`,
postDeploymentsCurl: `curl
${prefix}${webhook.postPipelineDeployTaskEndpoint} -X 'POST' -H 'Authorization:
Bearer ${
- webhook.apiKey ?? '{API_KEY}'
+ apiKey ?? '{API_KEY}'
}' -d '{
"commit_sha":"the sha of deployment commit",
"repo_url":"the repo URL of the deployment commit",
@@ -61,19 +61,21 @@ const transformURI = (prefix: string, webhook: IWebhook) =>
{
export const ViewDialog = ({ initialId, onCancel }: Props) => {
const [isOpen, setIsOpen] = useState(false);
const [operating, setOperating] = useState(false);
+ const [apiKey, setApiKey] = useState('');
const dispatch = useAppDispatch();
const webhook = useAppSelector((state) => selectWebhook(state, initialId))
as IWebhook;
const prefix = useMemo(() => `${window.location.origin}/api`, []);
- const URI = transformURI(prefix, webhook);
+ const URI = transformURI(prefix, webhook, apiKey);
const handleGenerateNewKey = async () => {
- const [success] = await operator(() =>
dispatch(renewWebhookApiKey(initialId)), {
+ const [success, res] = await operator(async () => await
dispatch(renewWebhookApiKey(initialId)).unwrap(), {
setOperating,
});
if (success) {
+ setApiKey(res.apiKey);
setIsOpen(false);
}
};
@@ -120,12 +122,12 @@ export const ViewDialog = ({ initialId, onCancel }:
Props) => {
label="API Key"
subLabel="If you have forgotten your API key, you can revoke the
previous key and generate a new one as a replacement."
>
- {!webhook.apiKey ? (
+ {!apiKey ? (
<Button intent={Intent.PRIMARY} text="Revoke and generate a new
key" onClick={() => setIsOpen(true)} />
) : (
<>
<S.ApiKey>
- <CopyText content={webhook.apiKey} />
+ <CopyText content={apiKey} />
<span>No Expiration</span>
</S.ApiKey>
<S.Tips>
diff --git a/config-ui/src/types/webhook.ts b/config-ui/src/types/webhook.ts
index 71b510ee6..2035bf675 100644
--- a/config-ui/src/types/webhook.ts
+++ b/config-ui/src/types/webhook.ts
@@ -34,6 +34,5 @@ export interface IWebhook {
postIssuesEndpoint: string;
closeIssuesEndpoint: string;
postPipelineDeployTaskEndpoint: string;
- apiKey: string;
apiKeyId: number;
}