Skip to content

Commit c335900

Browse files
authored
Merge pull request #7 from NiklasMerz/headers
Headers
2 parents f1a3b30 + c47ab89 commit c335900

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

.github/workflows/example.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ jobs:
2727
with:
2828
netlify-token: ${{ secrets.NETLIFY_TOKEN }}
2929
netlify-site-id: ${{ secrets.NETLIFY_SITE }}
30-
days: 1
30+
days: 0
31+
disable-header: true
3132
- uses: niklasmerz/csv-to-google-spreadsheet@fixes
3233
with:
3334
csv_path: pageviews.csv

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ inputs:
1212
description: 'How many days back from today should be fetched. Netlify stores analytics for about 30 days.'
1313
default: '29'
1414
required: false
15+
disable-header:
16+
description: 'Set to true for CSV files with no header line. Can be useful for appending.'
17+
default: 'false'
18+
required: false
1519
runs:
1620
using: 'docker'
1721
image: 'Dockerfile'

index.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const fetch = require('node-fetch');
22
const core = require('@actions/core');
33

4-
const token = process.env.NETLIFY_TOKEN || core.getInput('netlify-token', { required: true });
5-
const siteId = process.env.NETLIFY_SITE_ID || core.getInput('netlify-site-id', { required: true });
4+
const token = process.env.NETLIFY_TOKEN || core.getInput('netlify-token', {required: true});
5+
const siteId = process.env.NETLIFY_SITE_ID || core.getInput('netlify-site-id', {required: true});
6+
const days = process.env.DAYS || core.getInput('days');
7+
const disableHeader = process.env.DISABLEHEADER === "true" || core.getInput('disable-header') === "true";
68

79
const startDate = new Date();
810
startDate.setUTCHours(0);
@@ -16,7 +18,6 @@ endDate.setUTCMinutes(59);
1618
endDate.setUTCSeconds(59);
1719
endDate.setUTCMilliseconds(999);
1820

19-
const days = process.env.DAYS || core.getInput('days');
2021
startDate.setUTCDate(endDate.getDate() - days);
2122

2223

@@ -73,14 +74,22 @@ function writeToCSV(data, metric) {
7374
let header = [];
7475
try {
7576
if (data[0] instanceof Array) {
76-
header = [
77-
{ id: 'date', title: 'date' },
78-
{ id: 'timestamp', title: 'timestamp' },
79-
{ id: 'value', title: 'count' },
80-
];
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+
}
8186
} else {
8287
for (const key in data[0]) {
83-
header.push({ id: key, title: key });
88+
if (disableHeader) {
89+
header.push(key);
90+
} else {
91+
header.push({ id: key, title: key });
92+
}
8493
}
8594
}
8695
} catch (e) {

0 commit comments

Comments
 (0)