Skip to content

Commit db5652e

Browse files
authored
[Alerting][Connectors] Refactor Jira: Generic Implementation (phase one) (#73778)
1 parent 1c3f0fc commit db5652e

File tree

67 files changed

+3582
-677
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+3582
-677
lines changed

x-pack/plugins/actions/README.md

Lines changed: 95 additions & 70 deletions
Large diffs are not rendered by default.

x-pack/plugins/actions/server/builtin_action_types/servicenow/case_shema.ts renamed to x-pack/plugins/actions/server/builtin_action_types/case/common_schema.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,20 @@ export const IncidentConfigurationSchema = schema.object({
2222
mapping: schema.arrayOf(MapRecordSchema),
2323
});
2424

25+
export const UserSchema = schema.object({
26+
fullName: schema.nullable(schema.string()),
27+
username: schema.nullable(schema.string()),
28+
});
29+
2530
export const EntityInformation = {
26-
createdAt: schema.maybe(schema.string()),
27-
createdBy: schema.maybe(schema.any()),
31+
createdAt: schema.nullable(schema.string()),
32+
createdBy: schema.nullable(UserSchema),
2833
updatedAt: schema.nullable(schema.string()),
29-
updatedBy: schema.nullable(schema.any()),
34+
updatedBy: schema.nullable(UserSchema),
3035
};
3136

37+
export const EntityInformationSchema = schema.object(EntityInformation);
38+
3239
export const CommentSchema = schema.object({
3340
commentId: schema.string(),
3441
comment: schema.string(),

x-pack/plugins/actions/server/builtin_action_types/servicenow/case_types.ts renamed to x-pack/plugins/actions/server/builtin_action_types/case/common_types.ts

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,38 @@
66

77
import { TypeOf } from '@kbn/config-schema';
88
import {
9-
ExecutorSubActionGetIncidentParamsSchema,
10-
ExecutorSubActionHandshakeParamsSchema,
11-
} from './schema';
12-
import { IncidentConfigurationSchema, MapRecordSchema } from './case_shema';
13-
import {
14-
PushToServiceApiParams,
15-
ExternalServiceIncidentResponse,
16-
ExternalServiceParams,
17-
} from './types';
9+
IncidentConfigurationSchema,
10+
MapRecordSchema,
11+
CommentSchema,
12+
EntityInformationSchema,
13+
} from './common_schema';
1814

1915
export interface CreateCommentRequest {
2016
[key: string]: string;
2117
}
2218

2319
export type IncidentConfiguration = TypeOf<typeof IncidentConfigurationSchema>;
2420
export type MapRecord = TypeOf<typeof MapRecordSchema>;
21+
export type Comment = TypeOf<typeof CommentSchema>;
22+
export type EntityInformation = TypeOf<typeof EntityInformationSchema>;
2523

2624
export interface ExternalServiceCommentResponse {
2725
commentId: string;
2826
pushedDate: string;
2927
externalCommentId?: string;
3028
}
3129

32-
export type ExecutorSubActionGetIncidentParams = TypeOf<
33-
typeof ExecutorSubActionGetIncidentParamsSchema
34-
>;
35-
36-
export type ExecutorSubActionHandshakeParams = TypeOf<
37-
typeof ExecutorSubActionHandshakeParamsSchema
38-
>;
39-
40-
export interface PushToServiceResponse extends ExternalServiceIncidentResponse {
41-
comments?: ExternalServiceCommentResponse[];
42-
}
43-
4430
export interface PipedField {
4531
key: string;
4632
value: string;
4733
actionType: string;
4834
pipes: string[];
4935
}
5036

51-
export interface TransformFieldsArgs {
52-
params: PushToServiceApiParams;
37+
export interface TransformFieldsArgs<P, S> {
38+
params: P;
5339
fields: PipedField[];
54-
currentIncident?: ExternalServiceParams;
40+
currentIncident?: S;
5541
}
5642

5743
export interface TransformerArgs {

x-pack/plugins/actions/server/builtin_action_types/case/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ export const buildMap = (mapping: MapRecord[]): Map<string, MapRecord> => {
5151
}, new Map());
5252
};
5353

54-
export const mapParams = (
55-
params: Partial<ExecutorSubActionPushParams>,
56-
mapping: Map<string, MapRecord>
57-
): AnyParams => {
54+
export const mapParams = <T extends {}>(params: T, mapping: Map<string, MapRecord>): AnyParams => {
5855
return Object.keys(params).reduce((prev: AnyParams, curr: string): AnyParams => {
5956
const field = mapping.get(curr);
6057
if (field) {
@@ -106,7 +103,10 @@ export const createConnectorExecutor = ({
106103
const { comments, externalId, ...restParams } = pushToServiceParams;
107104

108105
const mapping = buildMap(config.casesConfiguration.mapping);
109-
const externalCase = mapParams(restParams, mapping);
106+
const externalCase = mapParams<ExecutorSubActionPushParams>(
107+
restParams as ExecutorSubActionPushParams,
108+
mapping
109+
);
110110

111111
data = await api.pushToService({
112112
externalService,

0 commit comments

Comments
 (0)