mirror of
https://github.com/jdalrymple/gitbeaker.git
synced 2026-01-18 15:55:30 +00:00
Gitbeaker has been split up into 5 subpackages: gitbeaker-core, gitbeaker-node, gitbeaker-cli, gitbeaker-browser and gitbeaker-requester-utils.
gitbeaker-[node,cli,browser] are enviroment
specific sub packages. For example, if you want to use gitbeaker in a NodeJS environment, use gitbeaker-node. gitbeaker-core is where all the
base logic exists, and gitbeaker-requester-utils is a collection of utility functions for making custom requester libraries.
BREAKING CHANGE: 🧨 This migration requires users to import specific subpackages. For NodeJS
usage, that would be @gitbeaker/node.
113 lines
2.8 KiB
TypeScript
113 lines
2.8 KiB
TypeScript
import { BaseService, RequestHelper, BaseRequestOptions, Sudo } from '../infrastructure';
|
|
|
|
export type RepositoryFileSchema = RepositoryFileSchemaDefault | RepositoryFileSchemaCamelized;
|
|
|
|
export interface RepositoryFileSchemaDefault {
|
|
file_name: string;
|
|
file_path: string;
|
|
size: number;
|
|
encoding: string;
|
|
content: string;
|
|
content_sha256: string;
|
|
ref: string;
|
|
blob_id: string;
|
|
commit_id: string;
|
|
last_commit_id: string;
|
|
}
|
|
|
|
export interface RepositoryFileSchemaCamelized {
|
|
fileName: string;
|
|
filePath: string;
|
|
size: number;
|
|
encoding: string;
|
|
content: string;
|
|
contentSha256: string;
|
|
ref: string;
|
|
blobId: string;
|
|
commitId: string;
|
|
lastCommitId: string;
|
|
}
|
|
|
|
export class RepositoryFiles extends BaseService {
|
|
create(
|
|
projectId: string | number,
|
|
filePath: string,
|
|
branch: string,
|
|
content: string,
|
|
commitMessage: string,
|
|
options?: BaseRequestOptions,
|
|
) {
|
|
const [pId, path] = [projectId, filePath].map(encodeURIComponent);
|
|
|
|
return RequestHelper.post(this, `projects/${pId}/repository/files/${path}`, {
|
|
branch,
|
|
content,
|
|
commitMessage,
|
|
...options,
|
|
});
|
|
}
|
|
|
|
edit(
|
|
projectId: string | number,
|
|
filePath: string,
|
|
branch: string,
|
|
content: string,
|
|
commitMessage: string,
|
|
options?: BaseRequestOptions,
|
|
) {
|
|
const [pId, path] = [projectId, filePath].map(encodeURIComponent);
|
|
|
|
return RequestHelper.put(this, `projects/${pId}/repository/files/${path}`, {
|
|
branch,
|
|
content,
|
|
commitMessage,
|
|
...options,
|
|
});
|
|
}
|
|
|
|
remove(
|
|
projectId: string | number,
|
|
filePath: string,
|
|
branch: string,
|
|
commitMessage: string,
|
|
options?: BaseRequestOptions,
|
|
) {
|
|
const [pId, path] = [projectId, filePath].map(encodeURIComponent);
|
|
|
|
return RequestHelper.del(this, `projects/${pId}/repository/files/${path}`, {
|
|
branch,
|
|
commitMessage,
|
|
...options,
|
|
});
|
|
}
|
|
|
|
show(
|
|
projectId: string | number,
|
|
filePath: string,
|
|
ref: string,
|
|
options?: Sudo,
|
|
): Promise<RepositoryFileSchema> {
|
|
const [pId, path] = [projectId, filePath].map(encodeURIComponent);
|
|
|
|
return RequestHelper.get(this, `projects/${pId}/repository/files/${path}`, {
|
|
ref,
|
|
...options,
|
|
}) as Promise<RepositoryFileSchema>;
|
|
}
|
|
|
|
showBlame(projectId: string | number, filePath: string, options?: Sudo) {
|
|
const [pId, path] = [projectId, filePath].map(encodeURIComponent);
|
|
|
|
return RequestHelper.get(this, `projects/${pId}/repository/files/${path}/blame`, options);
|
|
}
|
|
|
|
showRaw(projectId: string | number, filePath: string, ref: string, options?: Sudo) {
|
|
const [pId, path] = [projectId, filePath].map(encodeURIComponent);
|
|
|
|
return RequestHelper.get(this, `projects/${pId}/repository/files/${path}/raw`, {
|
|
ref,
|
|
...options,
|
|
});
|
|
}
|
|
}
|