t-comm
Version:
专业、稳定、纯粹的工具库
77 lines (76 loc) • 2.6 kB
TypeScript
/** 仓库文件内容 */
export interface RepoFile {
/** 文件内容(已 base64 解码为 utf-8 字符串) */
content: string;
/** 工蜂返回的原始 encoding(通常为 base64) */
encoding: string;
/** blob_id,作为 sha 使用 */
sha: string;
}
/**
* 获取仓库中指定文件的内容(自动 base64 解码)
*
* 对应工蜂 API:GET /api/v3/projects/:id/repository/files
*
* @param {object} options 输入配置
* @param {string | number} options.projectName 项目名称或项目 ID
* @param {string} options.filePath 文件路径(如 src/utils/helper.ts)
* @param {string} [options.ref='master'] 分支名或 commit SHA
* @param {string} options.privateToken 密钥
* @param {string} [options.baseUrl] baseUrl
* @returns {Promise<RepoFile>} 文件内容(已解码)
* @example
*
* getFileContent({
* projectName: 'group/sub/repo',
* filePath: 'src/utils/helper.ts',
* ref: 'master',
* privateToken: 'xxxxx',
* }).then(file => console.log(file.content));
*/
export declare function getFileContent({ projectName, filePath, ref, privateToken, baseUrl, }: {
projectName: string | number;
filePath: string;
ref?: string;
privateToken: string;
baseUrl?: string;
}): Promise<RepoFile>;
/**
* 更新仓库中的文件(通过 API 提交,不需要 clone)
*
* 对应工蜂 API:PUT /api/v3/projects/:id/repository/files
*
* @param {object} options 输入配置
* @param {string | number} options.projectName 项目名称或项目 ID
* @param {string} options.filePath 文件路径
* @param {string} options.content 新的文件内容(纯文本)
* @param {string} options.commitMessage 提交消息
* @param {string} options.branch 目标分支
* @param {string} options.privateToken 密钥
* @param {string} [options.baseUrl] baseUrl
* @returns {Promise<{ file_path: string; branch_name: string } & Record<string, unknown>>}
* @example
*
* updateFile({
* projectName: 'group/sub/repo',
* filePath: 'src/utils/helper.ts',
* content: 'export const x = 1;\n',
* commitMessage: 'chore: update helper',
* branch: 'master',
* privateToken: 'xxxxx',
* }).then((resp) => {
*
* })
*/
export declare function updateFile({ projectName, filePath, content, commitMessage, branch, privateToken, baseUrl, }: {
projectName: string | number;
filePath: string;
content: string;
commitMessage: string;
branch: string;
privateToken: string;
baseUrl?: string;
}): Promise<{
file_path: string;
branch_name: string;
} & Record<string, unknown>>;