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

Commit692cb66

Browse files
committed
setup commit parsing for testing
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent8558b8e commit692cb66

File tree

3 files changed

+55
-39
lines changed

3 files changed

+55
-39
lines changed

‎src/utils/commits.ts

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import*asfsfrom"fs";
22
importutilfrom"util";
33
import*aspathfrom"path";
4+
import{ListLogSummary}from"simple-git/typings/response";
45
importgitP,{SimpleGit}from"simple-git/promise";
56
import{validateCommitOrder}from"./validateCommits";
67

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

1617
exporttypeCommitLogObject={[position:string]:string[]};
1718

19+
exportfunctionparseCommits(logs:ListLogSummary<any>){
20+
// Filter relevant logs
21+
constcommits:CommitLogObject={};
22+
constpositions:string[]=[];
23+
24+
for(constcommitoflogs.all){
25+
constmatches=commit.message.match(
26+
/^(?<stepId>(?<levelId>L?\d+)([S|\.]\d+))(?<stepType>[Q|A|T|S])?/
27+
);
28+
29+
if(matches&&matches.length){
30+
// Use an object of commit arrays to collect all commits
31+
constposition=matches[0];
32+
if(!commits[position]){
33+
// does not exist, create the list
34+
commits[position]=[commit.hash];
35+
}else{
36+
// add to the list
37+
commits[position].unshift(commit.hash);
38+
}
39+
positions.unshift(position);
40+
}else{
41+
constinitMatches=commit.message.match(/^INIT/);
42+
if(initMatches&&initMatches.length){
43+
if(!commits.INIT){
44+
// does not exist, create the list
45+
commits.INIT=[commit.hash];
46+
}else{
47+
// add to the list
48+
commits.INIT.unshift(commit.hash);
49+
}
50+
positions.unshift("INIT");
51+
}
52+
}
53+
}
54+
return{ commits, positions};
55+
}
56+
1857
exportasyncfunctiongetCommits({
1958
localDir,
2059
codeBranch,
@@ -49,48 +88,19 @@ export async function getCommits({
4988
// track the original branch in case of failure
5089
constoriginalBranch=branches.current;
5190

52-
// Filter relevant logs
53-
constcommits:CommitLogObject={};
54-
5591
try{
5692
// Checkout the code branches
5793
awaitgit.checkout(codeBranch);
5894

5995
// Load all logs
6096
constlogs=awaitgit.log();
61-
constpositions:string[]=[];
6297

63-
for(constcommitoflogs.all){
64-
constmatches=commit.message.match(
65-
/^(?<stepId>(?<levelId>L?\d+)([S|\.]\d+))(?<stepType>[QA])?/
66-
);
98+
const{ commits, positions}=parseCommits(logs);
6799

68-
if(matches&&matches.length){
69-
// Use an object of commit arrays to collect all commits
70-
constposition=matches[0];
71-
if(!commits[position]){
72-
// does not exist, create the list
73-
commits[position]=[commit.hash];
74-
}else{
75-
// add to the list
76-
commits[position].unshift(commit.hash);
77-
}
78-
positions.unshift(position);
79-
}else{
80-
constinitMatches=commit.message.match(/^INIT/);
81-
if(initMatches&&initMatches.length){
82-
if(!commits.INIT){
83-
// does not exist, create the list
84-
commits.INIT=[commit.hash];
85-
}else{
86-
// add to the list
87-
commits.INIT.unshift(commit.hash);
88-
}
89-
positions.unshift("INIT");
90-
}
91-
}
92-
}
100+
// validate order
93101
validateCommitOrder(positions);
102+
103+
returncommits;
94104
}catch(e){
95105
console.error("Error with checkout or commit matching");
96106
thrownewError(e.message);
@@ -100,8 +110,4 @@ export async function getCommits({
100110
// cleanup the tmp directory
101111
awaitrmdir(tmpDir,{recursive:true});
102112
}
103-
104-
console.log(commits);
105-
106-
returncommits;
107113
}

‎src/utils/parse.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ export function parse(params: ParseParams): any {
187187
level.setup.commits=params.commits[level.id];
188188
}
189189

190+
//@deprecated L1 system
191+
if(params.commits[`L${level.id}`]){
192+
if(!level.setup){
193+
level.setup={};
194+
}
195+
level.setup.commits=params.commits[`L${level.id}`];
196+
}
197+
190198
returnlevel;
191199
}
192200
);

‎src/utils/validateCommits.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ export function validateCommitOrder(positions: string[]): boolean {
1313
current={level:0,step:0};
1414
return;
1515
}else{
16-
constlevelMatch=position.match(/^L?([0-9]+)Q?$/);
17-
conststepMatch=position.match(/^L?([0-9]+)[S|\.]([0-9]+)[Q|A]?$/);
16+
//@deprecate - remove L|Q
17+
constlevelMatch=position.match(/^L?([0-9]+)[Q|T]?$/);
18+
//@deprecate - remove S|Q|A
19+
conststepMatch=position.match(/^L?([0-9]+)[S|\.]([0-9]+)[Q|A|T|S]?$/);
1820
if(levelMatch){
1921
// allows next level or step
2022
const[_,levelString]=levelMatch;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp