Skip to content

Commit 0db2cec

Browse files
committed
refactor: break out logic to function
1 parent eef2ea0 commit 0db2cec

1 file changed

Lines changed: 29 additions & 24 deletions

File tree

src/extension.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,40 @@ async function _handleRepo(git: API) {
3636
await makeAndFillCommitMsg(targetRepo);
3737
}
3838

39+
async function _chooseRepoForAutofill(uri?: vscode.Uri): Promise<void> {
40+
const git = getGitExtension();
41+
42+
if (!git) {
43+
vscode.window.showErrorMessage("Unable to load Git Extension");
44+
return;
45+
}
46+
47+
if (git.repositories.length === 0) {
48+
vscode.window.showErrorMessage(
49+
"No repos found. Please open a repo or run `git init` then try this extension again."
50+
);
51+
return;
52+
}
53+
54+
vscode.commands.executeCommand("workbench.view.scm");
55+
56+
if (uri) {
57+
_handleRepos(git, uri);
58+
} else {
59+
_handleRepo(git);
60+
}
61+
}
62+
3963
/**
40-
* Set up the autofill command to run when triggered.
64+
* Set up the extension activation.
65+
*
66+
* The autofill command as configured in `package.json` will be triggered
67+
* and run the autofill logic for a repo.
4168
*/
4269
export function activate(context: vscode.ExtensionContext) {
4370
const disposable = vscode.commands.registerCommand(
4471
"commitMsg.autofill",
45-
async (uri?) => {
46-
const git = getGitExtension();
47-
48-
if (!git) {
49-
vscode.window.showErrorMessage("Unable to load Git Extension");
50-
return;
51-
}
52-
53-
if (git.repositories.length === 0) {
54-
vscode.window.showErrorMessage(
55-
"No repos found. Please open a repo or run git init then try this extension again."
56-
);
57-
return;
58-
}
59-
60-
vscode.commands.executeCommand("workbench.view.scm");
61-
62-
if (uri) {
63-
_handleRepos(git, uri);
64-
} else {
65-
_handleRepo(git);
66-
}
67-
}
72+
_chooseRepoForAutofill
6873
);
6974

7075
context.subscriptions.push(disposable);

0 commit comments

Comments
 (0)