Commit d78ba114 by Lin Wang

fix: upload the JSON to the Google sheet

parent 41b63eb9
......@@ -31,6 +31,7 @@
"send-gsheet": "bun run src/detect_section_selector_masters/sendDiffToGoogleSheets.ts",
"task:slack": "bun run task && 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
if (typeof first === 'number') {
const pageA = baselineData[first] || {};
const pageB = otherData[first] || {};
context[selectedLanguages[baselineId]] = { pageUid: pageA.pageUid, pageTitle: pageA.pageTitle, sectionIndex: pageA.sectionIndex };
context[selectedLanguages[otherId]] = { pageUid: pageB.pageUid, pageTitle: pageB.pageTitle, sectionIndex: pageB.sectionIndex };
// Build flattened context keys with language prefix
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');
if (idx !== -1) {
const itemIdx = change.path[idx + 1];
if (typeof itemIdx === 'number') {
context[selectedLanguages[baselineId]].id = pageA.result?.[itemIdx]?.id;
context[selectedLanguages[otherId]].id = pageB.result?.[itemIdx]?.id;
context[selectedLanguages[baselineId]].path = pageA.result?.[itemIdx]?.path;
context[selectedLanguages[otherId]].path = pageB.result?.[itemIdx]?.path;
}
// Attach id and path with language prefix
context[`${langA}:id`] = pageA.result?.[itemIdx]?.id || 'Not Applicable';
context[`${langB}:id`] = pageB.result?.[itemIdx]?.id || 'Not Applicable';
context[`${langA}:path`] = pageA.result?.[itemIdx]?.path || 'Not Applicable';
context[`${langB}:path`] = pageB.result?.[itemIdx]?.path || 'Not Applicable';
}
}
return { ...change, context };
......@@ -69,27 +76,27 @@ selectedSelectors
const semantic = annotated.map(change => {
const map: Record<string, string> = { E: '修改', N: '新增', D: '删除', A: '数组类型的变更' };
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;
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') {
if (change.kind === 'E') {
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;
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;
newV = (change as any).rhs;
} else if (change.kind === 'A') {
oldV = (change as any).item.lhs;
newV = (change as any).item.rhs;
}
return {
"更改类型": type,
"问题类型": pathStr,
[`${selectedLanguages[baselineId]}模版值`]: oldV,
[`${selectedLanguages[otherId]}模版值`]: newV,
context: change.context
return {
[`${selectedLanguages[baselineId]} VS ${selectedLanguages[otherId]} 更改类型`]: type,
"字段类型": pathStr,
[`${selectedLanguages[baselineId]}:模版值`]: oldV || 'Not Applicable',
[`${selectedLanguages[otherId]}:模版值`]: newV || 'Not Applicable',
...change.context
};
});
......
......@@ -35,7 +35,14 @@ async function uploadAllToSheets() {
const data = JSON.parse(raw);
if (!data.length) continue;
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
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