From fa619fdf2b98eddbc45698a8d6f9ddeccee1aa12 Mon Sep 17 00:00:00 2001 From: shmck Date: Sun, 31 May 2020 21:40:30 -0700 Subject: [PATCH 1/3] remove 'g' from commits Signed-off-by: shmck --- tests/parse.test.ts | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/tests/parse.test.ts b/tests/parse.test.ts index e2109e5..5c8092e 100644 --- a/tests/parse.test.ts +++ b/tests/parse.test.ts @@ -437,7 +437,7 @@ The first step expect(result.levels[0].steps[0]).toEqual(expected.levels[0].steps[0]); }); - it("should load the full config for a step", () => { + it("should load the full config for multiple levels & steps", () => { const md = `# Title Description. @@ -524,12 +524,13 @@ The third step text: md, config, commits: { - L1S1Q: ["abcdefg1", "123456789"], - L1S1A: ["1gfedcba", "987654321"], - L1S2Q: ["2abcdefg"], - L1S2A: ["3abcdefg"], - L2S1Q: ["4abcdefg"], - L2S1A: ["5abcdefg"], + INIT: [""], + L1S1Q: ["abcdef1", "123456789"], + L1S1A: ["1fedcba", "987654321"], + L1S2Q: ["2abcdef"], + L1S2A: ["3abcdef"], + L2S1Q: ["4abcdef"], + L2S1A: ["5abcdef"], }, }); const expected = { @@ -547,7 +548,7 @@ The third step id: "L1S1", content: "The first step", setup: { - commits: ["abcdefg1", "123456789"], + commits: ["abcdef1", "123456789"], commands: ["npm install"], files: ["someFile.js"], watchers: ["someFile.js"], @@ -555,7 +556,7 @@ The third step subtasks: true, }, solution: { - commits: ["1gfedcba", "987654321"], + commits: ["1fedcba", "987654321"], commands: ["npm install"], files: ["someFile.js"], }, @@ -564,7 +565,7 @@ The third step id: "L1S2", content: "The second step", setup: { - commits: ["2abcdefg"], + commits: ["2abcdef"], commands: ["npm install"], files: ["someFile.js"], watchers: ["someFile.js"], @@ -572,7 +573,7 @@ The third step subtasks: true, }, solution: { - commits: ["3abcdefg"], + commits: ["3abcdef"], commands: ["npm install"], files: ["someFile.js"], }, @@ -589,7 +590,7 @@ The third step id: "L2S1", content: "The third step", setup: { - commits: ["4abcdefg"], + commits: ["4abcdef"], commands: ["npm install"], files: ["someFile.js"], watchers: ["someFile.js"], @@ -597,7 +598,7 @@ The third step subtasks: true, }, solution: { - commits: ["5abcdefg"], + commits: ["5abcdef"], commands: ["npm install"], files: ["someFile.js"], }, @@ -639,7 +640,7 @@ The first step text: md, config, commits: { - L1S1Q: ["abcdefg1", "123456789"], + L1S1Q: ["abcdef1", "123456789"], }, }); const expected = { @@ -657,7 +658,7 @@ The first step id: "L1S1", content: "The first step", setup: { - commits: ["abcdefg1", "123456789"], + commits: ["abcdef1", "123456789"], }, }, ], @@ -684,7 +685,7 @@ Description. }, directory: "coderoad", setup: { - commits: ["abcdefg1"], + commits: ["abcdef1"], commands: [], }, }, @@ -721,7 +722,7 @@ Description. }, directory: "coderoad", setup: { - commits: ["abcdefg1"], + commits: ["abcdef1"], commands: [], }, }, From 0dc9353e0cae20774fb5f22df998f919f0666a6f Mon Sep 17 00:00:00 2001 From: shmck Date: Sun, 31 May 2020 21:43:47 -0700 Subject: [PATCH 2/3] capture init hashes Signed-off-by: shmck --- src/utils/commits.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/utils/commits.ts b/src/utils/commits.ts index ab3ee34..74132de 100644 --- a/src/utils/commits.ts +++ b/src/utils/commits.ts @@ -73,6 +73,17 @@ export async function getCommits({ // add to the list commits[position].push(commit.hash); } + } else { + const initMatches = commit.message.match(/^INIT/); + if (initMatches && initMatches.length) { + if (!commits.INIT) { + // does not exist, create the list + commits.INIT = [commit.hash]; + } else { + // add to the list + commits.INIT.push(commit.hash); + } + } } } } catch (e) { From 33d1f9ea8576a70495b29395745807737e79a612 Mon Sep 17 00:00:00 2001 From: shmck Date: Sun, 31 May 2020 22:01:15 -0700 Subject: [PATCH 3/3] load init commits Signed-off-by: shmck --- src/utils/parse.ts | 22 ++++++++----- tests/parse.test.ts | 75 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 10 deletions(-) diff --git a/src/utils/parse.ts b/src/utils/parse.ts index 8c23d24..afa1d4f 100644 --- a/src/utils/parse.ts +++ b/src/utils/parse.ts @@ -100,10 +100,20 @@ export function parse(params: ParseParams): any { const parsed: Partial = { version: params.config.version, summary: mdContent.summary, - config: params.config.config, + config: params.config.config || {}, levels: [], }; + // add init commits + if (params.commits.INIT && params.commits.INIT.length) { + console.log(JSON.stringify(parsed.config?.testRunner)); + // @ts-ignore + parsed.config.testRunner.setup = { + ...(parsed.config?.testRunner?.setup || {}), + commits: params.commits.INIT, + }; + } + // merge content and tutorial if (params.config.levels && params.config.levels.length) { parsed.levels = params.config.levels @@ -119,12 +129,10 @@ export function parse(params: ParseParams): any { // add level setup commits const levelSetupKey = level.id; if (params.commits[levelSetupKey]) { - if (!level.setup) { - level.setup = { - commits: [], - }; - } - level.setup.commits = params.commits[levelSetupKey]; + level.setup = { + ...(level.setup || {}), + commits: params.commits[levelSetupKey], + }; } // add level step commits diff --git a/tests/parse.test.ts b/tests/parse.test.ts index 5c8092e..ea84002 100644 --- a/tests/parse.test.ts +++ b/tests/parse.test.ts @@ -524,7 +524,6 @@ The third step text: md, config, commits: { - INIT: [""], L1S1Q: ["abcdef1", "123456789"], L1S1A: ["1fedcba", "987654321"], L1S2Q: ["2abcdef"], @@ -685,7 +684,6 @@ Description. }, directory: "coderoad", setup: { - commits: ["abcdef1"], commands: [], }, }, @@ -722,7 +720,6 @@ Description. }, directory: "coderoad", setup: { - commits: ["abcdef1"], commands: [], }, }, @@ -743,4 +740,76 @@ Description. }; expect(result.config).toEqual(expected.config); }); + + it("should parse the tutorial config with INIT commits", () => { + const md = `# Title + +Description. +`; + + const config = { + config: { + testRunner: { + command: "./node_modules/.bin/mocha", + args: { + filter: "--grep", + tap: "--reporter=mocha-tap-reporter", + }, + directory: "coderoad", + }, + appVersions: { + vscode: ">=0.7.0", + }, + repo: { + uri: "https://path.to/repo", + branch: "aBranch", + }, + dependencies: [ + { + name: "node", + version: ">=10", + }, + ], + }, + }; + const result = parse({ + text: md, + config, + commits: { + INIT: ["abcdef1", "123456789"], + }, + }); + const expected = { + summary: { + description: "Description.\n\nSecond description line", + }, + config: { + testRunner: { + command: "./node_modules/.bin/mocha", + args: { + filter: "--grep", + tap: "--reporter=mocha-tap-reporter", + }, + directory: "coderoad", + setup: { + commits: ["abcdef1", "123456789"], + }, + }, + repo: { + uri: "https://path.to/repo", + branch: "aBranch", + }, + dependencies: [ + { + name: "node", + version: ">=10", + }, + ], + appVersions: { + vscode: ">=0.7.0", + }, + }, + }; + expect(result.config).toEqual(expected.config); + }); });