commit 3d6f3df4f8d42e1b686ed65f7cffa28bf3e84d50
parent ec4f6a87cfe8e9f76146efd17d06c39dfe0ba8e7
Author: William Casarin <jb55@jb55.com>
Date: Sun, 17 Mar 2024 09:09:44 +0000
export: export as json instead of csv
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
M | export.js | | | 32 | +++++--------------------------- |
1 file changed, 5 insertions(+), 27 deletions(-)
diff --git a/export.js b/export.js
@@ -1,5 +1,4 @@
const fs = require("fs");
-const converter = require("json-2-csv");
// Gets a single comment
const getComment = async (octokit, values, issueNumber) => {
@@ -48,44 +47,23 @@ const getFullCommentData = async (octokit, values, data, verbose = false) => {
});
}
return fullComments;
-};
+}
const writeFile = async (data, fileName = false) => {
return new Promise((resolve, reject) => {
- converter
- .json2csv(data, {
- emptyFieldValue: "",
- })
- .then(
- (csvString) => {
- if (!fileName) {
- const now = new Date();
- fileName = `${now.getFullYear()}-${twoPadNumber(
- now.getMonth() + 1
- )}-${twoPadNumber(now.getDate())}-${twoPadNumber(
- now.getHours()
- )}-${twoPadNumber(now.getMinutes())}-${twoPadNumber(
- now.getSeconds()
- )}-issues.csv`;
- }
- fs.writeFile(fileName, csvString, "utf8", function (err) {
+ fs.writeFile(fileName, JSON.stringify(data), "utf8", function (err) {
if (err) {
reject(new Error("Error writing the file."));
} else {
resolve(fileName);
}
});
- },
- () => {
- reject(new Error("Invalid!"));
- }
- );
- });
-};
+ })
+}
const twoPadNumber = (number) => {
return String(number).padStart(2, "0");
-};
+}
const defaultExportColumns = (data) => {
return data.map((issueObject) => {