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
validate commits
Signed-off-by: shmck <[email protected]>
  • Loading branch information
ShMcK committed Jun 24, 2020
commit f6159c443f254caf2b9aa28191240d6ec981c8ef
19 changes: 15 additions & 4 deletions src/utils/validateCommits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,28 @@ export function validateCommitOrder(positions: string[]): boolean {
return;
} else {
// @deprecate - remove L|Q
const levelMatch = position.match(/^L?([0-9]+)[Q|T]?$/);
const levelMatch = position.match(/^(?<level>[0-9]+)$/);
// @deprecate - remove S|Q|A
const stepMatch = position.match(/^L?([0-9]+)[S|\.]([0-9]+)[Q|A|T|S]?$/);
const stepMatch = position.match(
/^(?<level>[0-9]+)\.(?<step>[0-9]+):[T|S]$/
);
if (levelMatch) {
// allows next level or step
const [_, levelString] = levelMatch;
const levelString = levelMatch?.groups?.level;
if (!levelString) {
console.warn(`No commit level match for ${position}`);
return;
}
const level = Number(levelString);
current = { level, step: 0 };
} else if (stepMatch) {
// allows next level or step
const [_, levelString, stepString] = stepMatch;
if (!stepMatch?.groups?.level || !stepMatch?.groups.step) {
console.warn(`No commit step match for ${position}`);
return;
}
const { level: levelString, step: stepString } = stepMatch.groups;

const level = Number(levelString);
const step = Number(stepString);
current = { level, step };
Expand Down
68 changes: 11 additions & 57 deletions tests/commitOrder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { validateCommitOrder } from "../src/utils/validateCommits";
describe("commitOrder", () => {
describe("#.# format", () => {
it("should return true if order is valid", () => {
const positions = ["INIT", "1", "1.1", "1.2", "2", "2.1"];
const positions = ["INIT", "1", "1.1:T", "1.2:T", "2", "2.1:T"];
const result = validateCommitOrder(positions);
expect(result).toBe(true);
});
Expand All @@ -13,81 +13,35 @@ describe("commitOrder", () => {
"INIT",
"1",
"1",
"1.1",
"1.1",
"1.2",
"1.2",
"1.1:T",
"1.1:S",
"1.2:T",
"1.2:S",
"2",
"2",
"2.1",
"2.1",
"2.1:T",
"2.1:S",
];
const result = validateCommitOrder(positions);
expect(result).toBe(true);
});
it("should return false if INIT is out of order", () => {
const positions = ["INIT", "1", "1.1", "1.2", "INIT", "2", "2.1"];
const positions = ["INIT", "1", "1.1:T", "1.2:T", "INIT", "2", "2.1:T"];
const result = validateCommitOrder(positions);
expect(result).toBe(false);
});
it("should return false if level after step is out of order", () => {
const positions = ["INIT", "1", "1.1", "1.2", "2.1", "2"];
const positions = ["INIT", "1", "1.1:T", "1.2:T", "2.1:T", "2"];
const result = validateCommitOrder(positions);
expect(result).toBe(false);
});
it("should return false if level is out of order", () => {
const positions = ["INIT", "1", "L3", "2"];
const positions = ["INIT", "1", "3", "2"];
const result = validateCommitOrder(positions);
expect(result).toBe(false);
});
it("should return false if step is out of order", () => {
const positions = ["INIT", "1", "1.1", "1.3", "1.2"];
const result = validateCommitOrder(positions);
expect(result).toBe(false);
});
});
// @deprecated
describe("L#S# format", () => {
it("should return true if order is valid", () => {
const positions = ["INIT", "L1", "L1S1", "L1S2", "L2", "L2S1"];
const result = validateCommitOrder(positions);
expect(result).toBe(true);
});
it("should return true if valid with duplicates", () => {
const positions = [
"INIT",
"INIT",
"L1",
"L1",
"L1S1",
"L1S1",
"L1S2",
"L1S2",
"L2",
"L2",
"L2S1",
"L2S1",
];
const result = validateCommitOrder(positions);
expect(result).toBe(true);
});
it("should return false if INIT is out of order", () => {
const positions = ["INIT", "L1", "L1S1", "L1S2", "INIT", "L2", "L2S1"];
const result = validateCommitOrder(positions);
expect(result).toBe(false);
});
it("should return false if level after step is out of order", () => {
const positions = ["INIT", "L1", "L1S1", "L1S2", "L2S1", "L2"];
const result = validateCommitOrder(positions);
expect(result).toBe(false);
});
it("should return false if level is out of order", () => {
const positions = ["INIT", "L1", "L3", "L2"];
const result = validateCommitOrder(positions);
expect(result).toBe(false);
});
it("should return false if step is out of order", () => {
const positions = ["INIT", "L1", "L1S1", "L1S3", "L1S2"];
const positions = ["INIT", "1", "1.1:T", "1.3:T", "1.2:T"];
const result = validateCommitOrder(positions);
expect(result).toBe(false);
});
Expand Down