fix(auto-tools): 修复CD过滤逻辑错误

- 重命名cdFiltered为in_cd_paths以提高可读性
- 修正CD路径过滤条件,将返回值取反确保正确过滤
- 修复cron时间类型判断逻辑,添加默认返回false避免意外通过
- 更新变量引用以使用新的变量名in_cd_paths
- 修正时间差计算逻辑确保CD状态判断准确
This commit is contained in:
yan
2026-01-18 22:51:22 +08:00
parent 5d6063a293
commit de743e9cbf

View File

@@ -553,24 +553,24 @@ async function initRun(config_run) {
recordPaths.sort((a, b) => b.timestamp - a.timestamp)
const timeConfigs = Array.from(timeJson);
const cdFiltered = matchedPaths.filter(item => {
//还在cd中的path
const in_cd_paths = matchedPaths.filter(item => {
const timeConfig = timeConfigs.find(cfg =>
item.fullPathNames.includes(cfg.name)
);
if (!timeConfig) return true;
if (!timeConfig) return false;
const record = recordPaths.find(r =>
r.path.includes(item.path)
);
if (!record || !record.timestamp) return true;
if (!record || !record.timestamp) return false;
const now = Date.now();
switch (timeType.fromValue(timeConfig.type)) {
case timeType.hours: {
const diff = getTimeDifference(record.timestamp, now);
return diff.total.hours >= timeConfig.value;
return !(diff.total.hours >= timeConfig.value);
}
case timeType.cron: {
const next = cronUtil.getNextCronTimestamp(
@@ -579,17 +579,17 @@ async function initRun(config_run) {
now,
cd.http_api
);
return next && now >= next;
return !(next && now >= next);
}
default:
return true;
return false;
}
});
// 移除 CD 未到的路径
if (cdFiltered.length > 0) {
if (in_cd_paths.length > 0) {
matchedPaths = Array.from(
new Set(matchedPaths).difference(new Set(cdFiltered))
new Set(matchedPaths).difference(new Set(in_cd_paths))
);
}
}