Commit fb2db896 by Lin Wang

feat: add the detect error message

parent fcc954dc
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
"scripts": { "scripts": {
"extract": "DETECTION_MODE=extract bun run src/detect_section_selector_masters/index.ts", "extract": "DETECTION_MODE=extract bun run src/detect_section_selector_masters/index.ts",
"extract:ai": "USE_AI_SELECTORS=true bun run extract", "extract:ai": "USE_AI_SELECTORS=true bun run extract",
"detect": "DETECTION_MODE=detect bun run src/detect_section_selector_masters/index.ts", "detect": "USE_AI_SELECTORS=false DETECTION_MODE=detect bun run src/detect_section_selector_masters/index.ts",
"detect:ai": "USE_AI_SELECTORS=true bun run detect", "detect:ai": "USE_AI_SELECTORS=true bun run detect",
"fix": "DETECTION_MODE=fix bun run src/detect_section_selector_masters/index.ts", "fix": "DETECTION_MODE=fix bun run src/detect_section_selector_masters/index.ts",
"fix:ai": "USE_AI_SELECTORS=true bun run fix", "fix:ai": "USE_AI_SELECTORS=true bun run fix",
......
...@@ -3,10 +3,12 @@ import { createReadStream } from 'fs'; ...@@ -3,10 +3,12 @@ import { createReadStream } from 'fs';
import { basename } from 'path'; import { basename } from 'path';
export async function sendSlackMessage(webhookUrl: string, params: { export async function sendSlackMessage(webhookUrl: string, params: {
note?: string,
issue: string, issue: string,
details?: string, details?: string,
}) { }) {
const parts: string[] = []; const parts: string[] = [];
if (params.note) parts.push(`${params.note}`);
parts.push(`Issue: ${params.issue}`); parts.push(`Issue: ${params.issue}`);
if (params.details) parts.push(`Details: ${params.details}`); if (params.details) parts.push(`Details: ${params.details}`);
const text = parts.join('\n'); const text = parts.join('\n');
......
import { sendSlackMessage } from '../clients/slack'; import { sendSlackMessage } from '../clients/slack';
import { readdirSync, readFileSync } from 'fs'; import { readdirSync, readFileSync } from 'fs';
import { join } from 'path'; import { join } from 'path';
import { diffBaselineId } from '../constant/section_selectors';
async function main() { async function main() {
// Scan diff directories for JSON files, with error handling // Scan diff directories for JSON files, with error handling
...@@ -28,15 +29,33 @@ async function main() { ...@@ -28,15 +29,33 @@ async function main() {
return false; return false;
} }
}); });
if (!hasChanges) {
console.log('No changes detected in both diff directories, skipping Slack notification.'); // Check detectOutput file for diffBaselineId
const detectOutputFile = join(__dirname, 'detectOutput', `${diffBaselineId}_detect.json`);
let hasDetectChanges = false;
let detectMessage = '';
try {
const detectData = JSON.parse(readFileSync(detectOutputFile, 'utf-8'));
hasDetectChanges = Array.isArray(detectData) && detectData.length > 0;
if (hasDetectChanges) {
detectMessage = '⚠️ Issues are detected in the EN master section template.';
}
} catch (e) {
console.warn(`DetectOutput file ${detectOutputFile} not found or invalid, skipping baseline check.`);
}
if (!hasChanges && !hasDetectChanges) {
console.log('No changes detected in diff directories and baseline, skipping Slack notification.');
process.exit(0); process.exit(0);
} }
const webhookUrl = process.env.SLACK_WEBHOOK!; const webhookUrl = process.env.SLACK_WEBHOOK!;
const nonAiUrl = `https://docs.google.com/spreadsheets/d/${process.env.GOOGLE_SHEET_ID}/edit`; const nonAiUrl = `https://docs.google.com/spreadsheets/d/${process.env.GOOGLE_SHEET_ID}/edit`;
const aiUrl = `https://docs.google.com/spreadsheets/d/${process.env.GOOGLE_SHEET_AI_ID}/edit`; const aiUrl = `https://docs.google.com/spreadsheets/d/${process.env.GOOGLE_SHEET_AI_ID}/edit`;
await sendSlackMessage(webhookUrl, { await sendSlackMessage(webhookUrl, {
note: `${detectMessage}`,
issue: 'Inconsistencies are detected in i18n master section template', issue: 'Inconsistencies are detected in i18n master section template',
details: `Google Sheet Links:\n- Non-AI selectors: ${nonAiUrl}\n- AI selectors: ${aiUrl}` details: `Google Sheet Links:\n- Non-AI selectors: ${nonAiUrl}\n- AI selectors: ${aiUrl}`
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment