From 3be863b077c253b4b8f20a40848ffef98ef6b251 Mon Sep 17 00:00:00 2001 From: shmck Date: Sun, 31 May 2020 16:18:53 -0700 Subject: [PATCH 1/3] parse version Signed-off-by: shmck --- src/utils/parse.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/parse.ts b/src/utils/parse.ts index 36fc5d3..787331c 100644 --- a/src/utils/parse.ts +++ b/src/utils/parse.ts @@ -98,6 +98,7 @@ export function parse(params: ParseParams): any { const mdContent: TutorialFrame = parseMdContent(params.text); const parsed: Partial = { + version: params.config.version, summary: mdContent.summary, config: params.config.config, levels: [], From c8e9721639559c0e2fb7597855f9a399935b77bf Mon Sep 17 00:00:00 2001 From: shmck Date: Sun, 31 May 2020 16:26:14 -0700 Subject: [PATCH 2/3] return to original branch even in failure Signed-off-by: shmck --- src/utils/commits.ts | 60 +++++++++++++++++++++------------------ src/utils/schema/index.ts | 2 +- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/utils/commits.ts b/src/utils/commits.ts index dd8f4bb..ab3ee34 100644 --- a/src/utils/commits.ts +++ b/src/utils/commits.ts @@ -45,41 +45,45 @@ export async function getCommits({ throw new Error(`Code branch "${codeBranch}" not found`); } - console.log("branches", branches); - - // Checkout the code branches - await git.checkout(codeBranch); - - console.log("checked out"); - - // Load all logs - const logs = await git.log(); - - console.log("logs", logs); + // track the original branch in case of failure + const originalBranch = branches.current; // Filter relevant logs const commits: CommitLogObject = {}; - for (const commit of logs.all) { - const matches = commit.message.match( - /^(?(?L\d+)(S\d+))(?[QA])?/ - ); - - if (matches && matches.length) { - // Use an object of commit arrays to collect all commits - const position = matches[0]; - if (!commits[position]) { - // does not exist, create the list - commits[position] = [commit.hash]; - } else { - // add to the list - commits[position].push(commit.hash); + try { + // Checkout the code branches + await git.checkout(codeBranch); + + // Load all logs + const logs = await git.log(); + + for (const commit of logs.all) { + const matches = commit.message.match( + /^(?(?L\d+)(S\d+))(?[QA])?/ + ); + + if (matches && matches.length) { + // Use an object of commit arrays to collect all commits + const position = matches[0]; + if (!commits[position]) { + // does not exist, create the list + commits[position] = [commit.hash]; + } else { + // add to the list + commits[position].push(commit.hash); + } } } + } catch (e) { + console.error("Error with checkout or commit matching"); + throw new Error(e.message); + } finally { + // revert back to the original branch on failure + await git.checkout(originalBranch); + // cleanup the tmp directory + await rmdir(tmpDir, { recursive: true }); } - console.log("remove"); - // cleanup the tmp directory - await rmdir(tmpDir, { recursive: true }); return commits; } diff --git a/src/utils/schema/index.ts b/src/utils/schema/index.ts index 29a9c4f..98d3fd6 100644 --- a/src/utils/schema/index.ts +++ b/src/utils/schema/index.ts @@ -193,7 +193,7 @@ export default { "The solution commits that can be loaded if the user gets stuck. It can also run commands and/or open files", }, { - required: ["commits"], + required: [], }, ], }, From caa4276f7947dad2c27970dd3d04536eed972acc Mon Sep 17 00:00:00 2001 From: shmck Date: Sun, 31 May 2020 16:26:57 -0700 Subject: [PATCH 3/3] pretty write json Signed-off-by: shmck --- src/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build.ts b/src/build.ts index 86d1165..016b64f 100644 --- a/src/build.ts +++ b/src/build.ts @@ -124,7 +124,7 @@ async function build(args: string[]) { // write tutorial if (tutorial) { try { - await write(options.output, JSON.stringify(tutorial), "utf8"); + await write(options.output, JSON.stringify(tutorial, null, 2), "utf8"); console.info(`Success! See output at ${options.output}`); } catch (e) { console.error("Error writing tutorial json file:");