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
+10 -10
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';
@@ -33,8 +29,9 @@ 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];
for (const key in extraArgs) {
if (extraArgs[key].includes(config?.OCO_MESSAGE_TEMPLATE_PLACEHOLDER))
return extraArgs[key];
}
return false;
};
@@ -51,8 +48,11 @@ const generateCommitMessageFromGitDiff = async (
try {
let commitMessage = await generateCommitMessageByDiff(diff);
if(typeof messageTemplate === 'string'){
commitMessage = messageTemplate.replace(config?.OCO_MESSAGE_TEMPLATE_PLACEHOLDER, commitMessage);
if (typeof messageTemplate === 'string') {
commitMessage = messageTemplate.replace(
config?.OCO_MESSAGE_TEMPLATE_PLACEHOLDER,
commitMessage
);
}
commitSpinner.stop('📝 Commit message generated');
+11 -12
View File
@@ -2,11 +2,11 @@ import {
ChatCompletionRequestMessage,
ChatCompletionRequestMessageRoleEnum
} from 'openai';
import {api} from './api';
import {DEFAULT_MODEL_TOKEN_LIMIT, getConfig} from './commands/config';
import {mergeDiffs} from './utils/mergeDiffs';
import {i18n, I18nLocals} from './i18n';
import {tokenCount} from './utils/tokenCount';
import { api } from './api';
import { DEFAULT_MODEL_TOKEN_LIMIT, getConfig } from './commands/config';
import { mergeDiffs } from './utils/mergeDiffs';
import { i18n, I18nLocals } from './i18n';
import { tokenCount } from './utils/tokenCount';
const config = getConfig();
const translation = i18n[(config?.OCO_LANGUAGE as I18nLocals) || 'en'];
@@ -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 = {