Skip to content

Feature handle build issues #15

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
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
return to original branch even in failure
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed May 31, 2020
commit c8e9721639559c0e2fb7597855f9a399935b77bf
60 changes: 32 additions & 28 deletions src/utils/commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
/^(?<stepId>(?<levelId>L\d+)(S\d+))(?<stepType>[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(
/^(?<stepId>(?<levelId>L\d+)(S\d+))(?<stepType>[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;
}
2 changes: 1 addition & 1 deletion src/utils/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
},
],
},
Expand Down