Commit d78ba114 by Lin Wang

fix: upload the JSON to the Google sheet

parent 41b63eb9
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
"send-gsheet": "bun run src/detect_section_selector_masters/sendDiffToGoogleSheets.ts", "send-gsheet": "bun run src/detect_section_selector_masters/sendDiffToGoogleSheets.ts",
"task:slack": "bun run task && bun run send-diff", "task:slack": "bun run task && bun run send-diff",
"task:slack:ai": "bun run task:ai && bun run send-diff", "task:slack:ai": "bun run task:ai && bun run send-diff",
"task:gsheet": "bun run task && bun run send-gsheet" "task:gsheet": "bun run task && bun run send-gsheet",
"task:gsheet:ai": "bun run task:ai && bun run send-gsheet"
} }
} }
\ No newline at end of file
...@@ -49,17 +49,24 @@ selectedSelectors ...@@ -49,17 +49,24 @@ selectedSelectors
if (typeof first === 'number') { if (typeof first === 'number') {
const pageA = baselineData[first] || {}; const pageA = baselineData[first] || {};
const pageB = otherData[first] || {}; const pageB = otherData[first] || {};
context[selectedLanguages[baselineId]] = { pageUid: pageA.pageUid, pageTitle: pageA.pageTitle, sectionIndex: pageA.sectionIndex }; // Build flattened context keys with language prefix
context[selectedLanguages[otherId]] = { pageUid: pageB.pageUid, pageTitle: pageB.pageTitle, sectionIndex: pageB.sectionIndex }; const langA = selectedLanguages[baselineId];
const langB = selectedLanguages[otherId];
// pageUid, pageTitle, sectionIndex
context[`${langA}:subcategory`] = pageA.pageTitle;
context[`${langB}:subcategory`] = pageB.pageTitle;
context[`${langA}:sectionIndex`] = pageA.sectionIndex;
context[`${langB}:sectionIndex`] = pageB.sectionIndex;
context[`${langA}:pageUid`] = pageA.pageUid;
context[`${langB}:pageUid`] = pageB.pageUid;
const idx = change.path.indexOf('result'); const idx = change.path.indexOf('result');
if (idx !== -1) { if (idx !== -1) {
const itemIdx = change.path[idx + 1]; const itemIdx = change.path[idx + 1];
if (typeof itemIdx === 'number') { // Attach id and path with language prefix
context[selectedLanguages[baselineId]].id = pageA.result?.[itemIdx]?.id; context[`${langA}:id`] = pageA.result?.[itemIdx]?.id || 'Not Applicable';
context[selectedLanguages[otherId]].id = pageB.result?.[itemIdx]?.id; context[`${langB}:id`] = pageB.result?.[itemIdx]?.id || 'Not Applicable';
context[selectedLanguages[baselineId]].path = pageA.result?.[itemIdx]?.path; context[`${langA}:path`] = pageA.result?.[itemIdx]?.path || 'Not Applicable';
context[selectedLanguages[otherId]].path = pageB.result?.[itemIdx]?.path; context[`${langB}:path`] = pageB.result?.[itemIdx]?.path || 'Not Applicable';
}
} }
} }
return { ...change, context }; return { ...change, context };
...@@ -69,27 +76,27 @@ selectedSelectors ...@@ -69,27 +76,27 @@ selectedSelectors
const semantic = annotated.map(change => { const semantic = annotated.map(change => {
const map: Record<string, string> = { E: '修改', N: '新增', D: '删除', A: '数组类型的变更' }; const map: Record<string, string> = { E: '修改', N: '新增', D: '删除', A: '数组类型的变更' };
const type = map[change.kind] || change.kind; const type = map[change.kind] || change.kind;
const pathStr = (change.path || []).map(seg => typeof seg === 'number' ? `[${seg}]` : seg).join('.'); const pathStr = (change.path || []).filter(seg => typeof seg !== 'number' && seg !== 'result').join('.');
let oldV: any, newV: any; let oldV: any, newV: any;
if (change.kind === 'E') { if (change.kind === 'E') {
oldV = (change as any).lhs;
newV = (change as any).rhs;
} else if (change.kind === 'N') {
oldV = (change as any).lhs;
newV = (change as any).rhs;
} else if (change.kind === 'D') {
oldV = (change as any).lhs; oldV = (change as any).lhs;
newV = (change as any).rhs; newV = (change as any).rhs;
} else if (change.kind === 'A') { } else if (change.kind === 'N') {
oldV = (change as any).item.lhs; oldV = (change as any).lhs;
newV = (change as any).item.rhs; newV = (change as any).rhs;
} else if (change.kind === 'D') {
oldV = (change as any).lhs;
newV = (change as any).rhs;
} else if (change.kind === 'A') {
oldV = (change as any).item.lhs;
newV = (change as any).item.rhs;
} }
return { return {
"更改类型": type, [`${selectedLanguages[baselineId]} VS ${selectedLanguages[otherId]} 更改类型`]: type,
"问题类型": pathStr, "字段类型": pathStr,
[`${selectedLanguages[baselineId]}模版值`]: oldV, [`${selectedLanguages[baselineId]}:模版值`]: oldV || 'Not Applicable',
[`${selectedLanguages[otherId]}模版值`]: newV, [`${selectedLanguages[otherId]}:模版值`]: newV || 'Not Applicable',
context: change.context ...change.context
}; };
}); });
......
...@@ -35,7 +35,14 @@ async function uploadAllToSheets() { ...@@ -35,7 +35,14 @@ async function uploadAllToSheets() {
const data = JSON.parse(raw); const data = JSON.parse(raw);
if (!data.length) continue; if (!data.length) continue;
const headers = Object.keys(data[0]); const headers = Object.keys(data[0]);
const rows = data.map((row: any) => headers.map((h: string) => row[h])); const rows = data.map((row: any) =>
headers.map((h: string) => {
const cell = row[h];
return cell != null && typeof cell === 'object'
? JSON.stringify(cell)
: cell;
})
);
// Clear existing values // Clear existing values
await sheets.spreadsheets.values.clear({ spreadsheetId, range: `'${sheetName}'` }); await sheets.spreadsheets.values.clear({ spreadsheetId, range: `'${sheetName}'` });
......
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