mirror of
https://github.com/jdalrymple/gitbeaker.git
synced 2026-01-25 16:04:01 +00:00
94 lines
2.8 KiB
TypeScript
94 lines
2.8 KiB
TypeScript
import { BaseResource } from '@gitbeaker/requester-utils';
|
|
import { RequestHelper, createFormData, endpoint } from '../infrastructure';
|
|
import type {
|
|
GitlabAPIResponse,
|
|
PaginationRequestOptions,
|
|
PaginationTypes,
|
|
ShowExpanded,
|
|
Sudo,
|
|
} from '../infrastructure';
|
|
|
|
export interface MetricImageSchema extends Record<string, unknown> {
|
|
id: number;
|
|
created_at: string;
|
|
filename: string;
|
|
file_path: string;
|
|
url: string;
|
|
url_text: string;
|
|
}
|
|
|
|
export class AlertManagement<C extends boolean = false> extends BaseResource<C> {
|
|
allMetricImages<E extends boolean = false, P extends PaginationTypes = 'offset'>(
|
|
projectId: string | number,
|
|
alertIId: number,
|
|
options?: PaginationRequestOptions<P> & Sudo & ShowExpanded<E>,
|
|
): Promise<GitlabAPIResponse<MetricImageSchema[], C, E, P>> {
|
|
const { sudo, showExpanded, maxPages, ...qp } = options || {};
|
|
const requestOptions = options ? {
|
|
sudo: sudo,
|
|
showExpanded: showExpanded,
|
|
maxPages: maxPages,
|
|
searchParams: qp,
|
|
} : undefined;
|
|
|
|
return RequestHelper.get<MetricImageSchema[]>()(
|
|
this,
|
|
endpoint`projects/${projectId}/alert_management_alerts/${alertIId}/metric_images`,
|
|
requestOptions,
|
|
);
|
|
}
|
|
|
|
editMetricImage<E extends boolean = false>(
|
|
projectId: string | number,
|
|
alertIId: number,
|
|
imageId: number,
|
|
options?: { url?: string; urlText?: string } & Sudo & ShowExpanded<E>,
|
|
): Promise<GitlabAPIResponse<MetricImageSchema, C, E, void>> {
|
|
return RequestHelper.put<MetricImageSchema>()(
|
|
this,
|
|
endpoint`projects/${projectId}/alert_management_alerts/${alertIId}/metric_images/${imageId}`,
|
|
{
|
|
sudo: options?.sudo,
|
|
showExpanded: options?.showExpanded,
|
|
body: {
|
|
url: options?.url,
|
|
urlText: options?.urlText,
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
removeMetricImage<E extends boolean = false>(
|
|
projectId: string | number,
|
|
alertIId: number,
|
|
imageId: number,
|
|
options?: Sudo & ShowExpanded<E>,
|
|
): Promise<GitlabAPIResponse<void, C, E, void>> {
|
|
return RequestHelper.del()(
|
|
this,
|
|
endpoint`projects/${projectId}/alert_management_alerts/${alertIId}/metric_images/${imageId}`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
uploadMetricImage<E extends boolean = false>(
|
|
projectId: string | number,
|
|
alertIId: number,
|
|
metricImage: { content: Blob; filename: string },
|
|
options?: { url?: string; urlText?: string } & Sudo & ShowExpanded<E>,
|
|
): Promise<GitlabAPIResponse<MetricImageSchema, C, E, void>> {
|
|
return RequestHelper.post<MetricImageSchema>()(
|
|
this,
|
|
endpoint`projects/${projectId}/alert_management_alerts/${alertIId}/metric_images`,
|
|
{
|
|
...options,
|
|
body: createFormData({
|
|
file: [metricImage.content, metricImage.filename],
|
|
url: options?.url,
|
|
urlText: options?.urlText,
|
|
}),
|
|
},
|
|
);
|
|
}
|
|
}
|