@@ -20,7 +20,9 @@ export class TestCommitMessageProvider implements CommitMessageProvider {
20
20
readonly icon = new ThemeIcon ( 'rocket' ) ;
21
21
readonly title = 'Generate Commit Message (Test)' ;
22
22
23
- async provideCommitMessage ( repository : ApiRepository , _ : string [ ] , token : CancellationToken ) : Promise < string | undefined > {
23
+ private readonly _changesMap = new Map < string , [ string [ ] , number ] > ( ) ;
24
+
25
+ async provideCommitMessage ( repository : ApiRepository , changes : string [ ] , token : CancellationToken ) : Promise < string | undefined > {
24
26
console . log ( 'Repository: ' , repository . rootUri . fsPath ) ;
25
27
26
28
if ( token . isCancellationRequested ) {
@@ -29,9 +31,31 @@ export class TestCommitMessageProvider implements CommitMessageProvider {
29
31
30
32
return new Promise ( resolve => {
31
33
token . onCancellationRequested ( ( ) => resolve ( undefined ) ) ;
32
- setTimeout ( ( ) => resolve ( `Test commit message (${ Math . random ( ) } )` ) , 5000 ) ;
34
+
35
+ setTimeout ( ( ) => {
36
+ const attemptCount = this . getAttemptCount ( repository , changes ) ;
37
+ this . _changesMap . set ( repository . rootUri . fsPath , [ changes , attemptCount ] ) ;
38
+
39
+ resolve ( `Test commit message (Attempt No. ${ attemptCount } )` ) ;
40
+ } , 5000 ) ;
33
41
} ) ;
34
42
}
43
+
44
+ private getAttemptCount ( repository : ApiRepository , changes : string [ ] ) : number {
45
+ const [ previousChanges , previousCount ] = this . _changesMap . get ( repository . rootUri . fsPath ) ?? [ [ ] , 1 ] ;
46
+ if ( previousChanges . length !== changes . length ) {
47
+ return 1 ;
48
+ }
49
+
50
+ for ( let index = 0 ; index < changes . length ; index ++ ) {
51
+ if ( previousChanges [ index ] !== changes [ index ] ) {
52
+ return 1 ;
53
+ }
54
+ }
55
+
56
+ return previousCount + 1 ;
57
+ }
58
+
35
59
}
36
60
37
61
interface ActionButtonState {
0 commit comments