|
1 |
| -import { isEmpty } from "lodash"; |
2 | 1 | import * as vscode from "vscode";
|
3 | 2 | import { setApiKeyCommand } from ".";
|
4 |
| -import { GitExtension } from "../types/vscode"; |
5 |
| - |
6 |
| -import { getDeepLApiKey } from "../utils/getDeepLApiKey"; |
7 |
| -import { getTranslatedCommitMessage } from "../utils/getTranslatedCommitMessage"; |
8 |
| -import { |
9 |
| - activateGitExtension, |
10 |
| - getSingleRepository, |
11 |
| - isGitExtensionValidate, |
12 |
| -} from "../utils/gitExtension"; |
13 |
| -import validateString from "../utils/validateString"; |
| 3 | +import { isGitExtensionValid, activateGitExtension, getSingleRepository } from "../utils/git"; |
| 4 | +import getTranslatedCommitMessage from "../utils/getTranslatedCommitMessage"; |
| 5 | +import getDeepLApiKey from "../utils/getDeepLApiKey"; |
| 6 | +import isStringValid from "../utils/isStringValid"; |
| 7 | +import { isEmpty } from "lodash"; |
| 8 | +import getGitExtension from "../utils/git/getGitExtension"; |
14 | 9 |
|
15 | 10 | export async function translateCommitCommand() {
|
16 |
| - /** 1. (success) check if git extension is valid */ |
17 |
| - const gitExtension = |
18 |
| - vscode.extensions.getExtension<GitExtension>("vscode.git"); |
19 |
| - if (!isGitExtensionValidate(gitExtension)) { |
| 11 | + /** 1. check if git extension is valid & activate git extension*/ |
| 12 | + const gitExtension = getGitExtension(); |
| 13 | + if (!isGitExtensionValid(gitExtension)) { |
20 | 14 | return;
|
21 | 15 | }
|
22 | 16 | await activateGitExtension(gitExtension);
|
23 | 17 |
|
24 |
| - /** 2. (success ?) check if apiKey is valid */ |
25 |
| - let apikey: string | undefined = getDeepLApiKey(); |
26 |
| - if (!validateString(apikey)) { |
27 |
| - apikey = await setApiKeyCommand(); |
28 |
| - // vscode.window.showInformationMessage(apikey as string); |
29 |
| - // await vscode.commands.executeCommand(Commands.SetApiKey); |
| 18 | + /** 2. check if apiKey exists*/ |
| 19 | + let apiKey = getDeepLApiKey(); |
| 20 | + if (!isStringValid(apiKey)) { |
| 21 | + apiKey = await setApiKeyCommand(); |
30 | 22 | }
|
31 | 23 |
|
32 |
| - // if (!isValidateApiKey()) { |
33 |
| - // vscode.window.showInformationMessage("api key is invalid"); |
34 |
| - // return; |
35 |
| - // vscode.window.showInformationMessage(apikey as string); |
36 |
| - // await vscode.commands.executeCommand(Commands.SetApiKey); |
37 |
| - // } |
| 24 | + if (!isStringValid(apiKey)) { |
| 25 | + return; |
| 26 | + } |
38 | 27 |
|
39 |
| - /** 3. (success) get repository from git */ |
| 28 | + /** 3. get repository from git */ |
40 | 29 | const repository = getSingleRepository(gitExtension);
|
41 | 30 |
|
42 |
| - /** 4. (success) get commit from repository */ |
| 31 | + /** 4. get commit from repository */ |
43 | 32 | const commit = repository.inputBox.value;
|
44 | 33 | if (isEmpty(commit)) {
|
45 | 34 | vscode.window.showErrorMessage("Commit message is empty");
|
46 | 35 | return;
|
47 | 36 | }
|
48 |
| - /** 5. (success) translate commit message with Deepl api */ |
| 37 | + |
| 38 | + /** 5. translate commit message with Deepl api */ |
49 | 39 | const translatedMessage = await getTranslatedCommitMessage({
|
50 |
| - apikey: apikey as string, |
51 | 40 | commit,
|
| 41 | + apiKey, |
52 | 42 | });
|
53 | 43 |
|
54 |
| - /** 6. (success) log translated commit */ |
| 44 | + /** 6. log translated commit */ |
55 | 45 | repository.inputBox.value = translatedMessage;
|
56 | 46 | }
|
0 commit comments