82 lines
1.7 KiB
TypeScript
82 lines
1.7 KiB
TypeScript
import netTool from "./netTool";
|
|
|
|
const AUTH_HEADER = { "PRIVATE-TOKEN": "Zd1UASPcMwVox5tNS6ep" };
|
|
|
|
const BASE_URL = "https://git.n.xiaomi.com/api/v4";
|
|
|
|
/**
|
|
* 获取项目详情
|
|
* @param id
|
|
* @returns
|
|
*/
|
|
const fetchProjectDetails = async (id: number) => {
|
|
const URL = `${BASE_URL}/projects/${id}`;
|
|
try {
|
|
const response = (await netTool.get(
|
|
URL,
|
|
{},
|
|
AUTH_HEADER
|
|
)) as GitlabProjDetail & GitlabError;
|
|
if (response.message === "404 Project Not Found") return null;
|
|
return response;
|
|
} catch {
|
|
return null;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 获取流水线列表
|
|
* @param project_id
|
|
* @param page
|
|
* @returns
|
|
*/
|
|
const fetchPipelines = async (project_id: number, page = 1) => {
|
|
const URL = `${BASE_URL}/projects/${project_id}/pipelines`;
|
|
const params = { scope: "finished", per_page: 100, page };
|
|
try {
|
|
const response = (await netTool.get(
|
|
URL,
|
|
params,
|
|
AUTH_HEADER
|
|
)) as GitlabPipeline[] & GitlabError;
|
|
if (response?.message === "404 Project Not Found") return [];
|
|
return response;
|
|
} catch {
|
|
return [] as GitlabPipeline[];
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 获取流水线详情
|
|
* @param project_id
|
|
* @param pipeline_id
|
|
* @param created_at
|
|
* @returns
|
|
*/
|
|
const fetchPipelineDetails = async (
|
|
project_id: number,
|
|
pipeline_id: number,
|
|
created_at: string
|
|
) => {
|
|
const URL = `${BASE_URL}/projects/${project_id}/pipelines/${pipeline_id}`;
|
|
try {
|
|
const response = (await netTool.get(
|
|
URL,
|
|
{},
|
|
AUTH_HEADER
|
|
)) as GitlabPipelineDetail & GitlabError;
|
|
if (response.message === "404 Project Not Found") return null;
|
|
return { ...response, created_at };
|
|
} catch {
|
|
return null;
|
|
}
|
|
};
|
|
|
|
const gitlab = {
|
|
fetchProjectDetails,
|
|
fetchPipelines,
|
|
fetchPipelineDetails,
|
|
};
|
|
|
|
export default gitlab;
|