Compare commits

..

7 Commits

Author SHA1 Message Date
di-sukharev
0eff198eb9 2.0.18 2023-05-22 12:31:43 +08:00
di-sukharev
b345eee815 build 2023-05-22 12:31:19 +08:00
henrycunh
cba599337d refactor(config.ts): handle undefined values and improve validation for OCO_OPENAI_MAX_TOKENS and OCO_MODEL (#176)
fix(config.ts): set default values for OCO_MODEL and OCO_LANGUAGE when reading from environment variables
refactor(generateCommitMessageFromGitDiff.ts): remove unused GenerateCommitMessageError interface
2023-05-22 12:30:41 +08:00
di-sukharev
4e25f1460a chore(README.md): update opencommit action version to v1.0.4 to fix bugs and improve functionality 2023-05-22 12:27:58 +08:00
di-sukharev
61b145455d Merge remote-tracking branch 'origin/master' into dev 2023-05-22 12:26:59 +08:00
di-sukharev
0b8dc12047 chore: update .eslintrc.json to disable import/order rule and enable simple-import-sort rules
chore: update .prettierignore to include /out directory
docs: update LICENSE file to include link to author's GitHub profile
chore: update tsconfig.json to move resolveJsonModule above moduleResolution for consistency
2023-05-22 12:22:37 +08:00
Sukharev
3eb319a919 GitHub action (#173)
* add option to run OpenCommit as a Github Action
2023-05-21 16:15:45 +08:00
12 changed files with 41 additions and 31 deletions

View File

@@ -21,8 +21,8 @@
"rules": {
"prettier/prettier": "error",
"no-console": "error",
"sort-imports": "off",
"import/order": "off",
"sort-imports": "off",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"import/first": "error",

View File

@@ -1,2 +1,3 @@
/build
/dist
/dist
/out

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) Dima Sukharev
Copyright (c) Dima Sukharev, https://github.com/di-sukharev
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@@ -48,7 +48,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: di-sukharev/opencommit@github-action-v1
- uses: di-sukharev/opencommit@github-action-v1.0.4
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -16272,7 +16272,7 @@ function G3(t, e2) {
// package.json
var package_default = {
name: "opencommit",
version: "2.0.16",
version: "2.0.17",
description: "Auto-generate impressive commits in 1 second. Killing lame commits with AI \u{1F92F}\u{1F52B}",
keywords: [
"git",
@@ -16315,6 +16315,7 @@ var package_default = {
dev: "ts-node ./src/cli.ts",
build: "rimraf out && node esbuild.config.js",
deploy: "npm run build && npm version patch && npm publish --tag latest",
"build:push": "npm run build && git add . && git commit -m 'build' && git push",
lint: "eslint src --ext ts && tsc --noEmit",
format: "prettier --write src"
},
@@ -17643,7 +17644,7 @@ var configValidators = {
}
validateConfig(
"OCO_OPENAI_MAX_TOKENS" /* OCO_OPENAI_MAX_TOKENS */,
typeof value === "number",
value ? typeof value === "number" : void 0,
"Must be a number"
);
return value;
@@ -17674,8 +17675,8 @@ var configValidators = {
},
["OCO_MODEL" /* OCO_MODEL */](value) {
validateConfig(
"OCO_OPENAI_BASE_PATH" /* OCO_OPENAI_BASE_PATH */,
value === "gpt-3.5-turbo" || value === "gpt-4",
"OCO_MODEL" /* OCO_MODEL */,
["gpt-3.5-turbo", "gpt-4"].includes(value),
`${value} is not supported yet, use 'gpt-4' or 'gpt-3.5-turbo' (default)`
);
return value;
@@ -17685,12 +17686,12 @@ var configPath = (0, import_path.join)((0, import_os.homedir)(), ".opencommit");
var getConfig = () => {
const configFromEnv = {
OCO_OPENAI_API_KEY: process.env.OCO_OPENAI_API_KEY,
OCO_OPENAI_MAX_TOKENS: Number(process.env.OCO_OPENAI_MAX_TOKENS),
OCO_OPENAI_MAX_TOKENS: process.env.OCO_OPENAI_MAX_TOKENS ? Number(process.env.OCO_OPENAI_MAX_TOKENS) : void 0,
OCO_OPENAI_BASE_PATH: process.env.OCO_OPENAI_BASE_PATH,
OCO_DESCRIPTION: process.env.OCO_DESCRIPTION === "true" ? true : false,
OCO_EMOJI: process.env.OCO_EMOJI === "true" ? true : false,
OCO_MODEL: process.env.OCO_MODEL,
OCO_LANGUAGE: process.env.OCO_LANGUAGE
OCO_MODEL: process.env.OCO_MODEL || "gpt-3.5-turbo",
OCO_LANGUAGE: process.env.OCO_LANGUAGE || "en"
};
const configExists = (0, import_fs.existsSync)(configPath);
if (!configExists)
@@ -17698,6 +17699,10 @@ var getConfig = () => {
const configFile = (0, import_fs.readFileSync)(configPath, "utf8");
const config4 = (0, import_ini.parse)(configFile);
for (const configKey of Object.keys(config4)) {
if (!config4[configKey] || ["null", "undefined"].includes(config4[configKey])) {
config4[configKey] = void 0;
continue;
}
try {
const validator = configValidators[configKey];
const validValue = validator(

View File

@@ -26839,7 +26839,7 @@ var configValidators = {
}
validateConfig(
"OCO_OPENAI_MAX_TOKENS" /* OCO_OPENAI_MAX_TOKENS */,
typeof value === "number",
value ? typeof value === "number" : void 0,
"Must be a number"
);
return value;
@@ -26870,8 +26870,8 @@ var configValidators = {
},
["OCO_MODEL" /* OCO_MODEL */](value) {
validateConfig(
"OCO_OPENAI_BASE_PATH" /* OCO_OPENAI_BASE_PATH */,
value === "gpt-3.5-turbo" || value === "gpt-4",
"OCO_MODEL" /* OCO_MODEL */,
["gpt-3.5-turbo", "gpt-4"].includes(value),
`${value} is not supported yet, use 'gpt-4' or 'gpt-3.5-turbo' (default)`
);
return value;
@@ -26881,12 +26881,12 @@ var configPath = (0, import_path.join)((0, import_os.homedir)(), ".opencommit");
var getConfig = () => {
const configFromEnv = {
OCO_OPENAI_API_KEY: process.env.OCO_OPENAI_API_KEY,
OCO_OPENAI_MAX_TOKENS: Number(process.env.OCO_OPENAI_MAX_TOKENS),
OCO_OPENAI_MAX_TOKENS: process.env.OCO_OPENAI_MAX_TOKENS ? Number(process.env.OCO_OPENAI_MAX_TOKENS) : void 0,
OCO_OPENAI_BASE_PATH: process.env.OCO_OPENAI_BASE_PATH,
OCO_DESCRIPTION: process.env.OCO_DESCRIPTION === "true" ? true : false,
OCO_EMOJI: process.env.OCO_EMOJI === "true" ? true : false,
OCO_MODEL: process.env.OCO_MODEL,
OCO_LANGUAGE: process.env.OCO_LANGUAGE
OCO_MODEL: process.env.OCO_MODEL || "gpt-3.5-turbo",
OCO_LANGUAGE: process.env.OCO_LANGUAGE || "en"
};
const configExists = (0, import_fs.existsSync)(configPath);
if (!configExists)
@@ -26894,6 +26894,10 @@ var getConfig = () => {
const configFile = (0, import_fs.readFileSync)(configPath, "utf8");
const config4 = (0, import_ini.parse)(configFile);
for (const configKey of Object.keys(config4)) {
if (!config4[configKey] || ["null", "undefined"].includes(config4[configKey])) {
config4[configKey] = void 0;
continue;
}
try {
const validator = configValidators[configKey];
const validValue = validator(

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "opencommit",
"version": "2.0.17",
"version": "2.0.18",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "opencommit",
"version": "2.0.17",
"version": "2.0.18",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.10.0",

View File

@@ -1,6 +1,6 @@
{
"name": "opencommit",
"version": "2.0.17",
"version": "2.0.18",
"description": "Auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
"keywords": [
"git",

View File

@@ -1,6 +1,5 @@
import { execa } from 'execa';
import {
GenerateCommitMessageErrorEnum,
generateCommitMessageByDiff
} from '../generateCommitMessageFromGitDiff';
import {

View File

@@ -80,7 +80,7 @@ export const configValidators = {
}
validateConfig(
CONFIG_KEYS.OCO_OPENAI_MAX_TOKENS,
typeof value === 'number',
value ? typeof value === 'number' : undefined,
'Must be a number'
);
@@ -117,8 +117,8 @@ export const configValidators = {
[CONFIG_KEYS.OCO_MODEL](value: any) {
validateConfig(
CONFIG_KEYS.OCO_OPENAI_BASE_PATH,
value === 'gpt-3.5-turbo' || value === 'gpt-4',
CONFIG_KEYS.OCO_MODEL,
['gpt-3.5-turbo', 'gpt-4'].includes(value),
`${value} is not supported yet, use 'gpt-4' or 'gpt-3.5-turbo' (default)`
);
return value;
@@ -134,12 +134,12 @@ const configPath = pathJoin(homedir(), '.opencommit');
export const getConfig = (): ConfigType | null => {
const configFromEnv = {
OCO_OPENAI_API_KEY: process.env.OCO_OPENAI_API_KEY,
OCO_OPENAI_MAX_TOKENS: Number(process.env.OCO_OPENAI_MAX_TOKENS),
OCO_OPENAI_MAX_TOKENS: process.env.OCO_OPENAI_MAX_TOKENS ? Number(process.env.OCO_OPENAI_MAX_TOKENS) : undefined,
OCO_OPENAI_BASE_PATH: process.env.OCO_OPENAI_BASE_PATH,
OCO_DESCRIPTION: process.env.OCO_DESCRIPTION === 'true' ? true : false,
OCO_EMOJI: process.env.OCO_EMOJI === 'true' ? true : false,
OCO_MODEL: process.env.OCO_MODEL,
OCO_LANGUAGE: process.env.OCO_LANGUAGE
OCO_MODEL: process.env.OCO_MODEL || 'gpt-3.5-turbo',
OCO_LANGUAGE: process.env.OCO_LANGUAGE || 'en'
};
const configExists = existsSync(configPath);
@@ -149,6 +149,10 @@ export const getConfig = (): ConfigType | null => {
const config = iniParse(configFile);
for (const configKey of Object.keys(config)) {
if (!config[configKey] || ['null', 'undefined'].includes(config[configKey])) {
config[configKey] = undefined;
continue;
}
try {
const validator = configValidators[configKey as CONFIG_KEYS];
const validValue = validator(

View File

@@ -74,9 +74,6 @@ export enum GenerateCommitMessageErrorEnum {
emptyMessage = 'EMPTY_MESSAGE'
}
interface GenerateCommitMessageError {
error: GenerateCommitMessageErrorEnum;
}
const INIT_MESSAGES_PROMPT_LENGTH = INIT_MESSAGES_PROMPT.map(
(msg) => tokenCount(msg.content) + 4

View File

@@ -5,8 +5,8 @@
"module": "ESNext",
// "rootDir": "./src",
"moduleResolution": "node",
"resolveJsonModule": true,
"moduleResolution": "node",
"allowJs": true,