Skip to content

Commit

Permalink
Setup company vaidation
Browse files Browse the repository at this point in the history
  • Loading branch information
abarmawi committed Jan 3, 2024
1 parent 4b4be6f commit 94c001b
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run validate
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ We welcome contributions from the community. If you wish to add a company to the
- Add a comprehensive commit message e.g. "Added new trigger-happy company". Push.
- Submit a pull request with a detailed description of your additions or changes.


#### Help! I'm not a developer! How do I contribute?

1. Create a [github account](https://github.com/).
Expand All @@ -38,7 +37,10 @@ We welcome contributions from the community. If you wish to add a company to the

Done! One of the project maintainers will review and merge your changes.

### Data Schema

- [Company Schema](./validators/companies/company-schema.yaml)

### Next steps
### Available commands

- Validate companies data schema
- `npm run validate` Validate the companies yaml files
90 changes: 90 additions & 0 deletions package-lock.json

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

20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "boycott-israeli-tech-companies-dataset",
"version": "1.0.0",
"description": "This repository is dedicated to providing a comprehensive list of Israeli tech companies to boycott, categorized based on their respective industries.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"validate": "node validators/companies/companies-validator.js",
"prepare": "husky install"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"ajv": "^8.12.0",
"husky": "^8.0.0",
"yaml": "^2.3.4"
},
"dependencies": {}
}
41 changes: 41 additions & 0 deletions validators/companies/companies-validator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Validate companies using JSON Schema

const fs = require("fs");
const path = require("path");
const yaml = require("yaml");
const Ajv = require("ajv");

const companiesDatasetDir = path.join(__dirname, "../../", "dataset/companies");
const companySchema = path.join(
__dirname,
"../../",
"validators/companies/company-schema.yaml"
);

// Load and parse YAML schema file
const schemaFile = fs.readFileSync(companySchema, "utf8");
const schema = yaml.parse(schemaFile);

// Create an Ajv instance
const ajv = new Ajv();
const validate = ajv.compile(schema);

// Get all categories (company files)
const categories = fs.readdirSync(companiesDatasetDir);

// Validate files 1 by 1
for (category of categories) {
const companies = fs.readFileSync(
`${companiesDatasetDir}/${category}`,
"utf8"
);
const data = yaml.parse(companies);

const valid = validate(data);
if (!valid) {
console.log("Validation errors:", validate.errors);
process.exit(1);
}
}

console.log("YAML data is valid!");
35 changes: 35 additions & 0 deletions validators/companies/company-schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
type: array
items:
type: object
properties:
Name:
type: string
maxLength: 50
Description:
type: string
maxLength: 500
Website:
type: string
maxLength: 50
Alternatives:
type: array
items:
type: object
properties:
Name:
type: string
maxLength: 50
Description:
type: string
maxLength: 500
Website:
type: string
maxLength: 50
required:
- Name
- Website
additionalProperties: false
required:
- Name
- Website
additionalProperties: false

0 comments on commit 94c001b

Please sign in to comment.