Skip to content

Commit 6b531aa

Browse files
authored
add schema validation and checklist rendering
1 parent b16c7c6 commit 6b531aa

22 files changed

+305
-94
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"jest": "^24.9.0",
4444
"jest-circus": "^26.4.2",
4545
"js-yaml": "^3.14.0",
46+
"jsonschema": "^1.3.0",
4647
"prettier": "2.1.1",
4748
"ts-jest": "^24.3.0",
4849
"typescript": "^4.0.2",

schemas/IConfig.json

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,21 @@
3333
"footerFileUrl": {
3434
"description": "File that will be added as the issue footer.\nExample: \"https://raw.githubusercontent.com/legomushroom/codespaces-board/main/sprints/sprint%2012/footer.md\"",
3535
"type": "string"
36+
},
37+
"isReplaceProjectMarkers": {
38+
"description": "If replace the <!-- codespaces-board:project_{id}:start -->\nmarkers instead of replacing entire issue body.\n\ndefault: false.",
39+
"type": "boolean"
40+
},
41+
"$schema": {
42+
"description": "Used by `vscode` in JSON files.",
43+
"type": "string"
3644
}
3745
},
46+
"additionalProperties": false,
47+
"required": [
48+
"boardIssue",
49+
"repos"
50+
],
3851
"definitions": {
3952
"IRepoSourceConfig": {
4053
"type": "object",
@@ -61,7 +74,12 @@
6174
]
6275
}
6376
}
64-
}
77+
},
78+
"additionalProperties": false,
79+
"required": [
80+
"owner",
81+
"repo"
82+
]
6583
},
6684
"IProject": {
6785
"type": "object",
@@ -76,8 +94,16 @@
7694
"items": {
7795
"type": "string"
7896
}
97+
},
98+
"isCheckListItems": {
99+
"description": "If to render issues as check list using the [x] markers.\n\ndefault: false",
100+
"type": "boolean"
79101
}
80-
}
102+
},
103+
"additionalProperties": false,
104+
"required": [
105+
"id"
106+
]
81107
}
82108
},
83109
"$schema": "http://json-schema.org/draft-07/schema#"

scripts/generate-json-schema.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ if (!fs.existsSync(OUTPUT_SCHEMA_FOLDER_PATH)){
1212
}
1313

1414
// schema generator settings
15-
const settings = {};
15+
const settings = {
16+
required: true,
17+
strictNullChecks: true,
18+
noExtraProps: true,
19+
};
1620

1721
// ts compiler options
1822
const compilerOptions = {

src/config.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
1+
import { Schema, Validator } from 'jsonschema';
2+
import * as path from 'path';
3+
4+
import { PROJECT_ROOT } from './constants';
5+
16
import { IConfig } from './interfaces/IConfig';
27

38
export const getConfigs = (configFilePath: string): IConfig[] => {
4-
const configs = require(configFilePath);
9+
const configs = require(path.join(PROJECT_ROOT, configFilePath));
10+
11+
return configs;
12+
};
13+
14+
export const getConfigSchema = (): Schema => {
15+
const schema = require(path.join(PROJECT_ROOT, `./schemas/IConfig.json`));
16+
17+
return schema;
18+
};
19+
20+
export const validateConfig = (config: unknown) => {
21+
const validator = new Validator();
22+
23+
const validationResult = validator.validate(config, getConfigSchema());
24+
const { errors } = validationResult;
525

6-
return configs;
26+
return errors;
727
};

src/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export const PROJECT_ROOT = '../';
1+
import * as path from 'path';
2+
3+
export const PROJECT_ROOT = path.join(__dirname, '../');

src/interfaces/IConfig.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,17 @@ export interface IConfig {
4747
* Example: "https://raw.githubusercontent.com/legomushroom/codespaces-board/main/sprints/sprint%2012/footer.md"
4848
*/
4949
footerFileUrl?: string;
50+
51+
/**
52+
* If replace the <!-- codespaces-board:project_{id}:start -->
53+
* markers instead of replacing entire issue body.
54+
*
55+
* default: false.
56+
*/
57+
isReplaceProjectMarkers?: boolean;
58+
59+
/**
60+
* Used by `vscode` in JSON files.
61+
*/
62+
['$schema']?: string,
5063
}

src/interfaces/IIssueState.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum IIssueState {
2+
Open = 'open',
3+
Closed = 'closed',
4+
}

src/interfaces/IProject.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ export interface IProject {
55
* @TJS-type integer
66
*/
77
id: number;
8+
89
/**
910
* Issue labels that will be rendered as sections
1011
* on the aggregated issue.
1112
*/
1213
trackLabels?: string[];
14+
15+
/**
16+
* If to render issues as check list using the [x] markers.
17+
*
18+
* default: false
19+
*/
20+
isCheckListItems?: boolean;
1321
}

src/interfaces/IProjectWithConfig.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { TProject } from './TProject';
2+
import { TProjectConfig } from './TProjetConfig';
3+
4+
5+
export interface IProjectWithConfig {
6+
project: TProject;
7+
projectConfig: TProjectConfig;
8+
}

src/interfaces/IProjectWithTrackedLabels.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)