mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-04-20 03:02:51 -04:00
feat(config): rename OCO_OPENAI_API_KEY to OCO_API_KEY for consistency and clarity
fix(config): add validation for OCO_WHY configuration key to ensure it is a boolean refactor(config): extract default config setting logic into setDefaultConfigValues function fix(cli): reorder function calls to ensure checkIsLatestVersion runs after runMigrations chore(migrations): update getConfig calls to disable caching and default value setting chore(migrations): remove obsolete configuration keys from global config file fix(migrations): improve migration logging with consistent output formatting style(migrations): enhance migration success and failure messages for better user feedback
This commit is contained in:
@@ -387,7 +387,7 @@ jobs:
|
||||
# set openAI api key in repo actions secrets,
|
||||
# for openAI keys go to: https://platform.openai.com/account/api-keys
|
||||
# for repo secret go to: <your_repo_url>/settings/secrets/actions
|
||||
OCO_OPENAI_API_KEY: ${{ secrets.OCO_OPENAI_API_KEY }}
|
||||
OCO_API_KEY: ${{ secrets.OCO_API_KEY }}
|
||||
|
||||
# customization
|
||||
OCO_TOKENS_MAX_INPUT: 4096
|
||||
|
||||
120
out/cli.cjs
120
out/cli.cjs
@@ -30074,6 +30074,14 @@ var configValidators = {
|
||||
).join(", ")}`
|
||||
);
|
||||
return value;
|
||||
},
|
||||
["OCO_WHY" /* OCO_WHY */](value) {
|
||||
validateConfig(
|
||||
"OCO_WHY" /* OCO_WHY */,
|
||||
typeof value === "boolean",
|
||||
"Must be true or false"
|
||||
);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
var OCO_AI_PROVIDER_ENUM = /* @__PURE__ */ ((OCO_AI_PROVIDER_ENUM2) => {
|
||||
@@ -30122,11 +30130,9 @@ var getEnvConfig = (envPath) => {
|
||||
OCO_API_URL: process.env.OCO_API_URL,
|
||||
OCO_API_KEY: process.env.OCO_API_KEY,
|
||||
OCO_AI_PROVIDER: process.env.OCO_AI_PROVIDER,
|
||||
OCO_TOKENS_MAX_INPUT: parseConfigVarValue(
|
||||
process.env.OCO_TOKENS_MAX_INPUT ?? 40960 /* DEFAULT_MAX_TOKENS_INPUT */
|
||||
),
|
||||
OCO_TOKENS_MAX_INPUT: parseConfigVarValue(process.env.OCO_TOKENS_MAX_INPUT),
|
||||
OCO_TOKENS_MAX_OUTPUT: parseConfigVarValue(
|
||||
process.env.OCO_TOKENS_MAX_OUTPUT ?? 4096 /* DEFAULT_MAX_TOKENS_OUTPUT */
|
||||
process.env.OCO_TOKENS_MAX_OUTPUT
|
||||
),
|
||||
OCO_DESCRIPTION: parseConfigVarValue(process.env.OCO_DESCRIPTION),
|
||||
OCO_EMOJI: parseConfigVarValue(process.env.OCO_EMOJI),
|
||||
@@ -30138,7 +30144,19 @@ var getEnvConfig = (envPath) => {
|
||||
OCO_GITPUSH: parseConfigVarValue(process.env.OCO_GITPUSH)
|
||||
};
|
||||
};
|
||||
var getGlobalConfig = (configPath) => {
|
||||
var setDefaultConfigValues = (config7) => {
|
||||
const entriesToSet = [];
|
||||
for (const entry of Object.entries(DEFAULT_CONFIG)) {
|
||||
const [key, _value] = entry;
|
||||
if (config7[key] === "undefined")
|
||||
entriesToSet.push(entry);
|
||||
}
|
||||
setConfig(entriesToSet);
|
||||
};
|
||||
var setGlobalConfig = (config7, configPath = defaultConfigPath) => {
|
||||
(0, import_fs.writeFileSync)(configPath, (0, import_ini.stringify)(config7), "utf8");
|
||||
};
|
||||
var getGlobalConfig = (configPath = defaultConfigPath) => {
|
||||
let globalConfig;
|
||||
const isGlobalConfigFileExist = (0, import_fs.existsSync)(configPath);
|
||||
if (!isGlobalConfigFileExist)
|
||||
@@ -30156,19 +30174,27 @@ var mergeConfigs = (main, fallback) => {
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
var _config = null;
|
||||
var getConfig = ({
|
||||
envPath = defaultEnvPath,
|
||||
globalPath = defaultConfigPath
|
||||
globalPath = defaultConfigPath,
|
||||
cache = true,
|
||||
setDefaultValues = true
|
||||
} = {}) => {
|
||||
if (_config && cache)
|
||||
return _config;
|
||||
const envConfig = getEnvConfig(envPath);
|
||||
const globalConfig = getGlobalConfig(globalPath);
|
||||
const config7 = mergeConfigs(envConfig, globalConfig);
|
||||
return config7;
|
||||
_config = mergeConfigs(envConfig, globalConfig);
|
||||
if (setDefaultValues)
|
||||
setDefaultConfigValues(_config);
|
||||
return _config;
|
||||
};
|
||||
var setConfig = (keyValues, globalConfigPath = defaultConfigPath) => {
|
||||
const config7 = getConfig({
|
||||
globalPath: globalConfigPath
|
||||
});
|
||||
const configToSet = {};
|
||||
for (let [key, value] of keyValues) {
|
||||
if (!configValidators.hasOwnProperty(key)) {
|
||||
const supportedKeys = Object.keys(configValidators).join("\n");
|
||||
@@ -30182,7 +30208,10 @@ For more help refer to our docs: https://github.com/di-sukharev/opencommit`
|
||||
}
|
||||
let parsedConfigValue;
|
||||
try {
|
||||
parsedConfigValue = JSON.parse(value);
|
||||
if (typeof value === "string")
|
||||
parsedConfigValue = JSON.parse(value);
|
||||
else
|
||||
parsedConfigValue = value;
|
||||
} catch (error) {
|
||||
parsedConfigValue = value;
|
||||
}
|
||||
@@ -30190,9 +30219,9 @@ For more help refer to our docs: https://github.com/di-sukharev/opencommit`
|
||||
parsedConfigValue,
|
||||
config7
|
||||
);
|
||||
config7[key] = validValue;
|
||||
configToSet[key] = validValue;
|
||||
}
|
||||
(0, import_fs.writeFileSync)(globalConfigPath, (0, import_ini.stringify)(config7), "utf8");
|
||||
setGlobalConfig(mergeConfigs(configToSet, config7), globalConfigPath);
|
||||
ce(`${source_default.green("\u2714")} config successfully set`);
|
||||
};
|
||||
var configCommand = G3(
|
||||
@@ -34617,22 +34646,22 @@ var resolveConfig_default = (config7) => {
|
||||
var isXHRAdapterSupported = typeof XMLHttpRequest !== "undefined";
|
||||
var xhr_default = isXHRAdapterSupported && function(config7) {
|
||||
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
||||
const _config = resolveConfig_default(config7);
|
||||
let requestData = _config.data;
|
||||
const requestHeaders = AxiosHeaders_default.from(_config.headers).normalize();
|
||||
let { responseType, onUploadProgress, onDownloadProgress } = _config;
|
||||
const _config2 = resolveConfig_default(config7);
|
||||
let requestData = _config2.data;
|
||||
const requestHeaders = AxiosHeaders_default.from(_config2.headers).normalize();
|
||||
let { responseType, onUploadProgress, onDownloadProgress } = _config2;
|
||||
let onCanceled;
|
||||
let uploadThrottled, downloadThrottled;
|
||||
let flushUpload, flushDownload;
|
||||
function done() {
|
||||
flushUpload && flushUpload();
|
||||
flushDownload && flushDownload();
|
||||
_config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
|
||||
_config.signal && _config.signal.removeEventListener("abort", onCanceled);
|
||||
_config2.cancelToken && _config2.cancelToken.unsubscribe(onCanceled);
|
||||
_config2.signal && _config2.signal.removeEventListener("abort", onCanceled);
|
||||
}
|
||||
let request3 = new XMLHttpRequest();
|
||||
request3.open(_config.method.toUpperCase(), _config.url, true);
|
||||
request3.timeout = _config.timeout;
|
||||
request3.open(_config2.method.toUpperCase(), _config2.url, true);
|
||||
request3.timeout = _config2.timeout;
|
||||
function onloadend() {
|
||||
if (!request3) {
|
||||
return;
|
||||
@@ -34683,10 +34712,10 @@ var xhr_default = isXHRAdapterSupported && function(config7) {
|
||||
request3 = null;
|
||||
};
|
||||
request3.ontimeout = function handleTimeout() {
|
||||
let timeoutErrorMessage = _config.timeout ? "timeout of " + _config.timeout + "ms exceeded" : "timeout exceeded";
|
||||
const transitional2 = _config.transitional || transitional_default;
|
||||
if (_config.timeoutErrorMessage) {
|
||||
timeoutErrorMessage = _config.timeoutErrorMessage;
|
||||
let timeoutErrorMessage = _config2.timeout ? "timeout of " + _config2.timeout + "ms exceeded" : "timeout exceeded";
|
||||
const transitional2 = _config2.transitional || transitional_default;
|
||||
if (_config2.timeoutErrorMessage) {
|
||||
timeoutErrorMessage = _config2.timeoutErrorMessage;
|
||||
}
|
||||
reject(new AxiosError_default(
|
||||
timeoutErrorMessage,
|
||||
@@ -34702,11 +34731,11 @@ var xhr_default = isXHRAdapterSupported && function(config7) {
|
||||
request3.setRequestHeader(key, val);
|
||||
});
|
||||
}
|
||||
if (!utils_default.isUndefined(_config.withCredentials)) {
|
||||
request3.withCredentials = !!_config.withCredentials;
|
||||
if (!utils_default.isUndefined(_config2.withCredentials)) {
|
||||
request3.withCredentials = !!_config2.withCredentials;
|
||||
}
|
||||
if (responseType && responseType !== "json") {
|
||||
request3.responseType = _config.responseType;
|
||||
request3.responseType = _config2.responseType;
|
||||
}
|
||||
if (onDownloadProgress) {
|
||||
[downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true);
|
||||
@@ -34717,7 +34746,7 @@ var xhr_default = isXHRAdapterSupported && function(config7) {
|
||||
request3.upload.addEventListener("progress", uploadThrottled);
|
||||
request3.upload.addEventListener("loadend", flushUpload);
|
||||
}
|
||||
if (_config.cancelToken || _config.signal) {
|
||||
if (_config2.cancelToken || _config2.signal) {
|
||||
onCanceled = (cancel) => {
|
||||
if (!request3) {
|
||||
return;
|
||||
@@ -34726,12 +34755,12 @@ var xhr_default = isXHRAdapterSupported && function(config7) {
|
||||
request3.abort();
|
||||
request3 = null;
|
||||
};
|
||||
_config.cancelToken && _config.cancelToken.subscribe(onCanceled);
|
||||
if (_config.signal) {
|
||||
_config.signal.aborted ? onCanceled() : _config.signal.addEventListener("abort", onCanceled);
|
||||
_config2.cancelToken && _config2.cancelToken.subscribe(onCanceled);
|
||||
if (_config2.signal) {
|
||||
_config2.signal.aborted ? onCanceled() : _config2.signal.addEventListener("abort", onCanceled);
|
||||
}
|
||||
}
|
||||
const protocol = parseProtocol(_config.url);
|
||||
const protocol = parseProtocol(_config2.url);
|
||||
if (protocol && platform_default.protocols.indexOf(protocol) === -1) {
|
||||
reject(new AxiosError_default("Unsupported protocol " + protocol + ":", AxiosError_default.ERR_BAD_REQUEST, config7));
|
||||
return;
|
||||
@@ -45534,9 +45563,9 @@ var prepareCommitMessageHook = async (isStageAllFlag = false) => {
|
||||
return;
|
||||
ae("opencommit");
|
||||
const config7 = getConfig();
|
||||
if (!config7.OCO_OPENAI_API_KEY && !config7.OCO_ANTHROPIC_API_KEY && !config7.OCO_AZURE_API_KEY) {
|
||||
if (!config7.OCO_API_KEY) {
|
||||
ce(
|
||||
"No OCO_OPENAI_API_KEY or OCO_ANTHROPIC_API_KEY or OCO_AZURE_API_KEY exists. Set your key via `oco config set <key>=<value>, e.g. `oco config set OCO_OPENAI_API_KEY=<value>`. For more info see https://github.com/di-sukharev/opencommit"
|
||||
"No OCO_API_KEY is set. Set your key via `oco config set OCO_API_KEY=<value>. For more info see https://github.com/di-sukharev/opencommit"
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -45594,7 +45623,7 @@ var import_path5 = require("path");
|
||||
|
||||
// src/migrations/00_use_single_api_key_and_url.ts
|
||||
var migrate = async () => {
|
||||
const config7 = getConfig();
|
||||
const config7 = getConfig({ cache: false, setDefaultValues: false });
|
||||
const aiProvider = config7.OCO_AI_PROVIDER;
|
||||
let apiKey;
|
||||
let apiUrl;
|
||||
@@ -45648,8 +45677,11 @@ function remove_obsolete_config_keys_from_global_file_default() {
|
||||
"OCO_FLOWISE_API_KEY",
|
||||
"OCO_FLOWISE_ENDPOINT"
|
||||
];
|
||||
obsoleteKeys.forEach((key) => {
|
||||
});
|
||||
const globalConfig = getGlobalConfig();
|
||||
const configToOverride = { ...globalConfig };
|
||||
for (const key of obsoleteKeys)
|
||||
delete configToOverride[key];
|
||||
setGlobalConfig(configToOverride);
|
||||
}
|
||||
|
||||
// src/migrations/_migrations.ts
|
||||
@@ -45683,19 +45715,25 @@ var saveCompletedMigration = (migrationName) => {
|
||||
};
|
||||
var runMigrations = async () => {
|
||||
const completedMigrations = getCompletedMigrations();
|
||||
console.log("Completed migrations:", completedMigrations);
|
||||
console.log("Migration files:", migrations);
|
||||
let isMigrated = false;
|
||||
for (const migration of migrations) {
|
||||
if (!completedMigrations.includes(migration.name)) {
|
||||
try {
|
||||
await migration.run();
|
||||
saveCompletedMigration(migration.name);
|
||||
console.log(`Migration ${migration.name} applied successfully.`);
|
||||
ce(`Migration ${migration.name} applied successfully.`);
|
||||
} catch (error) {
|
||||
console.error(`Failed to apply migration ${migration.name}:`, error);
|
||||
ce(
|
||||
`${source_default.red("Failed to apply migration")} ${migration.name}: ${error}`
|
||||
);
|
||||
}
|
||||
isMigrated = true;
|
||||
}
|
||||
}
|
||||
if (isMigrated) {
|
||||
ce("Migrations to your config were applied successfully. Please rerun.");
|
||||
process.exit(0);
|
||||
}
|
||||
};
|
||||
|
||||
// src/cli.ts
|
||||
@@ -45718,8 +45756,8 @@ Z2(
|
||||
help: { description: package_default.description }
|
||||
},
|
||||
async ({ flags }) => {
|
||||
await checkIsLatestVersion();
|
||||
await runMigrations();
|
||||
await checkIsLatestVersion();
|
||||
if (await isHookCalled()) {
|
||||
prepareCommitMessageHook();
|
||||
} else {
|
||||
|
||||
@@ -48887,6 +48887,14 @@ var configValidators = {
|
||||
).join(", ")}`
|
||||
);
|
||||
return value;
|
||||
},
|
||||
["OCO_WHY" /* OCO_WHY */](value) {
|
||||
validateConfig(
|
||||
"OCO_WHY" /* OCO_WHY */,
|
||||
typeof value === "boolean",
|
||||
"Must be true or false"
|
||||
);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
var defaultConfigPath = (0, import_path.join)((0, import_os.homedir)(), ".opencommit");
|
||||
@@ -48925,11 +48933,9 @@ var getEnvConfig = (envPath) => {
|
||||
OCO_API_URL: process.env.OCO_API_URL,
|
||||
OCO_API_KEY: process.env.OCO_API_KEY,
|
||||
OCO_AI_PROVIDER: process.env.OCO_AI_PROVIDER,
|
||||
OCO_TOKENS_MAX_INPUT: parseConfigVarValue(
|
||||
process.env.OCO_TOKENS_MAX_INPUT ?? 40960 /* DEFAULT_MAX_TOKENS_INPUT */
|
||||
),
|
||||
OCO_TOKENS_MAX_INPUT: parseConfigVarValue(process.env.OCO_TOKENS_MAX_INPUT),
|
||||
OCO_TOKENS_MAX_OUTPUT: parseConfigVarValue(
|
||||
process.env.OCO_TOKENS_MAX_OUTPUT ?? 4096 /* DEFAULT_MAX_TOKENS_OUTPUT */
|
||||
process.env.OCO_TOKENS_MAX_OUTPUT
|
||||
),
|
||||
OCO_DESCRIPTION: parseConfigVarValue(process.env.OCO_DESCRIPTION),
|
||||
OCO_EMOJI: parseConfigVarValue(process.env.OCO_EMOJI),
|
||||
@@ -48941,7 +48947,19 @@ var getEnvConfig = (envPath) => {
|
||||
OCO_GITPUSH: parseConfigVarValue(process.env.OCO_GITPUSH)
|
||||
};
|
||||
};
|
||||
var getGlobalConfig = (configPath) => {
|
||||
var setDefaultConfigValues = (config6) => {
|
||||
const entriesToSet = [];
|
||||
for (const entry of Object.entries(DEFAULT_CONFIG)) {
|
||||
const [key, _value] = entry;
|
||||
if (config6[key] === "undefined")
|
||||
entriesToSet.push(entry);
|
||||
}
|
||||
setConfig(entriesToSet);
|
||||
};
|
||||
var setGlobalConfig = (config6, configPath = defaultConfigPath) => {
|
||||
(0, import_fs.writeFileSync)(configPath, (0, import_ini.stringify)(config6), "utf8");
|
||||
};
|
||||
var getGlobalConfig = (configPath = defaultConfigPath) => {
|
||||
let globalConfig;
|
||||
const isGlobalConfigFileExist = (0, import_fs.existsSync)(configPath);
|
||||
if (!isGlobalConfigFileExist)
|
||||
@@ -48959,19 +48977,27 @@ var mergeConfigs = (main, fallback) => {
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
var _config = null;
|
||||
var getConfig = ({
|
||||
envPath = defaultEnvPath,
|
||||
globalPath = defaultConfigPath
|
||||
globalPath = defaultConfigPath,
|
||||
cache = true,
|
||||
setDefaultValues = true
|
||||
} = {}) => {
|
||||
if (_config && cache)
|
||||
return _config;
|
||||
const envConfig = getEnvConfig(envPath);
|
||||
const globalConfig = getGlobalConfig(globalPath);
|
||||
const config6 = mergeConfigs(envConfig, globalConfig);
|
||||
return config6;
|
||||
_config = mergeConfigs(envConfig, globalConfig);
|
||||
if (setDefaultValues)
|
||||
setDefaultConfigValues(_config);
|
||||
return _config;
|
||||
};
|
||||
var setConfig = (keyValues, globalConfigPath = defaultConfigPath) => {
|
||||
const config6 = getConfig({
|
||||
globalPath: globalConfigPath
|
||||
});
|
||||
const configToSet = {};
|
||||
for (let [key, value] of keyValues) {
|
||||
if (!configValidators.hasOwnProperty(key)) {
|
||||
const supportedKeys = Object.keys(configValidators).join("\n");
|
||||
@@ -48985,7 +49011,10 @@ For more help refer to our docs: https://github.com/di-sukharev/opencommit`
|
||||
}
|
||||
let parsedConfigValue;
|
||||
try {
|
||||
parsedConfigValue = JSON.parse(value);
|
||||
if (typeof value === "string")
|
||||
parsedConfigValue = JSON.parse(value);
|
||||
else
|
||||
parsedConfigValue = value;
|
||||
} catch (error) {
|
||||
parsedConfigValue = value;
|
||||
}
|
||||
@@ -48993,9 +49022,9 @@ For more help refer to our docs: https://github.com/di-sukharev/opencommit`
|
||||
parsedConfigValue,
|
||||
config6
|
||||
);
|
||||
config6[key] = validValue;
|
||||
configToSet[key] = validValue;
|
||||
}
|
||||
(0, import_fs.writeFileSync)(globalConfigPath, (0, import_ini.stringify)(config6), "utf8");
|
||||
setGlobalConfig(mergeConfigs(configToSet, config6), globalConfigPath);
|
||||
ce(`${source_default.green("\u2714")} config successfully set`);
|
||||
};
|
||||
var configCommand = G2(
|
||||
@@ -53420,22 +53449,22 @@ var resolveConfig_default = (config6) => {
|
||||
var isXHRAdapterSupported = typeof XMLHttpRequest !== "undefined";
|
||||
var xhr_default = isXHRAdapterSupported && function(config6) {
|
||||
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
||||
const _config = resolveConfig_default(config6);
|
||||
let requestData = _config.data;
|
||||
const requestHeaders = AxiosHeaders_default.from(_config.headers).normalize();
|
||||
let { responseType, onUploadProgress, onDownloadProgress } = _config;
|
||||
const _config2 = resolveConfig_default(config6);
|
||||
let requestData = _config2.data;
|
||||
const requestHeaders = AxiosHeaders_default.from(_config2.headers).normalize();
|
||||
let { responseType, onUploadProgress, onDownloadProgress } = _config2;
|
||||
let onCanceled;
|
||||
let uploadThrottled, downloadThrottled;
|
||||
let flushUpload, flushDownload;
|
||||
function done() {
|
||||
flushUpload && flushUpload();
|
||||
flushDownload && flushDownload();
|
||||
_config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
|
||||
_config.signal && _config.signal.removeEventListener("abort", onCanceled);
|
||||
_config2.cancelToken && _config2.cancelToken.unsubscribe(onCanceled);
|
||||
_config2.signal && _config2.signal.removeEventListener("abort", onCanceled);
|
||||
}
|
||||
let request3 = new XMLHttpRequest();
|
||||
request3.open(_config.method.toUpperCase(), _config.url, true);
|
||||
request3.timeout = _config.timeout;
|
||||
request3.open(_config2.method.toUpperCase(), _config2.url, true);
|
||||
request3.timeout = _config2.timeout;
|
||||
function onloadend() {
|
||||
if (!request3) {
|
||||
return;
|
||||
@@ -53486,10 +53515,10 @@ var xhr_default = isXHRAdapterSupported && function(config6) {
|
||||
request3 = null;
|
||||
};
|
||||
request3.ontimeout = function handleTimeout() {
|
||||
let timeoutErrorMessage = _config.timeout ? "timeout of " + _config.timeout + "ms exceeded" : "timeout exceeded";
|
||||
const transitional2 = _config.transitional || transitional_default;
|
||||
if (_config.timeoutErrorMessage) {
|
||||
timeoutErrorMessage = _config.timeoutErrorMessage;
|
||||
let timeoutErrorMessage = _config2.timeout ? "timeout of " + _config2.timeout + "ms exceeded" : "timeout exceeded";
|
||||
const transitional2 = _config2.transitional || transitional_default;
|
||||
if (_config2.timeoutErrorMessage) {
|
||||
timeoutErrorMessage = _config2.timeoutErrorMessage;
|
||||
}
|
||||
reject(new AxiosError_default(
|
||||
timeoutErrorMessage,
|
||||
@@ -53505,11 +53534,11 @@ var xhr_default = isXHRAdapterSupported && function(config6) {
|
||||
request3.setRequestHeader(key, val);
|
||||
});
|
||||
}
|
||||
if (!utils_default.isUndefined(_config.withCredentials)) {
|
||||
request3.withCredentials = !!_config.withCredentials;
|
||||
if (!utils_default.isUndefined(_config2.withCredentials)) {
|
||||
request3.withCredentials = !!_config2.withCredentials;
|
||||
}
|
||||
if (responseType && responseType !== "json") {
|
||||
request3.responseType = _config.responseType;
|
||||
request3.responseType = _config2.responseType;
|
||||
}
|
||||
if (onDownloadProgress) {
|
||||
[downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true);
|
||||
@@ -53520,7 +53549,7 @@ var xhr_default = isXHRAdapterSupported && function(config6) {
|
||||
request3.upload.addEventListener("progress", uploadThrottled);
|
||||
request3.upload.addEventListener("loadend", flushUpload);
|
||||
}
|
||||
if (_config.cancelToken || _config.signal) {
|
||||
if (_config2.cancelToken || _config2.signal) {
|
||||
onCanceled = (cancel) => {
|
||||
if (!request3) {
|
||||
return;
|
||||
@@ -53529,12 +53558,12 @@ var xhr_default = isXHRAdapterSupported && function(config6) {
|
||||
request3.abort();
|
||||
request3 = null;
|
||||
};
|
||||
_config.cancelToken && _config.cancelToken.subscribe(onCanceled);
|
||||
if (_config.signal) {
|
||||
_config.signal.aborted ? onCanceled() : _config.signal.addEventListener("abort", onCanceled);
|
||||
_config2.cancelToken && _config2.cancelToken.subscribe(onCanceled);
|
||||
if (_config2.signal) {
|
||||
_config2.signal.aborted ? onCanceled() : _config2.signal.addEventListener("abort", onCanceled);
|
||||
}
|
||||
}
|
||||
const protocol = parseProtocol(_config.url);
|
||||
const protocol = parseProtocol(_config2.url);
|
||||
if (protocol && platform_default.protocols.indexOf(protocol) === -1) {
|
||||
reject(new AxiosError_default("Unsupported protocol " + protocol + ":", AxiosError_default.ERR_BAD_REQUEST, config6));
|
||||
return;
|
||||
|
||||
@@ -31,8 +31,8 @@ cli(
|
||||
help: { description: packageJSON.description }
|
||||
},
|
||||
async ({ flags }) => {
|
||||
await checkIsLatestVersion();
|
||||
await runMigrations();
|
||||
await checkIsLatestVersion();
|
||||
|
||||
if (await isHookCalled()) {
|
||||
prepareCommitMessageHook();
|
||||
|
||||
@@ -269,6 +269,15 @@ export const configValidators = {
|
||||
).join(', ')}`
|
||||
);
|
||||
return value;
|
||||
},
|
||||
|
||||
[CONFIG_KEYS.OCO_WHY](value: any) {
|
||||
validateConfig(
|
||||
CONFIG_KEYS.OCO_WHY,
|
||||
typeof value === 'boolean',
|
||||
'Must be true or false'
|
||||
);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -300,8 +309,8 @@ export type ConfigType = {
|
||||
[CONFIG_KEYS.OCO_TEST_MOCK_TYPE]: string;
|
||||
};
|
||||
|
||||
const defaultConfigPath = pathJoin(homedir(), '.opencommit');
|
||||
const defaultEnvPath = pathResolve(process.cwd(), '.env');
|
||||
export const defaultConfigPath = pathJoin(homedir(), '.opencommit');
|
||||
export const defaultEnvPath = pathResolve(process.cwd(), '.env');
|
||||
|
||||
const assertConfigsAreValid = (config: Record<string, any>) => {
|
||||
for (const [key, value] of Object.entries(config)) {
|
||||
@@ -370,13 +379,9 @@ const getEnvConfig = (envPath: string) => {
|
||||
OCO_API_KEY: process.env.OCO_API_KEY,
|
||||
OCO_AI_PROVIDER: process.env.OCO_AI_PROVIDER as OCO_AI_PROVIDER_ENUM,
|
||||
|
||||
OCO_TOKENS_MAX_INPUT: parseConfigVarValue(
|
||||
process.env.OCO_TOKENS_MAX_INPUT ??
|
||||
DEFAULT_TOKEN_LIMITS.DEFAULT_MAX_TOKENS_INPUT
|
||||
),
|
||||
OCO_TOKENS_MAX_INPUT: parseConfigVarValue(process.env.OCO_TOKENS_MAX_INPUT),
|
||||
OCO_TOKENS_MAX_OUTPUT: parseConfigVarValue(
|
||||
process.env.OCO_TOKENS_MAX_OUTPUT ??
|
||||
DEFAULT_TOKEN_LIMITS.DEFAULT_MAX_TOKENS_OUTPUT
|
||||
process.env.OCO_TOKENS_MAX_OUTPUT
|
||||
),
|
||||
|
||||
OCO_DESCRIPTION: parseConfigVarValue(process.env.OCO_DESCRIPTION),
|
||||
@@ -392,7 +397,24 @@ const getEnvConfig = (envPath: string) => {
|
||||
};
|
||||
};
|
||||
|
||||
const getGlobalConfig = (configPath: string) => {
|
||||
const setDefaultConfigValues = (config: ConfigType) => {
|
||||
const entriesToSet: [key: string, value: string | boolean | number][] = [];
|
||||
for (const entry of Object.entries(DEFAULT_CONFIG)) {
|
||||
const [key, _value] = entry;
|
||||
if (config[key] === 'undefined') entriesToSet.push(entry);
|
||||
}
|
||||
|
||||
setConfig(entriesToSet);
|
||||
};
|
||||
|
||||
export const setGlobalConfig = (
|
||||
config: ConfigType,
|
||||
configPath: string = defaultConfigPath
|
||||
) => {
|
||||
writeFileSync(configPath, iniStringify(config), 'utf8');
|
||||
};
|
||||
|
||||
export const getGlobalConfig = (configPath: string = defaultConfigPath) => {
|
||||
let globalConfig: ConfigType;
|
||||
|
||||
const isGlobalConfigFileExist = existsSync(configPath);
|
||||
@@ -423,28 +445,40 @@ const mergeConfigs = (main: Partial<ConfigType>, fallback: ConfigType) => {
|
||||
interface GetConfigOptions {
|
||||
globalPath?: string;
|
||||
envPath?: string;
|
||||
cache?: boolean;
|
||||
setDefaultValues?: boolean;
|
||||
}
|
||||
|
||||
let _config: ConfigType | null = null;
|
||||
|
||||
export const getConfig = ({
|
||||
envPath = defaultEnvPath,
|
||||
globalPath = defaultConfigPath
|
||||
globalPath = defaultConfigPath,
|
||||
cache = true,
|
||||
setDefaultValues = true
|
||||
}: GetConfigOptions = {}): ConfigType => {
|
||||
if (_config && cache) return _config;
|
||||
|
||||
const envConfig = getEnvConfig(envPath);
|
||||
const globalConfig = getGlobalConfig(globalPath);
|
||||
|
||||
const config = mergeConfigs(envConfig, globalConfig);
|
||||
_config = mergeConfigs(envConfig, globalConfig);
|
||||
|
||||
return config;
|
||||
if (setDefaultValues) setDefaultConfigValues(_config);
|
||||
|
||||
return _config;
|
||||
};
|
||||
|
||||
export const setConfig = (
|
||||
keyValues: [key: string, value: string][],
|
||||
keyValues: [key: string, value: string | boolean | number][],
|
||||
globalConfigPath: string = defaultConfigPath
|
||||
) => {
|
||||
const config = getConfig({
|
||||
globalPath: globalConfigPath
|
||||
});
|
||||
|
||||
const configToSet = {};
|
||||
|
||||
for (let [key, value] of keyValues) {
|
||||
if (!configValidators.hasOwnProperty(key)) {
|
||||
const supportedKeys = Object.keys(configValidators).join('\n');
|
||||
@@ -456,7 +490,8 @@ export const setConfig = (
|
||||
let parsedConfigValue;
|
||||
|
||||
try {
|
||||
parsedConfigValue = JSON.parse(value);
|
||||
if (typeof value === 'string') parsedConfigValue = JSON.parse(value);
|
||||
else parsedConfigValue = value;
|
||||
} catch (error) {
|
||||
parsedConfigValue = value;
|
||||
}
|
||||
@@ -466,10 +501,10 @@ export const setConfig = (
|
||||
config
|
||||
);
|
||||
|
||||
config[key] = validValue;
|
||||
configToSet[key] = validValue;
|
||||
}
|
||||
|
||||
writeFileSync(globalConfigPath, iniStringify(config), 'utf8');
|
||||
setGlobalConfig(mergeConfigs(configToSet, config), globalConfigPath);
|
||||
|
||||
outro(`${chalk.green('✔')} config successfully set`);
|
||||
};
|
||||
|
||||
@@ -39,13 +39,9 @@ export const prepareCommitMessageHook = async (
|
||||
|
||||
const config = getConfig();
|
||||
|
||||
if (
|
||||
!config.OCO_OPENAI_API_KEY &&
|
||||
!config.OCO_ANTHROPIC_API_KEY &&
|
||||
!config.OCO_AZURE_API_KEY
|
||||
) {
|
||||
if (!config.OCO_API_KEY) {
|
||||
outro(
|
||||
'No OCO_OPENAI_API_KEY or OCO_ANTHROPIC_API_KEY or OCO_AZURE_API_KEY exists. Set your key via `oco config set <key>=<value>, e.g. `oco config set OCO_OPENAI_API_KEY=<value>`. For more info see https://github.com/di-sukharev/opencommit'
|
||||
'No OCO_API_KEY is set. Set your key via `oco config set OCO_API_KEY=<value>. For more info see https://github.com/di-sukharev/opencommit'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
} from '../commands/config';
|
||||
|
||||
const migrate = async (): Promise<void> => {
|
||||
const config = getConfig();
|
||||
const config = getConfig({ cache: false, setDefaultValues: false });
|
||||
|
||||
const aiProvider = config.OCO_AI_PROVIDER;
|
||||
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
import { writeFileSync } from 'fs';
|
||||
import {
|
||||
defaultConfigPath,
|
||||
getGlobalConfig,
|
||||
setGlobalConfig
|
||||
} from '../commands/config';
|
||||
|
||||
export default function () {
|
||||
const obsoleteKeys = [
|
||||
'OCO_OLLAMA_API_KEY',
|
||||
@@ -14,9 +21,11 @@ export default function () {
|
||||
'OCO_FLOWISE_ENDPOINT'
|
||||
];
|
||||
|
||||
obsoleteKeys.forEach((key) => {
|
||||
// if (config[key]) {
|
||||
// setConfig([[key, undefined]]);
|
||||
// }
|
||||
});
|
||||
const globalConfig = getGlobalConfig();
|
||||
|
||||
const configToOverride = { ...globalConfig };
|
||||
|
||||
for (const key of obsoleteKeys) delete configToOverride[key];
|
||||
|
||||
setGlobalConfig(configToOverride);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import fs from 'fs';
|
||||
import { homedir } from 'os';
|
||||
import { join as pathJoin } from 'path';
|
||||
import { migrations } from './_migrations';
|
||||
import { outro } from '@clack/prompts';
|
||||
import chalk from 'chalk';
|
||||
|
||||
const migrationsFile = pathJoin(homedir(), '.opencommit_migrations');
|
||||
|
||||
@@ -25,18 +27,32 @@ const saveCompletedMigration = (migrationName: string) => {
|
||||
export const runMigrations = async () => {
|
||||
const completedMigrations = getCompletedMigrations();
|
||||
|
||||
console.log('Completed migrations:', completedMigrations);
|
||||
console.log('Migration files:', migrations);
|
||||
let isMigrated = false;
|
||||
|
||||
for (const migration of migrations) {
|
||||
if (!completedMigrations.includes(migration.name)) {
|
||||
try {
|
||||
await migration.run();
|
||||
saveCompletedMigration(migration.name);
|
||||
console.log(`Migration ${migration.name} applied successfully.`);
|
||||
outro(`Migration ${migration.name} applied successfully.`);
|
||||
} catch (error) {
|
||||
console.error(`Failed to apply migration ${migration.name}:`, error);
|
||||
outro(
|
||||
`${chalk.red('Failed to apply migration')} ${
|
||||
migration.name
|
||||
}: ${error}`
|
||||
);
|
||||
}
|
||||
|
||||
isMigrated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isMigrated) {
|
||||
outro(
|
||||
`${chalk.green(
|
||||
'✔'
|
||||
)} Migrations to your config were applied successfully. Please rerun.`
|
||||
);
|
||||
process.exit(0);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user