mirror of
https://github.com/jdalrymple/gitbeaker.git
synced 2026-01-18 15:55:30 +00:00
Adding extensive typing support Unified browser and Node.JS implementations Adding support of Gitlab API 16.0
119 lines
3.1 KiB
TypeScript
119 lines
3.1 KiB
TypeScript
import { BaseResource } from '@gitbeaker/requester-utils';
|
|
import { RequestHelper, endpoint } from '../infrastructure';
|
|
import type {
|
|
GitlabAPIResponse,
|
|
PaginationRequestOptions,
|
|
PaginationTypes,
|
|
ShowExpanded,
|
|
Sudo,
|
|
UserAgentDetailSchema,
|
|
} from '../infrastructure';
|
|
import type {
|
|
CreateSnippetOptions,
|
|
EditSnippetOptions,
|
|
ExpandedSnippetSchema,
|
|
SnippetSchema,
|
|
} from './Snippets';
|
|
|
|
export class ProjectSnippets<C extends boolean = false> extends BaseResource<C> {
|
|
all<E extends boolean = false, P extends PaginationTypes = 'offset'>(
|
|
projectId: string | number,
|
|
options?: Sudo & ShowExpanded<E> & PaginationRequestOptions<P>,
|
|
): Promise<GitlabAPIResponse<SnippetSchema[], C, E, P>> {
|
|
return RequestHelper.get<SnippetSchema[]>()(
|
|
this,
|
|
endpoint`projects/${projectId}/snippets`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
create<E extends boolean = false>(
|
|
projectId: string | number,
|
|
title: string,
|
|
options?: CreateSnippetOptions & Sudo & ShowExpanded<E>,
|
|
) {
|
|
return RequestHelper.post<ExpandedSnippetSchema>()(
|
|
this,
|
|
endpoint`projects/${projectId}/snippets`,
|
|
{
|
|
title,
|
|
...options,
|
|
},
|
|
);
|
|
}
|
|
|
|
edit<E extends boolean = false>(
|
|
projectId: string | number,
|
|
snippetId: number,
|
|
options?: EditSnippetOptions & Sudo & ShowExpanded<E>,
|
|
) {
|
|
return RequestHelper.put<ExpandedSnippetSchema>()(
|
|
this,
|
|
endpoint`projects/${projectId}/snippets/${snippetId}`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
remove<E extends boolean = false>(
|
|
projectId: string | number,
|
|
snippetId: number,
|
|
options?: Sudo & ShowExpanded<E>,
|
|
) {
|
|
return RequestHelper.del()(
|
|
this,
|
|
endpoint`projects/${projectId}/snippets/${snippetId}`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
show<E extends boolean = false>(
|
|
projectId: string | number,
|
|
snippetId: number,
|
|
options?: Sudo & ShowExpanded<E>,
|
|
): Promise<GitlabAPIResponse<SnippetSchema, C, E, void>> {
|
|
return RequestHelper.get<SnippetSchema>()(
|
|
this,
|
|
endpoint`projects/${projectId}/snippets/${snippetId}`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
showContent<E extends boolean = false>(
|
|
projectId: string | number,
|
|
snippetId: number,
|
|
options?: Sudo & ShowExpanded<E>,
|
|
): Promise<GitlabAPIResponse<string, C, E, void>> {
|
|
return RequestHelper.get<string>()(
|
|
this,
|
|
endpoint`projects/${projectId}/snippets/${snippetId}/raw`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
showRepositoryFileContent<E extends boolean = false>(
|
|
projectId: string | number,
|
|
snippetId: number,
|
|
ref: string,
|
|
filePath: string,
|
|
options?: Sudo & ShowExpanded<E>,
|
|
): Promise<GitlabAPIResponse<string, C, E, void>> {
|
|
return RequestHelper.get<string>()(
|
|
this,
|
|
endpoint`projects/${projectId}/snippets/${snippetId}/files/${ref}/${filePath}/raw`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
showUserAgentDetails<E extends boolean = false>(
|
|
projectId: string | number,
|
|
snippetId: number,
|
|
options?: Sudo & ShowExpanded<E>,
|
|
) {
|
|
return RequestHelper.get<UserAgentDetailSchema>()(
|
|
this,
|
|
endpoint`projects/${projectId}/snippets/${snippetId}/user_agent_detail`,
|
|
options,
|
|
);
|
|
}
|
|
}
|