Skip to content

Feature/init hashes #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/utils/commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 15 additions & 7 deletions src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,20 @@ export function parse(params: ParseParams): any {
const parsed: Partial<T.Tutorial> = {
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
Expand All @@ -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
Expand Down
104 changes: 87 additions & 17 deletions tests/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -524,12 +524,12 @@ The third step
text: md,
config,
commits: {
L1S1Q: ["abcdefg1", "123456789"],
L1S1A: ["1gfedcba", "987654321"],
L1S2Q: ["2abcdefg"],
L1S2A: ["3abcdefg"],
L2S1Q: ["4abcdefg"],
L2S1A: ["5abcdefg"],
L1S1Q: ["abcdef1", "123456789"],
L1S1A: ["1fedcba", "987654321"],
L1S2Q: ["2abcdef"],
L1S2A: ["3abcdef"],
L2S1Q: ["4abcdef"],
L2S1A: ["5abcdef"],
},
});
const expected = {
Expand All @@ -547,15 +547,15 @@ 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"],
filter: "someFilter",
subtasks: true,
},
solution: {
commits: ["1gfedcba", "987654321"],
commits: ["1fedcba", "987654321"],
commands: ["npm install"],
files: ["someFile.js"],
},
Expand All @@ -564,15 +564,15 @@ The third step
id: "L1S2",
content: "The second step",
setup: {
commits: ["2abcdefg"],
commits: ["2abcdef"],
commands: ["npm install"],
files: ["someFile.js"],
watchers: ["someFile.js"],
filter: "someFilter",
subtasks: true,
},
solution: {
commits: ["3abcdefg"],
commits: ["3abcdef"],
commands: ["npm install"],
files: ["someFile.js"],
},
Expand All @@ -589,15 +589,15 @@ The third step
id: "L2S1",
content: "The third step",
setup: {
commits: ["4abcdefg"],
commits: ["4abcdef"],
commands: ["npm install"],
files: ["someFile.js"],
watchers: ["someFile.js"],
filter: "someFilter",
subtasks: true,
},
solution: {
commits: ["5abcdefg"],
commits: ["5abcdef"],
commands: ["npm install"],
files: ["someFile.js"],
},
Expand Down Expand Up @@ -639,7 +639,7 @@ The first step
text: md,
config,
commits: {
L1S1Q: ["abcdefg1", "123456789"],
L1S1Q: ["abcdef1", "123456789"],
},
});
const expected = {
Expand All @@ -657,7 +657,7 @@ The first step
id: "L1S1",
content: "The first step",
setup: {
commits: ["abcdefg1", "123456789"],
commits: ["abcdef1", "123456789"],
},
},
],
Expand All @@ -684,7 +684,6 @@ Description.
},
directory: "coderoad",
setup: {
commits: ["abcdefg1"],
commands: [],
},
},
Expand Down Expand Up @@ -721,7 +720,6 @@ Description.
},
directory: "coderoad",
setup: {
commits: ["abcdefg1"],
commands: [],
},
},
Expand All @@ -742,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);
});
});