-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevent.ts
More file actions
57 lines (46 loc) · 1.7 KB
/
event.ts
File metadata and controls
57 lines (46 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { GroupedEventDBScheme } from '@hawk.so/types';
import type { EventsTemplateVariables, TemplateEventData } from 'hawk-worker-sender/types/template-variables';
import { toMaxLen } from '../../../slack/src/templates/utils';
/**
* Renders backtrace overview
*
* @param event - event to render
*/
function renderBacktrace(event: GroupedEventDBScheme): string {
let code = '';
const firstNotEmptyFrame = event.payload.backtrace.find(frame => !!frame.sourceCode);
if (!firstNotEmptyFrame) {
return code;
}
code = firstNotEmptyFrame.sourceCode.map(({ line, content }) => {
let colDelimiter = ': ';
if (line === firstNotEmptyFrame.line) {
colDelimiter = ' ->';
}
const MAX_SOURCE_CODE_LINE_LENGTH = 65;
return `${line}${colDelimiter} ${toMaxLen(content, MAX_SOURCE_CODE_LINE_LENGTH)}`;
}).join('\n');
return code;
}
/**
* Return tpl with data substitutions
*
* @param tplData - event template data
*/
export default function render(tplData: EventsTemplateVariables): string {
const eventInfo = tplData.events[0] as TemplateEventData;
const event = eventInfo.event;
const eventURL = tplData.host + '/project/' + tplData.project._id + '/event/' + event._id + '/';
let location = 'Неизвестное место';
if (event.payload.backtrace && event.payload.backtrace.length > 0) {
location = event.payload.backtrace[0].file;
}
return ''.concat(
`**${event.payload.title}**`,
'\n',
`*${location}*\n`,
'```\n' + renderBacktrace(event) + '\n```',
'\n',
`[Посмотреть подробности](${eventURL}) `, `| *${tplData.project.name}*`, ` | ${eventInfo.newCount} новых (${eventInfo.event.totalCount} всего)`
);
}