This commit is contained in:
@@ -17,11 +17,11 @@ import java.util.concurrent.Callable;
|
||||
/**
|
||||
* 命令行入口。退出码:0 通过 / 1 阻断 / 2 执行错误。
|
||||
*/
|
||||
@Command(name = "cache-schema-checker",
|
||||
@Command(name = "serialization-schema-checker",
|
||||
mixinStandardHelpOptions = true,
|
||||
version = "cache-schema-checker 1.0.0",
|
||||
description = "检测两次提交间缓存 value 序列化结构变更并通过企微机器人通知。")
|
||||
public class CacheSchemaCheckerMain implements Callable<Integer> {
|
||||
version = "serialization-schema-checker 1.0.0",
|
||||
description = "检测两次提交间缓存/MQ 等 value 序列化结构变更并通过企微机器人通知。")
|
||||
public class SerializationSchemaCheckerMain implements Callable<Integer> {
|
||||
|
||||
@Option(names = "--config", required = true, description = "业务仓库检测配置文件路径")
|
||||
private Path configPath;
|
||||
@@ -56,12 +56,12 @@ public class CacheSchemaCheckerMain implements Callable<Integer> {
|
||||
CheckerConfig config = ConfigLoader.load(configPath);
|
||||
|
||||
if (!config.isEnabled()) {
|
||||
System.out.println("[cache-schema-checker] 总开关 enabled=false,跳过检测。");
|
||||
System.out.println("[serialization-schema-checker] 总开关 enabled=false,跳过检测。");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (oldSha == null || oldSha.trim().isEmpty()) {
|
||||
System.out.println("[cache-schema-checker] 无对比基准提交,跳过检测。");
|
||||
System.out.println("[serialization-schema-checker] 无对比基准提交,跳过检测。");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,6 @@ public class CacheSchemaCheckerMain implements Callable<Integer> {
|
||||
report.setRepository(repository != null ? repository : root.getFileName().toString());
|
||||
|
||||
ReportBuilder builder = new ReportBuilder(config.getNotify().getTitlePrefix());
|
||||
// CI:字段明细 + 完整企微 Markdown
|
||||
System.out.println(builder.toConsole(report));
|
||||
|
||||
boolean shouldNotify = config.getNotify().isEnabled()
|
||||
@@ -84,24 +83,24 @@ public class CacheSchemaCheckerMain implements Callable<Integer> {
|
||||
String webhook = config.getNotify().getWebhookUrl();
|
||||
List<String> messages = builder.toWeComMessages(report);
|
||||
int ok = new WeComNotifier().sendMarkdownMessages(webhook, messages);
|
||||
System.out.println("[cache-schema-checker] 企微通知发送: "
|
||||
System.out.println("[serialization-schema-checker] 企微通知发送: "
|
||||
+ ok + "/" + messages.size()
|
||||
+ (messages.size() > 1 ? "(已按 key 拆分)" : ""));
|
||||
}
|
||||
|
||||
if (report.isBlocked()) {
|
||||
System.out.println("[cache-schema-checker] block 模式命中,流水线将被阻断(exit 1)。");
|
||||
System.out.println("[serialization-schema-checker] block 模式命中,流水线将被阻断(exit 1)。");
|
||||
}
|
||||
return report.getExitCode();
|
||||
} catch (Exception e) {
|
||||
System.err.println("[cache-schema-checker] 执行错误: " + e.getMessage());
|
||||
System.err.println("[serialization-schema-checker] 执行错误: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int exitCode = new CommandLine(new CacheSchemaCheckerMain()).execute(args);
|
||||
int exitCode = new CommandLine(new SerializationSchemaCheckerMain()).execute(args);
|
||||
System.exit(exitCode);
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class CheckerConfig {
|
||||
/** 企微机器人 Webhook 完整 URL */
|
||||
private String webhookUrl = "";
|
||||
private boolean notifyOnClean = false;
|
||||
private String titlePrefix = "[缓存结构变更]";
|
||||
private String titlePrefix = "[序列化结构变更]";
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
|
||||
@@ -87,7 +87,7 @@ public final class ConfigLoader {
|
||||
n.setEnabled(bool(notify, "enabled", true));
|
||||
n.setWebhookUrl(resolveWebhookUrl(notify));
|
||||
n.setNotifyOnClean(bool(notify, "notify_on_clean", false));
|
||||
n.setTitlePrefix(str(notify, "title_prefix", "[缓存结构变更]"));
|
||||
n.setTitlePrefix(str(notify, "title_prefix", "[序列化结构变更]"));
|
||||
|
||||
Map<String, Object> ignore = asMap(map.get("ignore"));
|
||||
CheckerConfig.Ignore ig = config.getIgnore();
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ReportBuilder {
|
||||
private final String titlePrefix;
|
||||
|
||||
public ReportBuilder(String titlePrefix) {
|
||||
this.titlePrefix = titlePrefix == null ? "[缓存结构变更]" : titlePrefix;
|
||||
this.titlePrefix = titlePrefix == null ? "[序列化结构变更]" : titlePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ public class ReportBuilder {
|
||||
String header = buildHeader(report);
|
||||
List<String> bodies = buildKeyBodies(report);
|
||||
if (bodies.isEmpty()) {
|
||||
return Collections.singletonList(header + "未检测到缓存序列化结构变更。\n");
|
||||
return Collections.singletonList(header + "未检测到序列化结构变更。\n");
|
||||
}
|
||||
|
||||
StringBuilder combined = new StringBuilder(header);
|
||||
@@ -182,7 +182,7 @@ public class ReportBuilder {
|
||||
public String toConsole(CheckReport report) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (!report.hasChanges()) {
|
||||
sb.append("未检测到缓存序列化结构变更。\n");
|
||||
sb.append("未检测到序列化结构变更。\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user