feat: 修改从gitea上获取配置的逻辑
All checks were successful
Redis序列化结构检查 / redis-schema-check (push) Has been skipped
All checks were successful
Redis序列化结构检查 / redis-schema-check (push) Has been skipped
This commit is contained in:
@@ -2,13 +2,10 @@
|
|||||||
# Redis 序列化结构变更检测 — 业务仓库配置
|
# Redis 序列化结构变更检测 — 业务仓库配置
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# 说明:
|
# 说明:
|
||||||
# - 本文件为业务覆盖配置,会与 jar 内 default-config.yaml 深度合并
|
# - 本配置文件为业务覆盖配置,会与 jar 内 default-config.yaml 深度合并
|
||||||
# - 未声明的项沿用工具内置默认值(忽略规则、检测模式等)
|
# - 未声明的项沿用工具内置默认值(忽略规则、检测模式等)
|
||||||
# - 上线策略:先 notify 观察 1 周,稳定后改为 mode: block
|
|
||||||
|
|
||||||
# 运行模式
|
# 运行模式 notify-仅通知,不阻断流水线 block-按block_severities阻断流水线(exit 1)
|
||||||
# notify - 仅通知,不阻断流水线
|
|
||||||
# block - 按 block_severities 阻断流水线(exit 1)
|
|
||||||
mode: notify
|
mode: notify
|
||||||
|
|
||||||
# block 模式下触发阻断的严重级别(P0/P1/P2 全部阻断)
|
# block 模式下触发阻断的严重级别(P0/P1/P2 全部阻断)
|
||||||
@@ -20,9 +17,9 @@ block_severities:
|
|||||||
# 通知配置
|
# 通知配置
|
||||||
notify:
|
notify:
|
||||||
enabled: true
|
enabled: true
|
||||||
webhook_env: WECOM_ROBOT_WEBHOOK
|
webhook_url: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=fa14f0b3-e01a-40f6-96bd-e18beb94e85e
|
||||||
notify_on_clean: false
|
notify_on_clean: false
|
||||||
title_prefix: "[Redis结构变更]"
|
title_prefix: "[Redis数据结构变更]"
|
||||||
|
|
||||||
# 观察期:先只扫描 jnpf-tenant 模块,稳定后改为 include_modules: []
|
# 观察期:先只扫描 jnpf-tenant 模块,稳定后改为 include_modules: []
|
||||||
include_modules:
|
include_modules:
|
||||||
|
|||||||
@@ -60,8 +60,6 @@ jobs:
|
|||||||
echo "Java: $(java -version 2>&1 | head -1)"
|
echo "Java: $(java -version 2>&1 | head -1)"
|
||||||
|
|
||||||
- name: 执行 Redis 序列化结构检测
|
- name: 执行 Redis 序列化结构检测
|
||||||
env:
|
|
||||||
WECOM_ROBOT_WEBHOOK: ${{ secrets.WECOM_ROBOT_WEBHOOK }}
|
|
||||||
run: |
|
run: |
|
||||||
OLD_SHA=$(git rev-parse HEAD~1 2>/dev/null || echo "")
|
OLD_SHA=$(git rev-parse HEAD~1 2>/dev/null || echo "")
|
||||||
if [ -z "$OLD_SHA" ]; then
|
if [ -z "$OLD_SHA" ]; then
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class RedisSchemaCheckerMain implements Callable<Integer> {
|
|||||||
boolean shouldNotify = config.getNotify().isEnabled()
|
boolean shouldNotify = config.getNotify().isEnabled()
|
||||||
&& (report.hasChanges() || config.getNotify().isNotifyOnClean());
|
&& (report.hasChanges() || config.getNotify().isNotifyOnClean());
|
||||||
if (shouldNotify && !dryRun) {
|
if (shouldNotify && !dryRun) {
|
||||||
String webhook = System.getenv(config.getNotify().getWebhookEnv());
|
String webhook = config.getNotify().getWebhookUrl();
|
||||||
boolean ok = new WeComNotifier().sendMarkdown(webhook, builder.toMarkdown(report));
|
boolean ok = new WeComNotifier().sendMarkdown(webhook, builder.toMarkdown(report));
|
||||||
System.out.println("[redis-schema-checker] 企微通知发送: " + (ok ? "成功" : "失败/跳过"));
|
System.out.println("[redis-schema-checker] 企微通知发送: " + (ok ? "成功" : "失败/跳过"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ public class CheckerConfig {
|
|||||||
|
|
||||||
public static class Notify {
|
public static class Notify {
|
||||||
private boolean enabled = true;
|
private boolean enabled = true;
|
||||||
private String webhookEnv = "WECOM_ROBOT_WEBHOOK";
|
/** 企微机器人 Webhook 完整 URL */
|
||||||
|
private String webhookUrl = "";
|
||||||
private boolean notifyOnClean = false;
|
private boolean notifyOnClean = false;
|
||||||
private String titlePrefix = "[Redis结构变更]";
|
private String titlePrefix = "[Redis结构变更]";
|
||||||
|
|
||||||
@@ -49,12 +50,12 @@ public class CheckerConfig {
|
|||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWebhookEnv() {
|
public String getWebhookUrl() {
|
||||||
return webhookEnv;
|
return webhookUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWebhookEnv(String webhookEnv) {
|
public void setWebhookUrl(String webhookUrl) {
|
||||||
this.webhookEnv = webhookEnv;
|
this.webhookUrl = webhookUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNotifyOnClean() {
|
public boolean isNotifyOnClean() {
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public final class ConfigLoader {
|
|||||||
Map<String, Object> notify = asMap(map.get("notify"));
|
Map<String, Object> notify = asMap(map.get("notify"));
|
||||||
CheckerConfig.Notify n = config.getNotify();
|
CheckerConfig.Notify n = config.getNotify();
|
||||||
n.setEnabled(bool(notify, "enabled", true));
|
n.setEnabled(bool(notify, "enabled", true));
|
||||||
n.setWebhookEnv(str(notify, "webhook_env", "WECOM_ROBOT_WEBHOOK"));
|
n.setWebhookUrl(resolveWebhookUrl(notify));
|
||||||
n.setNotifyOnClean(bool(notify, "notify_on_clean", false));
|
n.setNotifyOnClean(bool(notify, "notify_on_clean", false));
|
||||||
n.setTitlePrefix(str(notify, "title_prefix", "[Redis结构变更]"));
|
n.setTitlePrefix(str(notify, "title_prefix", "[Redis结构变更]"));
|
||||||
|
|
||||||
@@ -137,6 +137,21 @@ public final class ConfigLoader {
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优先读取 webhook_url;兼容旧字段 webhook_env(值为 http 开头时视为 URL)。
|
||||||
|
*/
|
||||||
|
private static String resolveWebhookUrl(Map<String, Object> notify) {
|
||||||
|
String url = str(notify, "webhook_url", "");
|
||||||
|
if (url != null && !url.trim().isEmpty()) {
|
||||||
|
return url.trim();
|
||||||
|
}
|
||||||
|
String legacy = str(notify, "webhook_env", "");
|
||||||
|
if (legacy != null && legacy.trim().startsWith("http")) {
|
||||||
|
return legacy.trim();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static Map<String, Object> asMap(Object obj) {
|
private static Map<String, Object> asMap(Object obj) {
|
||||||
if (obj instanceof Map) {
|
if (obj instanceof Map) {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ source_roots:
|
|||||||
# 通知配置
|
# 通知配置
|
||||||
notify:
|
notify:
|
||||||
enabled: true
|
enabled: true
|
||||||
webhook_env: "WECOM_ROBOT_WEBHOOK"
|
webhook_url: ""
|
||||||
notify_on_clean: false
|
notify_on_clean: false
|
||||||
title_prefix: "[Redis结构变更]"
|
title_prefix: "[Redis结构变更]"
|
||||||
|
|
||||||
|
|||||||
@@ -38,4 +38,28 @@ class ConfigLoaderTest {
|
|||||||
assertFalse(config.getNotify().isEnabled());
|
assertFalse(config.getNotify().isEnabled());
|
||||||
assertTrue(config.getBlockSeverities().contains("P2"));
|
assertTrue(config.getBlockSeverities().contains("P2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void loadsWebhookUrlFromConfig(@org.junit.jupiter.api.io.TempDir Path tmp) throws IOException {
|
||||||
|
Path cfg = tmp.resolve("biz.yaml");
|
||||||
|
Files.write(cfg, ("notify:\n"
|
||||||
|
+ " webhook_url: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=test\n"
|
||||||
|
).getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
CheckerConfig config = ConfigLoader.load(cfg);
|
||||||
|
assertEquals("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=test",
|
||||||
|
config.getNotify().getWebhookUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void legacyWebhookEnvUrlStillWorks(@org.junit.jupiter.api.io.TempDir Path tmp) throws IOException {
|
||||||
|
Path cfg = tmp.resolve("biz.yaml");
|
||||||
|
Files.write(cfg, ("notify:\n"
|
||||||
|
+ " webhook_env: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=legacy\n"
|
||||||
|
).getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
CheckerConfig config = ConfigLoader.load(cfg);
|
||||||
|
assertEquals("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=legacy",
|
||||||
|
config.getNotify().getWebhookUrl());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user