forked from ericanastas/deploy-google-app-script-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commitTracker.js
83 lines (70 loc) · 2.12 KB
/
commitTracker.js
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
class dataEntry {
constructor(header, data) {
for (let i = 0; i < header.length; i++) {
this[header[i]] = data[i];
}
}
}
function splitDataIntoArrayOfObjs_(dataArray, header) {
let outData = [];
for (let entry of dataArray) {
Logger.log(entry);
let dataLine = new dataEntry(header, entry);
outData.push(dataLine);
}
return outData;
}
function turnArrayOfObjsIntoData_(objArray) {
let keys = [];
for (let key in objArray[0]) {
Logger.log(key);
keys.push(key);
}
let outData = [];
for (let entry of objArray) {
let singleEntry = [];
for (let key of keys) {
singleEntry.push(entry[key]);
}
outData.push(singleEntry);
}
return outData;
}
function checkForAndAddCommit() {
let worksheet = SpreadsheetApp.getActiveSpreadsheet();
let sheet = worksheet.getSheetByName("commitLog");
let baseData = sheet.getDataRange().getValues();
Logger.log(baseData);
let header = baseData.shift();
let objArray = splitDataIntoArrayOfObjs_(baseData, header);
let commits = [];
for (let entry of objArray) {
commits.push(entry["commit_sha"]);
}
if (commits.includes(GITHUB_DATA.commit_sha)) {
Logger.log("Commit already there");
} else {
objArray.unshift(GITHUB_DATA);
}
let finalData = turnArrayOfObjsIntoData_(objArray)
sendDataToDisplayV3_commitTracker_(header, finalData, sheet)
}
function sendDataToDisplayV3_commitTracker_(header, finalData, sheet) {
// responsible for actually displaying the data. Clears first to get rid of anything that might be left over.
sheet.clearContents();
sheet.appendRow(header);
Logger.log(finalData.length);
Logger.log("adding Header");
Logger.log(header);
sheet.getRange(1, 1, 1, header.length).setValues([header]);
Logger.log("added header, adding data");
if (finalData.length == 0 || typeof finalData == null) {
Logger.log("no data, skipping");
return;
} else {
sheet.getRange(2, 1, finalData.length, finalData[0].length).setValues(finalData);
// Logger.log("Data added, sorting");
// sheet.getRange(2, 1, finalData.length, header.length)
// Logger.log("data added")
}
}