Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feature/markdown as master #48

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 17 commits into from
Jun 24, 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
setup commit parsing for testing
Signed-off-by: shmck <[email protected]>
  • Loading branch information
ShMcK committed Jun 23, 2020
commit 692cb660b744920aed3c470c96125d5e9e45cb58
80 changes: 43 additions & 37 deletions src/utils/commits.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from "fs";
import util from "util";
import * as path from "path";
import { ListLogSummary } from "simple-git/typings/response";
import gitP, { SimpleGit } from "simple-git/promise";
import { validateCommitOrder } from "./validateCommits";

Expand All @@ -15,6 +16,44 @@ type GetCommitOptions = {

export type CommitLogObject = { [position: string]: string[] };

export function parseCommits(logs: ListLogSummary<any>) {
// Filter relevant logs
const commits: CommitLogObject = {};
const positions: string[] = [];

for (const commit of logs.all) {
const matches = commit.message.match(
/^(?<stepId>(?<levelId>L?\d+)([S|\.]\d+))(?<stepType>[Q|A|T|S])?/
);

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].unshift(commit.hash);
}
positions.unshift(position);
} 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.unshift(commit.hash);
}
positions.unshift("INIT");
}
}
}
return { commits, positions };
}

export async function getCommits({
localDir,
codeBranch,
Expand Down Expand Up @@ -49,48 +88,19 @@ export async function getCommits({
// track the original branch in case of failure
const originalBranch = branches.current;

// Filter relevant logs
const commits: CommitLogObject = {};

try {
// Checkout the code branches
await git.checkout(codeBranch);

// Load all logs
const logs = await git.log();
const positions: string[] = [];

for (const commit of logs.all) {
const matches = commit.message.match(
/^(?<stepId>(?<levelId>L?\d+)([S|\.]\d+))(?<stepType>[QA])?/
);
const { commits, positions } = parseCommits(logs);

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].unshift(commit.hash);
}
positions.unshift(position);
} 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.unshift(commit.hash);
}
positions.unshift("INIT");
}
}
}
// validate order
validateCommitOrder(positions);

return commits;
} catch (e) {
console.error("Error with checkout or commit matching");
throw new Error(e.message);
Expand All @@ -100,8 +110,4 @@ export async function getCommits({
// cleanup the tmp directory
await rmdir(tmpDir, { recursive: true });
}

console.log(commits);

return commits;
}
8 changes: 8 additions & 0 deletions src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ export function parse(params: ParseParams): any {
level.setup.commits = params.commits[level.id];
}

// @deprecated L1 system
if (params.commits[`L${level.id}`]) {
if (!level.setup) {
level.setup = {};
}
level.setup.commits = params.commits[`L${level.id}`];
}

return level;
}
);
Expand Down
6 changes: 4 additions & 2 deletions src/utils/validateCommits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export function validateCommitOrder(positions: string[]): boolean {
current = { level: 0, step: 0 };
return;
} else {
const levelMatch = position.match(/^L?([0-9]+)Q?$/);
const stepMatch = position.match(/^L?([0-9]+)[S|\.]([0-9]+)[Q|A]?$/);
// @deprecate - remove L|Q
const levelMatch = position.match(/^L?([0-9]+)[Q|T]?$/);
// @deprecate - remove S|Q|A
const stepMatch = position.match(/^L?([0-9]+)[S|\.]([0-9]+)[Q|A|T|S]?$/);
if (levelMatch) {
// allows next level or step
const [_, levelString] = levelMatch;
Expand Down