Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf6159c4

Browse files
committed
validate commits
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parentdeba9b3 commitf6159c4

File tree

2 files changed

+26
-61
lines changed

2 files changed

+26
-61
lines changed

‎src/utils/validateCommits.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,28 @@ export function validateCommitOrder(positions: string[]): boolean {
1414
return;
1515
}else{
1616
//@deprecate - remove L|Q
17-
constlevelMatch=position.match(/^L?([0-9]+)[Q|T]?$/);
17+
constlevelMatch=position.match(/^(?<level>[0-9]+)$/);
1818
//@deprecate - remove S|Q|A
19-
conststepMatch=position.match(/^L?([0-9]+)[S|\.]([0-9]+)[Q|A|T|S]?$/);
19+
conststepMatch=position.match(
20+
/^(?<level>[0-9]+)\.(?<step>[0-9]+):[T|S]$/
21+
);
2022
if(levelMatch){
2123
// allows next level or step
22-
const[_,levelString]=levelMatch;
24+
constlevelString=levelMatch?.groups?.level;
25+
if(!levelString){
26+
console.warn(`No commit level match for${position}`);
27+
return;
28+
}
2329
constlevel=Number(levelString);
2430
current={ level,step:0};
2531
}elseif(stepMatch){
2632
// allows next level or step
27-
const[_,levelString,stepString]=stepMatch;
33+
if(!stepMatch?.groups?.level||!stepMatch?.groups.step){
34+
console.warn(`No commit step match for${position}`);
35+
return;
36+
}
37+
const{level:levelString,step:stepString}=stepMatch.groups;
38+
2839
constlevel=Number(levelString);
2940
conststep=Number(stepString);
3041
current={ level, step};

‎tests/commitOrder.test.ts

Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { validateCommitOrder } from "../src/utils/validateCommits";
33
describe("commitOrder",()=>{
44
describe("#.# format",()=>{
55
it("should return true if order is valid",()=>{
6-
constpositions=["INIT","1","1.1","1.2","2","2.1"];
6+
constpositions=["INIT","1","1.1:T","1.2:T","2","2.1:T"];
77
constresult=validateCommitOrder(positions);
88
expect(result).toBe(true);
99
});
@@ -13,81 +13,35 @@ describe("commitOrder", () => {
1313
"INIT",
1414
"1",
1515
"1",
16-
"1.1",
17-
"1.1",
18-
"1.2",
19-
"1.2",
16+
"1.1:T",
17+
"1.1:S",
18+
"1.2:T",
19+
"1.2:S",
2020
"2",
2121
"2",
22-
"2.1",
23-
"2.1",
22+
"2.1:T",
23+
"2.1:S",
2424
];
2525
constresult=validateCommitOrder(positions);
2626
expect(result).toBe(true);
2727
});
2828
it("should return false if INIT is out of order",()=>{
29-
constpositions=["INIT","1","1.1","1.2","INIT","2","2.1"];
29+
constpositions=["INIT","1","1.1:T","1.2:T","INIT","2","2.1:T"];
3030
constresult=validateCommitOrder(positions);
3131
expect(result).toBe(false);
3232
});
3333
it("should return false if level after step is out of order",()=>{
34-
constpositions=["INIT","1","1.1","1.2","2.1","2"];
34+
constpositions=["INIT","1","1.1:T","1.2:T","2.1:T","2"];
3535
constresult=validateCommitOrder(positions);
3636
expect(result).toBe(false);
3737
});
3838
it("should return false if level is out of order",()=>{
39-
constpositions=["INIT","1","L3","2"];
39+
constpositions=["INIT","1","3","2"];
4040
constresult=validateCommitOrder(positions);
4141
expect(result).toBe(false);
4242
});
4343
it("should return false if step is out of order",()=>{
44-
constpositions=["INIT","1","1.1","1.3","1.2"];
45-
constresult=validateCommitOrder(positions);
46-
expect(result).toBe(false);
47-
});
48-
});
49-
//@deprecated
50-
describe("L#S# format",()=>{
51-
it("should return true if order is valid",()=>{
52-
constpositions=["INIT","L1","L1S1","L1S2","L2","L2S1"];
53-
constresult=validateCommitOrder(positions);
54-
expect(result).toBe(true);
55-
});
56-
it("should return true if valid with duplicates",()=>{
57-
constpositions=[
58-
"INIT",
59-
"INIT",
60-
"L1",
61-
"L1",
62-
"L1S1",
63-
"L1S1",
64-
"L1S2",
65-
"L1S2",
66-
"L2",
67-
"L2",
68-
"L2S1",
69-
"L2S1",
70-
];
71-
constresult=validateCommitOrder(positions);
72-
expect(result).toBe(true);
73-
});
74-
it("should return false if INIT is out of order",()=>{
75-
constpositions=["INIT","L1","L1S1","L1S2","INIT","L2","L2S1"];
76-
constresult=validateCommitOrder(positions);
77-
expect(result).toBe(false);
78-
});
79-
it("should return false if level after step is out of order",()=>{
80-
constpositions=["INIT","L1","L1S1","L1S2","L2S1","L2"];
81-
constresult=validateCommitOrder(positions);
82-
expect(result).toBe(false);
83-
});
84-
it("should return false if level is out of order",()=>{
85-
constpositions=["INIT","L1","L3","L2"];
86-
constresult=validateCommitOrder(positions);
87-
expect(result).toBe(false);
88-
});
89-
it("should return false if step is out of order",()=>{
90-
constpositions=["INIT","L1","L1S1","L1S3","L1S2"];
44+
constpositions=["INIT","1","1.1:T","1.3:T","1.2:T"];
9145
constresult=validateCommitOrder(positions);
9246
expect(result).toBe(false);
9347
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp