Skip to content

Commit

Permalink
Create dump of all standaardenregister's configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofVDB1 committed Nov 22, 2023
1 parent d79ba46 commit ee3f85b
Show file tree
Hide file tree
Showing 16 changed files with 1,069 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/blank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ on:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
# This workflow contains a single job called "validate-standaarden"
validate-standaarden:
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
# Different Node versions. Each node version will trigger the action
node-version:
- 16.x
- 18.x
Expand Down
69 changes: 69 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = __importDefault(require("axios"));
const configuration_1 = require("./types/configuration");
const utils_1 = require("./utils/utils");
const options = {
method: 'GET',
};
const getStandardRegistry = () => __awaiter(void 0, void 0, void 0, function* () {
const url = 'https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Standaarden/configuratie/standaardenregister.json';
try {
const response = yield (0, axios_1.default)(url, options);
const data = response === null || response === void 0 ? void 0 : response.data;
return data || []; // Add a default return value in case of error or empty data
}
catch (error) {
console.error('Error: unable to fetch the standards registry', error);
return []; // Add a default return value in case of error or empty data
}
});
const getConfiguration = (url) => __awaiter(void 0, void 0, void 0, function* () {
try {
const response = yield (0, axios_1.default)(url, options);
const data = response === null || response === void 0 ? void 0 : response.data;
return data || {}; // Add a default return value in case of error or empty data
}
catch (error) {
console.error('Error: unable to fetch the configuration', error);
return configuration_1.defaultConfiguration; // Add a default return value in case of error or empty data
}
});
const resolveConfigurations = () => __awaiter(void 0, void 0, void 0, function* () {
try {
const standards = yield getStandardRegistry();
return standards.map((standard) => __awaiter(void 0, void 0, void 0, function* () {
const rawUrl = (0, utils_1.generateRawGithubPath)(standard === null || standard === void 0 ? void 0 : standard.repository, 'standaardenregister', standard === null || standard === void 0 ? void 0 : standard.configuration);
return getConfiguration(rawUrl);
}));
}
catch (error) {
console.error('Error: unable to resolve the configurations', error);
return []; // Add a default return value in case of error or empty data
}
});
const saveConfigurations = () => __awaiter(void 0, void 0, void 0, function* () {
try {
const promises = yield resolveConfigurations();
const configurations = yield Promise.all(promises);
const csvData = (0, utils_1.convertJsonToCsv)(configurations);
(0, utils_1.writeFile)('report/merged_configurations.csv', csvData);
(0, utils_1.convertCsvToExcel)(csvData, "report/merged_configurations");
}
catch (error) {
console.error('Error: unable to save the configuration in a file', error);
}
});
saveConfigurations();
62 changes: 62 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import axios from 'axios'

import { FetchOptions } from './types/fetchOptions'
import { Configuration, defaultConfiguration } from './types/configuration'
import { Standard } from './types/standard'
import { generateRawGithubPath, writeFile, convertJsonToCsv, convertCsvToExcel } from './utils/utils'

const options: FetchOptions = {
method: 'GET',
}

const getStandardRegistry = async (): Promise<Array<Standard>> => {
const url: string = 'https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Standaarden/configuratie/standaardenregister.json'

try {
const response = await axios<Array<Standard>>(url, options)
const data = response?.data
return data || [] // Add a default return value in case of error or empty data
} catch (error: unknown) {
console.error('Error: unable to fetch the standards registry', error)
return [] // Add a default return value in case of error or empty data
}
}

const getConfiguration = async (url: string): Promise<Configuration> => {
try {
const response = await axios<Configuration>(url, options)
const data = response?.data
return data || {} // Add a default return value in case of error or empty data
} catch (error: unknown) {
console.error('Error: unable to fetch the configuration', error)
return defaultConfiguration // Add a default return value in case of error or empty data
}
}


const resolveConfigurations = async (): Promise<Promise<Configuration>[]> => {
try {
const standards: Array<Standard> = await getStandardRegistry()
return standards.map(async (standard: Standard) => {
const rawUrl = generateRawGithubPath(standard?.repository, 'standaardenregister', standard?.configuration)
return getConfiguration(rawUrl)
})
} catch (error: unknown) {
console.error('Error: unable to resolve the configurations', error)
return [] // Add a default return value in case of error or empty data
}
}

const saveConfigurations = async (): Promise<void> => {
try {
const promises = await resolveConfigurations()
const configurations = await Promise.all(promises)
const csvData = convertJsonToCsv(configurations)
writeFile('report/merged_configurations.csv', csvData)
convertCsvToExcel(csvData, "report/merged_configurations")
} catch (error: unknown) {
console.error('Error: unable to save the configuration in a file', error)
}
}

saveConfigurations()
Loading

0 comments on commit ee3f85b

Please sign in to comment.