gitlab_monitor/service/gitlab/repository.ts
zhaoyingbo 92fa30ef3d
All checks were successful
CI Monitor MIflow / build-image (push) Successful in 2m42s
feat: 支持初步的CR
2024-08-12 12:24:45 +00:00

28 lines
746 B
TypeScript

import netTool from "../netTool"
import { GITLAB_AUTH_HEADER, GITLAB_BASE_URL, gitlabReqWarp } from "./tools"
/**
* 获取指定项目中某个文件的内容。
* @param {number} project_id - 项目ID。
* @param {string} path - 文件路径。
* @param {string} ref - 分支或标签名称。
* @returns {Promise<string>} 返回包含文件内容的Promise。
*/
const getFileContent = async (
project_id: number,
path: string,
ref: string
) => {
const URL = `${GITLAB_BASE_URL}/projects/${project_id}/repository/files/${encodeURIComponent(path)}/raw?ref=${ref}`
return gitlabReqWarp<string>(
() => netTool.get(URL, {}, GITLAB_AUTH_HEADER),
""
)
}
const repository = {
getFileContent,
}
export default repository