format files

This commit is contained in:
di-sukharev
2023-07-05 15:13:30 +08:00
parent 897eb73cd7
commit 028c0bc518
3 changed files with 147 additions and 148 deletions
+8 -8
View File
@@ -1,7 +1,5 @@
import { execa } from 'execa';
import {
generateCommitMessageByDiff
} from '../generateCommitMessageFromGitDiff';
import { generateCommitMessageByDiff } from '../generateCommitMessageFromGitDiff';
import {
assertGitRepo,
getChangedFiles,
@@ -18,9 +16,7 @@ import {
multiselect,
select
} from '@clack/prompts';
import {
getConfig
} from '../commands/config';
import { getConfig } from '../commands/config';
import chalk from 'chalk';
import { trytm } from '../utils/trytm';
@@ -34,7 +30,8 @@ const getGitRemotes = async () => {
// Check for the presence of message templates
const checkMessageTemplate = (extraArgs: string[]): string | false => {
for (const key in extraArgs) {
if(extraArgs[key].includes(config?.OCO_MESSAGE_TEMPLATE_PLACEHOLDER)) return extraArgs[key];
if (extraArgs[key].includes(config?.OCO_MESSAGE_TEMPLATE_PLACEHOLDER))
return extraArgs[key];
}
return false;
};
@@ -52,7 +49,10 @@ const generateCommitMessageFromGitDiff = async (
let commitMessage = await generateCommitMessageByDiff(diff);
if (typeof messageTemplate === 'string') {
commitMessage = messageTemplate.replace(config?.OCO_MESSAGE_TEMPLATE_PLACEHOLDER, commitMessage);
commitMessage = messageTemplate.replace(
config?.OCO_MESSAGE_TEMPLATE_PLACEHOLDER,
commitMessage
);
}
commitSpinner.stop('📝 Commit message generated');
+6 -7
View File
@@ -84,10 +84,11 @@ export const generateCommitMessageByDiff = async (
diff: string
): Promise<string> => {
try {
const MAX_REQUEST_TOKENS = DEFAULT_MODEL_TOKEN_LIMIT
- ADJUSTMENT_FACTOR
- INIT_MESSAGES_PROMPT_LENGTH
- config?.OCO_OPENAI_MAX_TOKENS;
const MAX_REQUEST_TOKENS =
DEFAULT_MODEL_TOKEN_LIMIT -
ADJUSTMENT_FACTOR -
INIT_MESSAGES_PROMPT_LENGTH -
config?.OCO_OPENAI_MAX_TOKENS;
if (tokenCount(diff) >= MAX_REQUEST_TOKENS) {
const commitMessagePromises = getCommitMsgsPromisesFromFileDiffs(
@@ -154,7 +155,6 @@ function getMessagesPromisesByChangesInFile(
return commitMsgsFromFileLineDiffs;
}
function splitDiff(diff: string, maxChangeLength: number) {
const lines = diff.split('\n');
const splitDiffs = [];
@@ -219,10 +219,9 @@ export function getCommitMsgsPromisesFromFileDiffs(
}
}
return commitMessagePromises;
}
function delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
return new Promise((resolve) => setTimeout(resolve, ms));
}
+1 -1
View File
@@ -36,7 +36,7 @@ export enum I18nLocals {
'id_ID' = 'id_ID',
'pl' = 'pl',
'tr' = 'tr',
'th' = 'th',
'th' = 'th'
}
export const i18n = {