Skip to content

Commit

Permalink
Push comments to work notes
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Feb 2, 2021
1 parent 077bdb2 commit 5fb7113
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const pushToServiceHandler = async ({
externalService,
params,
secrets,
commentFieldKey,
}: PushToServiceApiHandlerArgs): Promise<PushToServiceResponse> => {
const { comments } = params;
let res: PushToServiceResponse;
Expand Down Expand Up @@ -51,7 +52,7 @@ const pushToServiceHandler = async ({
incidentId: res.id,
incident: {
...incident,
comments: currentComment.comment,
[commentFieldKey]: currentComment.comment,
},
});
res.comments = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ export function getServiceNowSIRActionType(
}),
params: ExecutorParamsSchemaSIR,
},
executor: curry(executor)({ logger, configurationUtilities, table: serviceNowSIRTable }),
executor: curry(executor)({
logger,
configurationUtilities,
table: serviceNowSIRTable,
commentFieldKey: 'work_notes',
}),
};
}

Expand All @@ -106,7 +111,13 @@ async function executor(
logger,
configurationUtilities,
table,
}: { logger: Logger; configurationUtilities: ActionsConfigurationUtilities; table: string },
commentFieldKey = 'comments',
}: {
logger: Logger;
configurationUtilities: ActionsConfigurationUtilities;
table: string;
commentFieldKey?: string;
},
execOptions: ActionTypeExecutorOptions<
ServiceNowPublicConfigurationType,
ServiceNowSecretConfigurationType,
Expand Down Expand Up @@ -146,6 +157,7 @@ async function executor(
params: pushToServiceParams,
secrets,
logger,
commentFieldKey,
});

logger.debug(`response push to service for incident id: ${data.id}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export interface PushToServiceApiHandlerArgs extends ExternalServiceApiHandlerAr
params: PushToServiceApiParams;
secrets: Record<string, unknown>;
logger: Logger;
commentFieldKey: string;
}

export interface GetIncidentApiHandlerArgs extends ExternalServiceApiHandlerArgs {
Expand Down
69 changes: 69 additions & 0 deletions x-pack/plugins/case/server/routes/api/cases/mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import {
BasicParams,
CommentResponse,
CommentType,
ConnectorMappingsAttributes,
} from '../../../../common/api';

export const updateUser = {
updatedAt: '2020-03-13T08:34:53.450Z',
updatedBy: { full_name: 'Another User', username: 'another' },
};

const entity = {
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { full_name: 'Elastic User', username: 'elastic', email: 'elastic@elastic.co' },
updatedAt: null,
updatedBy: null,
};

export const comment: CommentResponse = {
id: 'mock-comment-1',
comment: 'Wow, good luck catching that bad meanie!',
type: CommentType.user as const,
created_at: '2019-11-25T21:55:00.177Z',
created_by: {
full_name: 'elastic',
email: 'testemail@elastic.co',
username: 'elastic',
},
pushed_at: null,
pushed_by: null,
updated_at: '2019-11-25T21:55:00.177Z',
updated_by: {
full_name: 'elastic',
email: 'testemail@elastic.co',
username: 'elastic',
},
version: 'WzEsMV0=',
};

export const defaultPipes = ['informationCreated'];
export const basicParams: BasicParams = {
description: 'a description',
title: 'a title',
...entity,
};

export const mappings: ConnectorMappingsAttributes[] = [
{
source: 'title',
target: 'short_description',
action_type: 'overwrite',
},
{
source: 'description',
target: 'description',
action_type: 'append',
},
{
source: 'comments',
target: 'comments',
action_type: 'append',
},
];

0 comments on commit 5fb7113

Please sign in to comment.