import { Gitlab } from "../../types/gitlab" import netTool from "../netTool" import { GITLAB_AUTH_HEADER, GITLAB_BASE_URL, gitlabReqWarp } from "./tools" /** * 获取特定GitLab流水线的详细信息。 * @param {number} project_id - 项目的ID。 * @param {number} pipeline_id - 流水线的ID。 * @param {string} created_at - 流水线的创建日期。 */ const getDetail = async ( project_id: number, pipeline_id: number, created_at?: string ) => { const URL = `${GITLAB_BASE_URL}/projects/${project_id}/pipelines/${pipeline_id}` const res = await gitlabReqWarp( () => netTool.get(URL, {}, GITLAB_AUTH_HEADER), null ) if (res === null) return null return { ...res, created_at } } /** * 获取特定项目的GitLab流水线列表。 * @param {number} project_id - 项目的ID。 * @param {number} [page=1] - 结果的页码(默认值:1)。 * @returns {Promise} 一个解析为流水线数组的promise。 */ const getList = async ( project_id: number, page = 1 ): Promise => { const URL = `${GITLAB_BASE_URL}/projects/${project_id}/pipelines` const params = { scope: "finished", per_page: 100, page } return gitlabReqWarp( () => netTool.get(URL, params, GITLAB_AUTH_HEADER), [] ) } /** * 获取特定GitLab流水线的任务列表。 * @param {number} project_id - 项目的ID。 * @param {number} pipeline_id - 流水线的ID。 * @returns {Promise} 一个解析为任务数组的promise。 */ const getJobs = async ( project_id: number, pipeline_id: number ): Promise => { const URL = `${GITLAB_BASE_URL}/projects/${project_id}/pipelines/${pipeline_id}/jobs` return gitlabReqWarp( () => netTool.get(URL, {}, GITLAB_AUTH_HEADER), [] ) } const pipeline = { getDetail, getList, getJobs, } export default pipeline