Skip to content

Commit 6996054

Browse files
committed
お願いchatGPT
1 parent e332f80 commit 6996054

3 files changed

Lines changed: 74 additions & 5 deletions

File tree

dist/index.js

Lines changed: 34 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,51 @@ const renderHTML = (mat: any) => {
126126
temp = `<tr>${temp}</tr>`;
127127
} else {
128128
const { count: innerCount, body: innerBody } = renderHTML(val);
129-
count += innerCount;
130-
temp += `<th rowspan="${count}">${key}</th>`;
129+
temp += `<th rowspan="${innerCount}">${key}</th>`;
131130
temp += innerBody;
132131
}
133132
body += temp;
134133
}
135134
return { count, body };
136135
};
137136

137+
// chatGPT
138+
function createRecursiveTable(data: NestedData): string {
139+
let html = "<table border='1'>";
140+
html += "<thead><tr><th>Key</th><th>Value</th></tr></thead><tbody>";
141+
142+
function traverse(obj: NestedData | number[], depth = 0): string {
143+
let rows = "";
144+
145+
if (Array.isArray(obj)) {
146+
// 配列の場合、単純に値を出力
147+
rows += `<td>${obj.join(", ")}</td></tr>`;
148+
} else {
149+
for (const key in obj) {
150+
const value = obj[key];
151+
const rowspan = countRows(value);
152+
153+
rows += `<tr>`;
154+
rows += `<td rowspan="${rowspan}">${key}</td>`;
155+
156+
if (Array.isArray(value)) {
157+
// 次が配列なら、すぐ値を出す
158+
rows += `<td>${value.join(", ")}</td></tr>`;
159+
} else {
160+
// 次がオブジェクトなら、さらに潜る
161+
rows += traverse(value, depth + 1);
162+
}
163+
}
164+
}
165+
166+
return rows;
167+
}
168+
169+
html += traverse(data);
170+
html += "</tbody></table>";
171+
return html;
172+
}
173+
138174
console.log("body is", body);
139175

140176
if (body) {
@@ -150,6 +186,7 @@ if (body) {
150186
<tbody>${renderHTML(matrix).body}</tbody>
151187
</table>
152188
`;
189+
body += createRecursiveTable(matrix);
153190
octokit.rest.issues.createComment({
154191
owner,
155192
repo,

0 commit comments

Comments
 (0)