Skip to content

Commit b16c7c6

Browse files
authored
consume JSON config
1 parent 987ed46 commit b16c7c6

25 files changed

+561
-163
lines changed

.github/workflows/test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ jobs:
2222
- uses: ./
2323
with:
2424
token: ${{secret.REPO_GITHUB_PAT}}
25+
config: "./testConfig.json"

TODO.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
- Pass the config JSON file refrence thru the yml file
2-
- Create the JSON schema for config
2+
- issue markers
33
- Add the PR parsing logic
44
- Add developer achievements
5-
- stats on when moved from one column to another
5+
6+
- stats on when moved from one column to another ?

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ inputs:
55
token:
66
required: true
77
description: 'GitHub token for API requests'
8+
config:
9+
required: true
10+
description: 'Path to the config'
811
runs:
912
using: 'node12'
1013
main: 'dist/index.js'

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
"scripts": {
88
"build": "tsc",
99
"watch": "tsc -w",
10-
"localy": "node ./lib/main.js",
10+
"locally": "node ./lib/main.js",
1111
"format": "prettier --write **/*.ts",
1212
"format-check": "prettier --check **/*.ts",
1313
"lint": "eslint src/**/*.ts",
1414
"package": "ncc build --source-map --license licenses.txt",
1515
"test": "jest",
16-
"all": "npm run build && npm run format && npm run lint && npm run package && npm test"
16+
"all": "yarn run build && yarn run format && yarn run lint && yarn run package && yarn test",
17+
"generate-json-schema": "node ./scripts/generate-json-schema.js"
1718
},
1819
"repository": {
1920
"type": "git",
@@ -44,6 +45,7 @@
4445
"js-yaml": "^3.14.0",
4546
"prettier": "2.1.1",
4647
"ts-jest": "^24.3.0",
47-
"typescript": "^4.0.2"
48+
"typescript": "^4.0.2",
49+
"typescript-json-schema": "^0.43.0"
4850
}
4951
}

schemas/IConfig.json

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"boardIssue": {
5+
"description": "The issue that is used as aggregated board.",
6+
"type": "string"
7+
},
8+
"repos": {
9+
"description": "List of the repositories/projects to track.",
10+
"type": "array",
11+
"items": {
12+
"$ref": "#/definitions/IRepoSourceConfig"
13+
}
14+
},
15+
"sprintStartDate": {
16+
"description": "The sprint start date in the `yyyy/mm/dd` format.\nExample: \"2020/10/15\"",
17+
"type": "string"
18+
},
19+
"sprintDuration": {
20+
"description": "Sprint duration in days including weekends.\nMust be specified if the `sprintStartDate` set.\nExample: \"21\" (3 weeks)",
21+
"minimum": 7,
22+
"type": "integer"
23+
},
24+
"sprintNumberHolidays": {
25+
"description": "Number of holidays during the sprint.\nExample: \"2\"",
26+
"minimum": 0,
27+
"type": "integer"
28+
},
29+
"headerFileUrl": {
30+
"description": "File that will be added as the issue header.\nExample: \"https://raw.githubusercontent.com/legomushroom/codespaces-board/main/sprints/sprint%2012/header.md\"",
31+
"type": "string"
32+
},
33+
"footerFileUrl": {
34+
"description": "File that will be added as the issue footer.\nExample: \"https://raw.githubusercontent.com/legomushroom/codespaces-board/main/sprints/sprint%2012/footer.md\"",
35+
"type": "string"
36+
}
37+
},
38+
"definitions": {
39+
"IRepoSourceConfig": {
40+
"type": "object",
41+
"properties": {
42+
"owner": {
43+
"description": "Repo owner username.",
44+
"type": "string"
45+
},
46+
"repo": {
47+
"description": "Repo name.",
48+
"type": "string"
49+
},
50+
"projects": {
51+
"description": "Project to track, if not set assuming all projects on the repo.",
52+
"type": "array",
53+
"items": {
54+
"anyOf": [
55+
{
56+
"$ref": "#/definitions/IProject"
57+
},
58+
{
59+
"type": "number"
60+
}
61+
]
62+
}
63+
}
64+
}
65+
},
66+
"IProject": {
67+
"type": "object",
68+
"properties": {
69+
"id": {
70+
"description": "Project id.",
71+
"type": "integer"
72+
},
73+
"trackLabels": {
74+
"description": "Issue labels that will be rendered as sections\non the aggregated issue.",
75+
"type": "array",
76+
"items": {
77+
"type": "string"
78+
}
79+
}
80+
}
81+
}
82+
},
83+
"$schema": "http://json-schema.org/draft-07/schema#"
84+
}

scripts/generate-json-schema.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const TJS = require('typescript-json-schema');
4+
5+
const TARGET_TYPE = 'IConfig';
6+
const TARGET_TYPE_FILE = path.resolve('./src/interfaces/IConfig.ts');
7+
const OUTPUT_SCHEMA_FOLDER_PATH = path.resolve(`./schemas`);
8+
const OUTPUT_SCHEMA_FILE_PATH = path.join(OUTPUT_SCHEMA_FOLDER_PATH, `./${TARGET_TYPE}.json`);
9+
10+
if (!fs.existsSync(OUTPUT_SCHEMA_FOLDER_PATH)){
11+
fs.mkdirSync(OUTPUT_SCHEMA_FOLDER_PATH);
12+
}
13+
14+
// schema generator settings
15+
const settings = {};
16+
17+
// ts compiler options
18+
const compilerOptions = {
19+
strictNullChecks: true,
20+
};
21+
22+
console.log(`Generating JSON schema for the "${TARGET_TYPE}" type..`)
23+
24+
const program = TJS.getProgramFromFiles(
25+
[TARGET_TYPE_FILE],
26+
compilerOptions,
27+
);
28+
29+
// We can either get the schema for one file and one type...
30+
const schema = TJS.generateSchema(program, TARGET_TYPE, settings);
31+
if (!schema) {
32+
throw new Error(`Cannot generate schema for the "${TARGET_TYPE}" type.`);
33+
}
34+
35+
fs.writeFileSync(OUTPUT_SCHEMA_FILE_PATH, JSON.stringify(schema, null, 2));
36+
37+
console.log(`JSON schema has been written to the file: ${OUTPUT_SCHEMA_FILE_PATH}.`);

src/config.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { IConfig } from './interfaces/IConfig';
2+
3+
export const getConfigs = (configFilePath: string): IConfig[] => {
4+
const configs = require(configFilePath);
5+
6+
return configs;
7+
};

src/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const PROJECT_ROOT = '../';

src/interfaces/IConfig.ts

+40-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,50 @@
11
import { IRepoSourceConfig } from './IRepoSourceConfig';
22

33
export interface IConfig {
4-
// issue that is used as board
4+
/**
5+
* The issue that is used as aggregated board.
6+
*/
57
boardIssue: string;
6-
// yyyy/mm/dd => 2020/10/15
8+
9+
/**
10+
* List of the repositories/projects to track.
11+
*/
12+
repos: IRepoSourceConfig[];
13+
14+
/**
15+
* The sprint start date in the `yyyy/mm/dd` format.
16+
* Example: "2020/10/15"
17+
*/
718
sprintStartDate?: string;
8-
// number in days with weekends, e.g. 3 weeks => 21
19+
20+
/**
21+
* Sprint duration in days including weekends.
22+
* Must be specified if the `sprintStartDate` set.
23+
* Example: "21" (3 weeks)
24+
*
25+
* @minimum 7
26+
* @TJS-type integer
27+
*/
928
sprintDuration?: number;
10-
// number of holidays, default: 0
29+
30+
/**
31+
* Number of holidays during the sprint.
32+
* Example: "2"
33+
*
34+
* @minimum 0
35+
* @TJS-type integer
36+
*/
1137
sprintNumberHolidays?: number;
12-
// file that will be added as the issue header
38+
39+
/**
40+
* File that will be added as the issue header.
41+
* Example: "https://raw.githubusercontent.com/legomushroom/codespaces-board/main/sprints/sprint%2012/header.md"
42+
*/
1343
headerFileUrl?: string;
14-
// file that will be added as the issue footer
44+
45+
/**
46+
* File that will be added as the issue footer.
47+
* Example: "https://raw.githubusercontent.com/legomushroom/codespaces-board/main/sprints/sprint%2012/footer.md"
48+
*/
1549
footerFileUrl?: string;
16-
// list of the repos to track
17-
repos: IRepoSourceConfig[];
1850
}

src/interfaces/IProject.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export interface IProject {
2+
/**
3+
* Project id.
4+
*
5+
* @TJS-type integer
6+
*/
7+
id: number;
8+
/**
9+
* Issue labels that will be rendered as sections
10+
* on the aggregated issue.
11+
*/
12+
trackLabels?: string[];
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { TProject } from './TProject';
2+
3+
4+
export interface IProjectWithTrackedLabels {
5+
project: TProject;
6+
labels: string[];
7+
}

src/interfaces/IRepoSourceConfig.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1+
import { IProject } from './IProject';
12

23
export interface IRepoSourceConfig {
4+
/**
5+
* Repo owner username.
6+
*/
37
owner: string;
8+
9+
/**
10+
* Repo name.
11+
*/
412
repo: string;
5-
projects?: number[]; // if not set, assume all projects
13+
14+
/**
15+
* Project to track, if not set assuming all projects on the repo.
16+
*/
17+
projects?: (IProject | number)[];
618
}

src/interfaces/TActionConfig.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { IConfig } from './IConfig';
2+
3+
export type TActionConfig = IConfig[];

0 commit comments

Comments
 (0)