Skip to content

Commit

Permalink
add csv script
Browse files Browse the repository at this point in the history
  • Loading branch information
LDannijs committed Jun 3, 2024
1 parent 7571851 commit bbb6f28
Show file tree
Hide file tree
Showing 326 changed files with 23,394 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,23 @@ jobs:
go build -o ../bin/validate ./cmd/validate.go
- name: Validate webhook templates
run: ./bin/validate
csv:
name: Upload CSV to Airtable
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Node.js dependencies
run: npm ci
- name: Create templates.csv
run: node csv.js
- name: Upload to Airtable
run: |
curl -X POST ${{ secrets.AIRTABLE_WEBHOOKS_API_ENDPOINT }} \
-H "Authorization: Bearer ${{ secrets.AIRTABLE_WEBHOOKS_API_KEY }}" \
-H "Content-Type: text/csv" \
--data-binary "@bin/templates.csv"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin/templates.csv
50 changes: 50 additions & 0 deletions bin/csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const fs = require('fs');
const path = require('path');
const yaml = require('yaml');
const { createObjectCsvWriter } = require('csv-writer');

// Define paths to the templates.yml file and the directory containing the template files
const templatesYmlPath = path.join(__dirname, '..', 'templates.yml');
const templatesDir = (__dirname, '..');

// Read and parse the templates.yml file
const templatesYml = fs.readFileSync(templatesYmlPath, 'utf8');
const templateNames = yaml.parse(templatesYml);

// Define the CSV writer
const csvWriter = createObjectCsvWriter({
path: 'templates.csv',
header: [
{ id: 'name', title: 'Name' },
{ id: 'description', title: 'Description' },
{ id: 'documentationUrl', title: 'Documentation URL' },
{ id: 'format', title: 'Format' },
{ id: 'logoUrl', title: 'Logo URL' }
]
});

// Function to read and parse each template file
const readTemplateFile = (templateName) => {
const templateFilePath = path.join(templatesDir, `${templateName}.yml`);
const templateYml = fs.readFileSync(templateFilePath, 'utf8');
const templateData = yaml.parse(templateYml);
let format = templateData.format;
if (format === 'json') {
format = format.toUpperCase();
}
return {
name: templateData.name,
description: templateData.description,
documentationUrl: templateData['documentation-url'],
format: format,
logoUrl: templateData['logo-url']
};
};

// Collect data from each template file
const templatesData = templateNames.map(templateName => readTemplateFile(templateName));

// Write data to CSV
csvWriter.writeRecords(templatesData)
.then(() => console.log('Templates data written to templates.csv'))
.catch(err => console.error('Error writing to CSV file', err));
1 change: 1 addition & 0 deletions bin/node_modules/.bin/yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions bin/node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions bin/node_modules/csv-writer/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bbb6f28

Please sign in to comment.