forked from frankie567/grafana-annotation-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
38 lines (29 loc) · 1014 Bytes
/
index.ts
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
import * as core from '@actions/core';
import { GrafanaClient } from './grafana';
export const run = async (): Promise<void> => {
try {
const apiHost = core.getInput('apiHost');
const apiToken = core.getInput('apiToken');
const grafanaClient = new GrafanaClient(apiHost, apiToken);
const text = core.getInput('text');
const rawDashboardId = core.getInput('dashboardId');
const rawPanelId = core.getInput('panelId');
const rawTags = core.getInput('tags');
const dashboardId = rawDashboardId ? Number.parseInt(rawDashboardId, 10) : undefined;
const panelId = rawPanelId ? Number.parseInt(rawPanelId, 10) : undefined;
const tags = rawTags ? rawTags.split(',') : undefined;
const time = Date.now();
const annotationId = await grafanaClient.createAnnotation(
text,
time,
dashboardId,
panelId,
tags,
);
core.info(`Created annotation ${annotationId}`);
}
catch (error) {
core.setFailed(error.message);
}
};
run();