Skip to content
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

Git - Track attempt count in the test commit message provider #196348

Merged
merged 1 commit into from Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 26 additions & 2 deletions extensions/git/src/commitMessageProvider.ts
Expand Up @@ -20,7 +20,9 @@ export class TestCommitMessageProvider implements CommitMessageProvider {
readonly icon = new ThemeIcon('rocket');
readonly title = 'Generate Commit Message (Test)';

async provideCommitMessage(repository: ApiRepository, _: string[], token: CancellationToken): Promise<string | undefined> {
private readonly _changesMap = new Map<string, [string[], number]>();

async provideCommitMessage(repository: ApiRepository, changes: string[], token: CancellationToken): Promise<string | undefined> {
console.log('Repository: ', repository.rootUri.fsPath);

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

return new Promise(resolve => {
token.onCancellationRequested(() => resolve(undefined));
setTimeout(() => resolve(`Test commit message (${Math.random()})`), 5000);

setTimeout(() => {
const attemptCount = this.getAttemptCount(repository, changes);
this._changesMap.set(repository.rootUri.fsPath, [changes, attemptCount]);

resolve(`Test commit message (Attempt No. ${attemptCount})`);
}, 5000);
});
}

private getAttemptCount(repository: ApiRepository, changes: string[]): number {
const [previousChanges, previousCount] = this._changesMap.get(repository.rootUri.fsPath) ?? [[], 1];
if (previousChanges.length !== changes.length) {
return 1;
}

for (let index = 0; index < changes.length; index++) {
if (previousChanges[index] !== changes[index]) {
return 1;
}
}

return previousCount + 1;
}

}

interface ActionButtonState {
Expand Down