Skip to content

Commit 9d2ff86

Browse files
authored
Git - Track attempt count in the test commit message provider (microsoft#196348)
1 parent cf94c5d commit 9d2ff86

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

extensions/git/src/commitMessageProvider.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ export class TestCommitMessageProvider implements CommitMessageProvider {
2020
readonly icon = new ThemeIcon('rocket');
2121
readonly title = 'Generate Commit Message (Test)';
2222

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> {
2426
console.log('Repository: ', repository.rootUri.fsPath);
2527

2628
if (token.isCancellationRequested) {
@@ -29,9 +31,31 @@ export class TestCommitMessageProvider implements CommitMessageProvider {
2931

3032
return new Promise(resolve => {
3133
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);
3341
});
3442
}
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+
3559
}
3660

3761
interface ActionButtonState {

0 commit comments

Comments
 (0)