fix: 获取pipline信息错误
This commit is contained in:
parent
524320c0e8
commit
bcc0eb0fd7
@ -26,6 +26,8 @@ const getFullPipelineList = async (project: ProjectRecordModel) => {
|
|||||||
// 如果当前页没有数据,则直接跳出
|
// 如果当前页没有数据,则直接跳出
|
||||||
if (pipelines.length === 0) break;
|
if (pipelines.length === 0) break;
|
||||||
pipelines.forEach((pipeline) => {
|
pipelines.forEach((pipeline) => {
|
||||||
|
// 如果已经有了比最新的pipeline还要早的pipeline,则跳出
|
||||||
|
if (hasBeforeLatestTime) return;
|
||||||
if (moment(pipeline.created_at).isSameOrBefore(latestTime)) {
|
if (moment(pipeline.created_at).isSameOrBefore(latestTime)) {
|
||||||
hasBeforeLatestTime = true;
|
hasBeforeLatestTime = true;
|
||||||
} else {
|
} else {
|
||||||
@ -52,6 +54,9 @@ const insertFullPipelineList = async (
|
|||||||
|
|
||||||
fullPipelineList.forEach((pipelineList) => {
|
fullPipelineList.forEach((pipelineList) => {
|
||||||
pipelineList.forEach((pipeline) => {
|
pipelineList.forEach((pipeline) => {
|
||||||
|
// 如果没有时间信息,则跳过
|
||||||
|
if (!pipeline.created_at || !pipeline.started_at || !pipeline.finished_at)
|
||||||
|
return;
|
||||||
dbPipelineList.push({
|
dbPipelineList.push({
|
||||||
project_id: fullProjectMap[pipeline.project_id],
|
project_id: fullProjectMap[pipeline.project_id],
|
||||||
user_id: fullUserMap[pipeline.user.id],
|
user_id: fullUserMap[pipeline.user.id],
|
||||||
|
@ -16,4 +16,4 @@ const syncPipLine = async () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default syncPipLine;
|
export default syncPipLine;
|
||||||
|
@ -4,7 +4,10 @@ const AUTH_HEADER = { "PRIVATE-TOKEN": "Zd1UASPcMwVox5tNS6ep" };
|
|||||||
|
|
||||||
const BASE_URL = "https://git.n.xiaomi.com/api/v4";
|
const BASE_URL = "https://git.n.xiaomi.com/api/v4";
|
||||||
|
|
||||||
const gitlabReqWarp = async <T = any>(func: Function, default_value: any) => {
|
const gitlabReqWarp = async <T = any>(
|
||||||
|
func: Function,
|
||||||
|
default_value: any
|
||||||
|
): Promise<T> => {
|
||||||
try {
|
try {
|
||||||
let response = {} as T & GitlabError;
|
let response = {} as T & GitlabError;
|
||||||
response = (await func()) as T & GitlabError;
|
response = (await func()) as T & GitlabError;
|
||||||
@ -13,7 +16,7 @@ const gitlabReqWarp = async <T = any>(func: Function, default_value: any) => {
|
|||||||
} catch {
|
} catch {
|
||||||
return default_value;
|
return default_value;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取项目详情
|
* 获取项目详情
|
||||||
@ -23,7 +26,10 @@ const gitlabReqWarp = async <T = any>(func: Function, default_value: any) => {
|
|||||||
const fetchProjectDetails = async (id: number | string) => {
|
const fetchProjectDetails = async (id: number | string) => {
|
||||||
if (typeof id === "string") id = encodeURIComponent(id);
|
if (typeof id === "string") id = encodeURIComponent(id);
|
||||||
const URL = `${BASE_URL}/projects/${id}`;
|
const URL = `${BASE_URL}/projects/${id}`;
|
||||||
return gitlabReqWarp<GitlabProjDetail>(() => netTool.get(URL, {}, AUTH_HEADER), null);
|
return gitlabReqWarp<GitlabProjDetail>(
|
||||||
|
() => netTool.get(URL, {}, AUTH_HEADER),
|
||||||
|
null
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,7 +41,10 @@ const fetchProjectDetails = async (id: number | string) => {
|
|||||||
const fetchPipelines = async (project_id: number, page = 1) => {
|
const fetchPipelines = async (project_id: number, page = 1) => {
|
||||||
const URL = `${BASE_URL}/projects/${project_id}/pipelines`;
|
const URL = `${BASE_URL}/projects/${project_id}/pipelines`;
|
||||||
const params = { scope: "finished", per_page: 100, page };
|
const params = { scope: "finished", per_page: 100, page };
|
||||||
return gitlabReqWarp<GitlabPipeline[]>(() => netTool.get(URL, params, AUTH_HEADER), []);
|
return gitlabReqWarp<GitlabPipeline[]>(
|
||||||
|
() => netTool.get(URL, params, AUTH_HEADER),
|
||||||
|
[]
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,7 +60,10 @@ const fetchPipelineDetails = async (
|
|||||||
created_at: string
|
created_at: string
|
||||||
) => {
|
) => {
|
||||||
const URL = `${BASE_URL}/projects/${project_id}/pipelines/${pipeline_id}`;
|
const URL = `${BASE_URL}/projects/${project_id}/pipelines/${pipeline_id}`;
|
||||||
const res = gitlabReqWarp<GitlabPipelineDetail>(() => netTool.get(URL, {}, AUTH_HEADER), null);
|
const res = await gitlabReqWarp<GitlabPipelineDetail>(
|
||||||
|
() => netTool.get(URL, {}, AUTH_HEADER),
|
||||||
|
null
|
||||||
|
);
|
||||||
if (res === null) return null;
|
if (res === null) return null;
|
||||||
return { ...res, created_at };
|
return { ...res, created_at };
|
||||||
};
|
};
|
||||||
@ -62,7 +74,10 @@ const fetchPipelineDetails = async (
|
|||||||
*/
|
*/
|
||||||
const fetchProjectBadges = async (project_id: number) => {
|
const fetchProjectBadges = async (project_id: number) => {
|
||||||
const URL = `${BASE_URL}/projects/${project_id}/badges`;
|
const URL = `${BASE_URL}/projects/${project_id}/badges`;
|
||||||
return gitlabReqWarp<GitlabBadge[]>(() => netTool.get(URL, {}, AUTH_HEADER), []);
|
return gitlabReqWarp<GitlabBadge[]>(
|
||||||
|
() => netTool.get(URL, {}, AUTH_HEADER),
|
||||||
|
[]
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,7 +86,10 @@ const fetchProjectBadges = async (project_id: number) => {
|
|||||||
*/
|
*/
|
||||||
const setProjectBadge = async (badge: GitlabBadgeSetParams) => {
|
const setProjectBadge = async (badge: GitlabBadgeSetParams) => {
|
||||||
const URL = `${BASE_URL}/projects/${badge.id}/badges/${badge.badge_id}`;
|
const URL = `${BASE_URL}/projects/${badge.id}/badges/${badge.badge_id}`;
|
||||||
return gitlabReqWarp<GitlabBadge>(() => netTool.put(URL, badge, AUTH_HEADER), null);
|
return gitlabReqWarp<GitlabBadge>(
|
||||||
|
() => netTool.put(URL, badge, AUTH_HEADER),
|
||||||
|
null
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,7 +98,10 @@ const setProjectBadge = async (badge: GitlabBadgeSetParams) => {
|
|||||||
*/
|
*/
|
||||||
const addProjectBadge = async (badge: GitlabBadgeSetParams) => {
|
const addProjectBadge = async (badge: GitlabBadgeSetParams) => {
|
||||||
const URL = `${BASE_URL}/projects/${badge.id}/badges`;
|
const URL = `${BASE_URL}/projects/${badge.id}/badges`;
|
||||||
return gitlabReqWarp<GitlabBadge>(() => netTool.post(URL, badge, {}, AUTH_HEADER), null);
|
return gitlabReqWarp<GitlabBadge>(
|
||||||
|
() => netTool.post(URL, badge, {}, AUTH_HEADER),
|
||||||
|
null
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const gitlab = {
|
const gitlab = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user