forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-table.js
More file actions
85 lines (68 loc) · 2.26 KB
/
Copy pathgenerate-table.js
File metadata and controls
85 lines (68 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const fs = require("fs");
const path = require("path");
const json2md = require("json2md");
const file = fs.readFileSync(
path.resolve(__dirname, "./cdk_outputs.json"),
"utf8"
);
function generateTable() {
const structure = [];
structure.push({ h1: "Previews" });
structure.push({
p: `**Commit SHA:** ${process.env.GITHUB_SHA?.substring(0, 7)}`,
});
const json = JSON.parse(file);
// Group entries by ProjectName
const projectGroups = Object.values(json).reduce((acc, entry) => {
if (!acc[entry.ProjectName]) {
acc[entry.ProjectName] = {
name: entry.ProjectName,
remote: "",
local: "",
lgcPythonDeploymentUrl: undefined,
lgcJSDeploymentUrl: undefined,
};
}
// Add URLs based on dependency type
if (entry.Dependencies === "Remote") {
acc[entry.ProjectName].remote = entry.FunctionUrl;
} else if (entry.Dependencies === "Local") {
acc[entry.ProjectName].local = entry.FunctionUrl;
}
// Add LGC Python Deployment URL if it exists
if (entry.LgcPythonDeploymentUrl) {
acc[entry.ProjectName].lgcPythonDeploymentUrl = entry.LgcPythonDeploymentUrl;
}
// Add LGC JS Deployment URL if it exists
if (entry.LgcJSDeploymentUrl) {
acc[entry.ProjectName].lgcJSDeploymentUrl = entry.LgcJSDeploymentUrl;
}
return acc;
}, {});
// Convert grouped data to rows array
const rows = Object.values(projectGroups).map((project) => {
let previewMdxString = `[Preview](${project.local})`;
if (project.lgcPythonDeploymentUrl) {
previewMdxString += ` • [Preview with LGC Python](${project.local}?lgcDeploymentUrl=${project.lgcPythonDeploymentUrl})`;
}
if (project.lgcJSDeploymentUrl) {
previewMdxString += ` • [Preview with LGC JS](${project.local}?lgcDeploymentUrl=${project.lgcJSDeploymentUrl})`;
}
const row = {
Name: project.name,
"Preview": previewMdxString,
};
return row;
});
structure.push({
table: {
// headers: ["Name", "Preview (Local Dependencies)", "Preview (Remote Dependencies)"],
headers: ["Name", "Preview"],
rows,
},
});
const md = json2md(structure);
console.log(md);
fs.writeFileSync(path.resolve(__dirname, "./preview-comment.md"), md);
}
generateTable();