-
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathDashboardAnnotations.ts
43 lines (39 loc) · 1.4 KB
/
DashboardAnnotations.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
39
40
41
42
43
import { BaseResource } from '@gitbeaker/requester-utils';
import { RequestHelper, endpoint } from '../infrastructure';
import type { GitlabAPIResponse, OneOf, ShowExpanded, Sudo } from '../infrastructure';
export interface DashboardAnnotationSchema extends Record<string, unknown> {
id: number;
starting_at: string;
ending_at?: null;
dashboard_path: string;
description: string;
environment_id: number;
cluster_id?: null;
}
export class DashboardAnnotations<C extends boolean = false> extends BaseResource<C> {
create<E extends boolean = false>(
dashboardPath: string,
startingAt: string,
description: string,
{
environmentId,
clusterId,
...options
}: OneOf<{ environmentId: number; clusterId: number }> & { endingAt?: string } & Sudo &
ShowExpanded<E> = {} as any,
): Promise<GitlabAPIResponse<DashboardAnnotationSchema, C, E, void>> {
let url: string;
if (environmentId) url = endpoint`environments/${environmentId}/metrics_dashboard/annotations`;
else if (clusterId) url = endpoint`clusters/${clusterId}/metrics_dashboard/annotations`;
else
throw new Error(
'Missing required argument. Please supply a environmentId or a cluserId in the options parameter.',
);
return RequestHelper.post<DashboardAnnotationSchema>()(this, url, {
dashboardPath,
startingAt,
description,
...options,
});
}
}