feat: 增加通知Provider和Jenkins自动同步

This commit is contained in:
湛兮
2026-06-11 21:07:54 +08:00
parent caec5a618d
commit 163f411485
14 changed files with 568 additions and 31 deletions
+59 -1
View File
@@ -28,6 +28,7 @@ const INTEGRATION_DEFINITIONS: IntegrationDefinition[] = [
key: 'jenkins',
name: 'Jenkins',
required: ['JENKINS_BASE_URL', 'JENKINS_USERNAME', 'JENKINS_API_TOKEN'],
optional: ['JENKINS_AUTO_SYNC_ENABLED', 'JENKINS_AUTO_SYNC_INTERVAL_MS'],
},
{
key: 'gitea',
@@ -40,7 +41,12 @@ const INTEGRATION_DEFINITIONS: IntegrationDefinition[] = [
key: 'notification',
name: '通知平台',
required: ['NOTIFICATION_PROVIDER'],
optional: ['WECOM_WEBHOOK_URL', 'FEISHU_WEBHOOK_URL', 'NOTIFICATION_WEBHOOK_URL'],
optional: [
'WECOM_WEBHOOK_URL',
'FEISHU_WEBHOOK_URL',
'NOTIFICATION_WEBHOOK_URL',
'DEVOPS_PUBLIC_URL',
],
note: '当前不强制配置机器人;后续可按 provider 接入企微、飞书或通用 webhook。',
},
{
@@ -87,6 +93,10 @@ export class SettingsService {
private toIntegrationStatus(
definition: IntegrationDefinition,
): IntegrationConfigStatus {
if (definition.key === 'notification') {
return this.toNotificationIntegrationStatus(definition);
}
const configured = definition.required.filter((key) =>
this.isConfiguredValue(this.getConfigValue(key)),
);
@@ -106,6 +116,54 @@ export class SettingsService {
};
}
private toNotificationIntegrationStatus(
definition: IntegrationDefinition,
): IntegrationConfigStatus {
const provider = this.getConfigValue('NOTIFICATION_PROVIDER')?.toLowerCase();
const providerWebhook = this.notificationWebhookKey(provider);
const required: EnvStringKey[] = providerWebhook
? ['NOTIFICATION_PROVIDER', providerWebhook]
: ['NOTIFICATION_PROVIDER'];
const configured = required.filter((key) =>
this.isConfiguredValue(this.getConfigValue(key)),
);
const missing = required.filter(
(key) => !this.isConfiguredValue(this.getConfigValue(key)),
);
return {
key: definition.key,
name: definition.name,
status: this.resolveStatus(configured.length, missing.length),
required,
configured,
missing,
...(definition.optional ? { optional: [...definition.optional] } : {}),
note:
provider && !providerWebhook
? `NOTIFICATION_PROVIDER=${provider} 暂不支持;可选 wecom、feishu、generic。`
: definition.note,
};
}
private notificationWebhookKey(
provider: string | undefined,
): EnvStringKey | undefined {
if (provider === 'wecom') {
return 'WECOM_WEBHOOK_URL';
}
if (provider === 'feishu') {
return 'FEISHU_WEBHOOK_URL';
}
if (provider === 'generic') {
return 'NOTIFICATION_WEBHOOK_URL';
}
return undefined;
}
private getConfigValue(key: EnvStringKey): string | undefined {
const value = this.config.get(key, { infer: true });