All checks were successful
CI Monitor MIflow / build-image (push) Successful in 45s
67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
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<Gitlab.PipelineDetail>(
|
||
() => 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<Gitlab.Pipeline[]>} 一个解析为流水线数组的promise。
|
||
*/
|
||
const getList = async (
|
||
project_id: number,
|
||
page = 1
|
||
): Promise<Gitlab.Pipeline[]> => {
|
||
const URL = `${GITLAB_BASE_URL}/projects/${project_id}/pipelines`
|
||
const params = { scope: "finished", per_page: 100, page }
|
||
return gitlabReqWarp<Gitlab.Pipeline[]>(
|
||
() => netTool.get(URL, params, GITLAB_AUTH_HEADER),
|
||
[]
|
||
)
|
||
}
|
||
|
||
/**
|
||
* 获取特定GitLab流水线的任务列表。
|
||
* @param {number} project_id - 项目的ID。
|
||
* @param {number} pipeline_id - 流水线的ID。
|
||
* @returns {Promise<Gitlab.Job[]>} 一个解析为任务数组的promise。
|
||
*/
|
||
const getJobs = async (
|
||
project_id: number,
|
||
pipeline_id: number
|
||
): Promise<Gitlab.Job[]> => {
|
||
const URL = `${GITLAB_BASE_URL}/projects/${project_id}/pipelines/${pipeline_id}/jobs`
|
||
return gitlabReqWarp<Gitlab.Job[]>(
|
||
() => netTool.get(URL, {}, GITLAB_AUTH_HEADER),
|
||
[]
|
||
)
|
||
}
|
||
|
||
const pipeline = {
|
||
getDetail,
|
||
getList,
|
||
getJobs,
|
||
}
|
||
|
||
export default pipeline
|