Skip to content

Commit ba26f44

Browse files
committed
Implement disable header
1 parent 34c7ca0 commit ba26f44

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ inputs:
1313
default: '29'
1414
required: false
1515
disable-header:
16-
description: 'Set to true for appending to CSV files and if no header is necessary'
16+
description: 'Set to true for CSV files with no header line. Can be useful for appending.'
1717
default: 'false'
1818
required: false
1919
runs:

index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const core = require('@actions/core');
44
const token = process.env.NETLIFY_TOKEN || core.getInput('netlify-token', {required: true});
55
const siteId = process.env.NETLIFY_SITE_ID || core.getInput('netlify-site-id', {required: true});
66
const days = process.env.DAYS || core.getInput('days');
7-
const header = process.env.DISABLEHEADER === "true" || core.getInput('disable-header') === "true";
7+
const disableHeader = process.env.DISABLEHEADER === "true" || core.getInput('disable-header') === "true";
88

99
const startDate = new Date();
1010
startDate.setUTCHours(0);
@@ -74,14 +74,22 @@ function writeToCSV(data, metric) {
7474
let header = [];
7575
try {
7676
if (data[0] instanceof Array) {
77-
header = [
78-
{ id: 'date', title: 'date' },
79-
{ id: 'timestamp', title: 'timestamp' },
80-
{ id: 'value', title: 'count' },
81-
];
77+
if (disableHeader) {
78+
header = ['date', 'timestamp', 'value'];
79+
} else {
80+
header = [
81+
{ id: 'date', title: 'date' },
82+
{ id: 'timestamp', title: 'timestamp' },
83+
{ id: 'value', title: 'count' },
84+
];
85+
}
8286
} else {
8387
for (const key in data[0]) {
84-
header.push({ id: key, title: key });
88+
if (disableHeader) {
89+
header.push(key);
90+
} else {
91+
header.push({ id: key, title: key });
92+
}
8593
}
8694
}
8795
} catch (e) {

0 commit comments

Comments
 (0)