Compare commits

...

63 Commits

Author SHA1 Message Date
di-sukharev
1080544631 2.0.12 2023-05-04 16:38:28 +08:00
di-sukharev
de68e6cc7a docs(README.md): add instructions for configuring openAI maxTokens and BASE_PATH parameters to customize API usage 2023-05-04 16:38:02 +08:00
di-sukharev
5addb7df25 2.0.11 2023-05-04 14:29:11 +08:00
di-sukharev
e447575980 2.0.10 2023-05-04 14:29:05 +08:00
di-sukharev
ffebbc6e1b docs: update opencommit-example.png to reflect recent changes in UI 2023-05-04 14:28:55 +08:00
di-sukharev
dab0f58d14 2.0.9 2023-05-04 12:52:22 +08:00
di-sukharev
226e21c28f 2.0.8 2023-05-04 12:52:14 +08:00
di-sukharev
0bb89abccc Merge remote-tracking branch 'origin/dev' 2023-05-04 12:51:35 +08:00
Tanoshii
ad70a90b1f Update commit.ts (#154)
* fixed type
2023-05-04 12:50:09 +08:00
di-sukharev
4deaf56e5a 2.0.7 2023-05-04 12:42:30 +08:00
di-sukharev
7c1fc10248 2.0.6 2023-05-04 12:42:24 +08:00
di-sukharev
0c25a9e32c Merge branch 'dev' 2023-05-04 12:41:35 +08:00
Juan José López Lira
3f5df6ef7c Bugfix/increase tokens (#132)
* feat(api.ts): add support for OPENAI_MAX_TOKENS environment variable
feat(config.ts): add OPENAI_MAX_TOKENS to CONFIG_KEYS and configValidators

* 2.0.2

* 2.0.3

* docs(README.md): add GPT-4 usage instructions and mention the cost difference compared to GPT-3.5-turbo

---------

Co-authored-by: di-sukharev <dim.sukharev@gmail.com>
2023-05-04 12:33:06 +08:00
di-sukharev
6cb85e40e9 2.0.5 2023-04-28 15:36:53 +08:00
di-sukharev
ba82d4d476 2.0.4 2023-04-28 15:36:45 +08:00
di-sukharev
9bf2ed34a5 docs(README.md): add GPT-4 usage instructions and mention the cost difference compared to GPT-3.5-turbo 2023-04-28 15:35:40 +08:00
di-sukharev
f6ab25ed1b 2.0.3 2023-04-28 15:31:54 +08:00
di-sukharev
83abd5ffd6 2.0.2 2023-04-28 15:31:46 +08:00
di-sukharev
42c26cbaaa fix(generateCommitMessageFromGitDiff.ts): update content to include WHAT and WHY in commit message instructions
fix(i18n/en.json): update commitFix and commitFeat messages to include reasons for changes
2023-04-28 15:31:10 +08:00
di-sukharev
51613c2aea feat(api.ts, config.ts): add support for custom model selection in OpenAi class
feat(config.ts): add model validation in configValidators
2023-04-28 15:29:32 +08:00
Sukharev
f04757f8af Revert "Suggest adding 'Edit' option to the Yes/No confirmation #53 (#70)" (#146)
This reverts commit 70f048672c.
2023-04-28 14:25:29 +08:00
Joshua Hamlet
70f048672c Suggest adding 'Edit' option to the Yes/No confirmation #53 (#70) 2023-04-28 14:22:45 +08:00
di-sukharev
a8a548ba5a 2.0.1 2023-04-28 14:15:39 +08:00
di-sukharev
eb09d5f4f6 Merge remote-tracking branch 'origin/dev' 2023-04-28 14:13:49 +08:00
Devrim Mazlum
801f6a9e7a feat(i18n): add support for Turkish (Türkçe) language (tr) (#110)
* feat(index.ts): Turkish language support

* feat(tr.json): Turkish language support
2023-04-17 01:14:34 +08:00
zenobit
b4f1bbdfe0 🌐 chore(i18n): add Czech language (#127)
* 🌐 chore(i18n): add Czech language

* 📦 chore(package-lock.json): aktualizace balíčku @dqbd/tiktoken na verzi 1.0.6
Byl aktualizován balíček @dqbd/tiktoken na verzi 1.0.6, což zahrnuje opravy chyb a zlepšení výkonu.
2023-04-17 01:09:51 +08:00
di-sukharev
1ecad09e44 chore(package.json): update package version from 1.1.51 to 2.0.0 2023-04-06 12:42:46 +08:00
di-sukharev
c57b5e394d 1.1.51 2023-04-06 12:30:14 +08:00
di-sukharev
8100d9beb8 1.1.50 2023-04-06 12:30:06 +08:00
di-sukharev
84997faea2 feat(package.json): add 'oco' alias for the 'opencommit' command line tool 2023-04-06 12:29:56 +08:00
di-sukharev
8f60345008 docs: update README.md
- Update information about the OpenAI model used by OpenCommit and its cost
2023-04-05 13:13:45 +08:00
Sukharev
c148048452 Create dependency-review.yml 2023-04-05 13:05:36 +08:00
Sukharev
add8855bf9 Create codeql.yml 2023-04-05 13:05:09 +08:00
di-sukharev
0cc5be10f2 1.1.49 2023-04-05 13:01:36 +08:00
di-sukharev
30d2d9d284 1.1.48 2023-04-05 13:01:28 +08:00
di-sukharev
d69fa6c2d7 Merge branch 'master' of github.com:di-sukharev/opencommit 2023-04-05 13:01:17 +08:00
di-sukharev
bf3b8c6ded chore(.yml): remove Close Stale Issues action from workflow. 2023-04-05 13:00:57 +08:00
Sukharev
f851ea1fff Create stale.yml 2023-04-05 13:00:29 +08:00
di-sukharev
d6cbaf5f5f refactor(tokenCount.ts): remove commented out code and unused import statement 2023-04-05 12:55:45 +08:00
di-sukharev
220d0b292f 1.1.47 2023-04-05 12:55:22 +08:00
di-sukharev
e5d3c8d4ff 1.1.46 2023-04-05 12:55:16 +08:00
di-sukharev
cbc8d61f99 feat(.yml): add GitHub Action to close stale issues using actions/stale@v4.1.1 2023-04-05 12:54:38 +08:00
di-sukharev
7fd357e78e 1.1.45 2023-04-05 12:45:01 +08:00
di-sukharev
5837d1fa2e 1.1.44 2023-04-05 12:44:54 +08:00
di-sukharev
36f282d8a5 Merge branch 'dev' 2023-04-05 12:44:30 +08:00
Raymond
9f65c450e3 build(esbuild.config.js): add esbuild configuration file and move build command to it (#82)
feat(package.json): add @dqbd/tiktoken dependency
fix(tokenCount.ts): uncomment Tiktoken import and encoding, and return token length instead of an approximation
2023-04-05 12:42:07 +08:00
di-sukharev
d5f53fec5a 1.1.43 2023-04-05 12:36:17 +08:00
di-sukharev
b6651a4c47 1.1.42 2023-04-05 12:36:13 +08:00
di-sukharev
2b10dc089c refactor(githook.ts): remove unused platform variable and switch statement
fix(githook.ts): change DEFAULT_SYMLINK_URL to use relative path instead of absolute path
2023-04-05 12:35:23 +08:00
di-sukharev
a5e60ac23c 1.1.41 2023-04-05 12:32:13 +08:00
di-sukharev
e519752938 1.1.40 2023-04-05 12:32:09 +08:00
di-sukharev
1ba5e20228 chore(TODO.md): add task to set max commit message length to improve commit message quality 2023-04-05 12:31:42 +08:00
di-sukharev
4103bafc4f chore(TODO.md): add task to try setting max commit message length 2023-04-05 12:30:01 +08:00
kimlym
5a9b460033 feat(api.ts): add support for OPENAI_BASE_PATH configuration variable (#80)
feat(config.ts): add OPENAI_BASE_PATH configuration key and validator function

Co-authored-by: yiminglu <yiming.lu@mioying.com>
2023-04-05 12:26:02 +08:00
l2D
3364289034 feat(i18n): add support for Thai (ไทย) language (th) (#117)
* feat(i18n): add Thai language support and translations for commit messages
2023-04-05 12:24:44 +08:00
Matt
5185f3365c Feature work with husky (#47) (#79)
* refactor(cli.ts): call isHookCalled function asynchronously

feat(githook.ts): add support for git core hooks path and fallback to default symlink url if not found

feat(utils/git.ts): add getCoreHooksPath function to retrieve the path of the core hooks directory.

* refactor(githook.ts): remove console.log statement from hookCommand function

* feat(prepare-commit-msg-hook.ts): add isStageAllFlag parameter to prepareCommitMessageHook function to stage all changes if flag is true

* refactor(githook.ts): use path.join to join path segments instead of string concatenation
style(githook.ts): format code with prettier
2023-04-01 13:29:22 +08:00
di-sukharev
17ed061f73 Merge branch 'dev' of github.com:di-sukharev/opencommit into dev 2023-04-01 13:25:57 +08:00
di-sukharev
06fa6daa72 1.1.39 2023-04-01 13:24:57 +08:00
Erick Amorim
6ba0f97163 Add support for the Android platform (#105) 2023-04-01 13:18:52 +08:00
Matt
0d559d4499 Issue templates (#78)
* Create bug.yaml

* adding issue templates

* Create featureRequest.yaml
2023-03-31 18:12:43 +08:00
zankyr
686f876cb0 [STYLE] Update commit messages using proper Italian language (#96)
* style(it.json): update commit message language to use proper Italian grammar and spelling
2023-03-31 18:11:39 +08:00
Manato
acf3e450ae chore(i18n): update Japanese translation for commit messages (#98)
Updated the Japanese translation for commit messages to reflect the changes made in the previous commit. The commitFix message now correctly states that the port variable was changed from lowercase 'port' to uppercase 'PORT'. The commitFeat message now correctly states that support for the 'process.env.PORT' environment variable was added. The commitDescription message explains that the use of the constant 'PORT' for the port variable provides consistency in naming conventions, and that the support for the 'process.env.PORT' environment variable allows the application to be more flexible and run on any available port specified by the environment variable.
2023-03-31 18:11:06 +08:00
Karol Lassak
8be30a734d feat(i18n): add support for Polish language (#102)
* feat(i18n): add support for Polish language
2023-03-31 18:09:17 +08:00
28 changed files with 483 additions and 73 deletions

91
.github/ISSUE_TEMPLATE/bug.yaml vendored Normal file
View File

@@ -0,0 +1,91 @@
name: 🐞 Bug Report
description: File a bug report
title: "[Bug]: "
labels: ["bug", "triage"]
assignees:
- octocat
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: input
id: opencommit-version
attributes:
label: Opencommit Version
description: What version of our software are you running?
placeholder: ex. 1.1.22
validations:
required: true
- type: input
id: node-version
attributes:
label: Node Version
description: What version of node are you running?
placeholder: ex. 19.8.1
validations:
required: true
- type: input
id: npm-version
attributes:
label: NPM Version
description: What version of npm are you running?
placeholder: ex. 9.6.2
validations:
required: true
- type: dropdown
id: OS
attributes:
label: What OS are you seeing the problem on?
multiple: true
options:
- Mac
- Windows
- Other Linux Distro
- type: textarea
id: what-happened
attributes:
label: What happened?
description: Also tell us, what did you expect to happen?
placeholder: Tell us what you see!
value: "A bug happened!"
validations:
required: true
- type: textarea
id: expected-behavior
attributes:
label: Expected Behavior
description: Also tell us, what did you expect to happen?
placeholder: Tell us what you expected to happen!
validations:
required: true
- type: textarea
id: current-behavior
attributes:
label: Current Behavior
description: Also tell us, what is currently happening?
placeholder: Tell us what is happening now.
validations:
required: true
- type: textarea
id: possible-solution
attributes:
label: Possible Solution
description: Do you have a solution for the issue?
placeholder: Tell us what the solution could look like.
validations:
required: false
- type: textarea
id: steps-to-reproduce
attributes:
label: Steps to Reproduce
description: Tell us how to reproduce the issue?
placeholder: Tell us how to reproduce the issue?
validations:
required: false
- type: textarea
id: logs
attributes:
label: Relevant log output
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
render: shell

View File

@@ -0,0 +1,48 @@
---
name: 🛠️ Feature Request
description: Suggest an idea to help us improve Opencommit
title: "[Feature]: "
labels:
- "feature_request"
body:
- type: markdown
attributes:
value: |
**Thanks :heart: for taking the time to fill out this feature request report!**
We kindly ask that you search to see if an issue [already exists](https://github.com/di-sukharev/opencommit/issues?q=is%3Aissue+sort%3Acreated-desc+) for your feature.
We are also happy to accept contributions from our users. For more details see [here](https://github.com/di-sukharev/opencommit/blob/master/.github/CONTRIBUTING.md).
- type: textarea
attributes:
label: Description
description: |
A clear and concise description of the feature you're interested in.
validations:
required: true
- type: textarea
attributes:
label: Suggested Solution
description: |
Describe the solution you'd like. A clear and concise description of what you want to happen.
validations:
required: true
- type: textarea
attributes:
label: Alternatives
description: |
Describe alternatives you've considered.
A clear and concise description of any alternative solutions or features you've considered.
validations:
required: false
- type: textarea
attributes:
label: Additional Context
description: |
Add any other context about the problem here.
validations:
required: false

1
.github/TODO.md vendored
View File

@@ -8,3 +8,4 @@
- [x] batch small files in one request
- [] add tests
- [] optimize prompt, maybe no prompt would be cleaner
- [] try setting max commit msg length, maybe it will make commits short and more concise

Binary file not shown.

Before

Width:  |  Height:  |  Size: 318 KiB

After

Width:  |  Height:  |  Size: 304 KiB

76
.github/workflows/codeql.yml vendored Normal file
View File

@@ -0,0 +1,76 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [ "master" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
schedule:
- cron: '21 16 * * 0'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"

20
.github/workflows/dependency-review.yml vendored Normal file
View File

@@ -0,0 +1,20 @@
# Dependency Review Action
#
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
#
# Source repository: https://github.com/actions/dependency-review-action
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
name: 'Dependency Review'
on: [pull_request]
permissions:
contents: read
jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
- name: 'Dependency Review'
uses: actions/dependency-review-action@v2

28
.github/workflows/stale.yml vendored Normal file
View File

@@ -0,0 +1,28 @@
# This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time.
#
# You can adjust the behavior by modifying this file.
# For more information, see:
# https://github.com/actions/stale
name: Mark stale issues and pull requests
on:
schedule:
- cron: '27 21 * * *'
jobs:
stale:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v5
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 40
stale-issue-message: 'Stale issue message'
stale-pr-message: 'Stale pull request message'
stale-issue-label: 'no-issue-activity'
stale-pr-label: 'no-pr-activity'

View File

@@ -54,6 +54,18 @@ oc
## Features
### Switch to GPT-4
By default OpenCommit uses GPT-3.5-turbo (ChatGPT).
You may switch to GPT-4 which performs better, but costs ~x15 times more 🤠
```sh
oc config set model=gpt-4
```
Make sure you do lowercase `gpt-4`.
### Preface commits with emoji 🤠
[GitMoji](https://gitmoji.dev/) convention is used.
@@ -84,6 +96,24 @@ To remove description:
oc config set description=false
```
### Configure openAI maxTokens param
Default value for `maxTokens` is 196, sometimes you can get 400 error if request+response exceeds `maxToken` parameter.
so you can increase it:
```sh
oc config set OPENAI_MAX_TOKENS=<number>
```
### Configure BASE_PATH for openAI api
if you want to call GPT via proxy — you can change `BASE_PATH` parameter:
```sh
oc config set OPENAI_BASE_PATH=<string>
```
### Internationalization support
To specify the language used to generate commit messages:
@@ -99,6 +129,7 @@ oc config set language=fr
oc config set language=French
oc config set language=française
```
The default language set is **English**
All available languages are currently listed in the [i18n](https://github.com/di-sukharev/opencommit/tree/master/src/i18n) folder
@@ -117,6 +148,7 @@ git commit -m "${generatedMessage}" --no-verify
```
### Ignore files
You can ignore files from submission to OpenAI by creating a `.opencommitignore` file. For example:
```ignorelang
@@ -155,4 +187,4 @@ Or follow the process of your IDE Source Control feature, when it calls `git com
## Payments
You pay for your own requests to OpenAI API. OpenCommit uses ChatGPT official model, that is ~10x times cheaper than GPT-3 and ~6x times cheaper than GPT-4.
You pay for your own requests to OpenAI API. OpenCommit uses ChatGPT (3.5-turbo) official model, that is ~15x times cheaper than GPT-4.

14
esbuild.config.js Normal file
View File

@@ -0,0 +1,14 @@
import { build } from 'esbuild'
import fs from 'fs'
await build({
entryPoints: ['./src/cli.ts'],
bundle: true,
platform: 'node',
format: 'cjs',
outfile: './out/cli.cjs',
});
const wasmFile = fs.readFileSync('./node_modules/@dqbd/tiktoken/lite/tiktoken_bg.wasm')
fs.writeFileSync('./out/tiktoken_bg.wasm', wasmFile)

11
package-lock.json generated
View File

@@ -1,15 +1,16 @@
{
"name": "opencommit",
"version": "1.1.38",
"version": "2.0.12",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "opencommit",
"version": "1.1.38",
"version": "2.0.12",
"license": "MIT",
"dependencies": {
"@clack/prompts": "^0.6.1",
"@dqbd/tiktoken": "^1.0.2",
"axios": "^1.3.4",
"chalk": "^5.2.0",
"cleye": "^1.3.2",
@@ -21,6 +22,7 @@
},
"bin": {
"oc": "out/cli.cjs",
"oco": "out/cli.cjs",
"opencommit": "out/cli.cjs"
},
"devDependencies": {
@@ -83,6 +85,11 @@
"node": ">=12"
}
},
"node_modules/@dqbd/tiktoken": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/@dqbd/tiktoken/-/tiktoken-1.0.6.tgz",
"integrity": "sha512-umSdeZTy/SbPPKVuZKV/XKyFPmXSN145CcM3iHjBbmhlohBJg7vaDp4cPCW+xNlWL6L2U1sp7T2BD+di2sUKdA=="
},
"node_modules/@esbuild/android-arm": {
"version": "0.15.18",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.15.18.tgz",

View File

@@ -1,6 +1,6 @@
{
"name": "opencommit",
"version": "1.1.38",
"version": "2.0.12",
"description": "GPT CLI to auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
"keywords": [
"git",
@@ -17,7 +17,8 @@
"main": "cli.js",
"bin": {
"opencommit": "./out/cli.cjs",
"oc": "./out/cli.cjs"
"oc": "./out/cli.cjs",
"oco": "./out/cli.cjs"
},
"repository": {
"url": "https://github.com/di-sukharev/opencommit"
@@ -40,7 +41,7 @@
"watch": "npm run -S build -- --sourcemap --watch",
"start": "node ./out/cli.cjs",
"dev": "ts-node ./src/cli.ts",
"build": "rimraf out && esbuild ./src/cli.ts --bundle --outfile=out/cli.cjs --format=cjs --platform=node",
"build": "rimraf out && node esbuild.config.js",
"deploy": "npm run build && npm version patch && npm publish --tag latest",
"lint": "eslint src --ext ts && tsc --noEmit",
"format": "prettier --write src"
@@ -60,6 +61,7 @@
},
"dependencies": {
"@clack/prompts": "^0.6.1",
"@dqbd/tiktoken": "^1.0.2",
"axios": "^1.3.4",
"chalk": "^5.2.0",
"cleye": "^1.3.2",

View File

@@ -12,6 +12,8 @@ import { CONFIG_MODES, getConfig } from './commands/config';
const config = getConfig();
let apiKey = config?.OPENAI_API_KEY;
let basePath = config?.OPENAI_BASE_PATH;
let maxTokens = config?.OPENAI_MAX_TOKENS;
const [command, mode] = process.argv.slice(2);
@@ -28,23 +30,31 @@ if (!apiKey && command !== 'config' && mode !== CONFIG_MODES.set) {
process.exit(1);
}
const MODEL = config?.model || 'gpt-3.5-turbo';
class OpenAi {
private openAiApiConfiguration = new OpenAiApiConfiguration({
apiKey: apiKey
});
private openAI!: OpenAIApi;
private openAI = new OpenAIApi(this.openAiApiConfiguration);
constructor() {
if (basePath) {
this.openAiApiConfiguration.basePath = basePath;
}
this.openAI = new OpenAIApi(this.openAiApiConfiguration);
}
public generateCommitMessage = async (
messages: Array<ChatCompletionRequestMessage>
): Promise<string | undefined> => {
try {
const { data } = await this.openAI.createChatCompletion({
model: 'gpt-3.5-turbo',
model: MODEL,
messages,
temperature: 0,
top_p: 0.1,
max_tokens: 196
max_tokens: maxTokens ?? 196
});
const message = data.choices[0].message;

View File

@@ -22,7 +22,8 @@ cli(
},
async () => {
// await checkIsLatestVersion();
if (isHookCalled) {
if (await isHookCalled()) {
prepareCommitMessageHook();
} else {
commit(extraArgs);

View File

@@ -73,7 +73,7 @@ ${chalk.grey('——————————————————')}`
...extraArgs
]);
outro(`${chalk.green('✔')} successfully committed`);
outro(`${chalk.green('✔')} Successfully committed`);
outro(stdout);
@@ -102,7 +102,7 @@ ${chalk.grey('——————————————————')}`
]);
pushSpinner.stop(
`${chalk.green('✔')} successfully pushed all commits to ${remotes[0]}`
`${chalk.green('✔')} Successfully pushed all commits to ${remotes[0]}`
);
if (stdout) outro(stdout);
@@ -126,7 +126,7 @@ ${chalk.grey('——————————————————')}`
pushSpinner.stop(
`${chalk.green(
'✔'
)} successfully pushed all commits to ${selectedRemote}`
)} Successfully pushed all commits to ${selectedRemote}`
);
if (stdout) outro(stdout);

View File

@@ -10,8 +10,11 @@ import { getI18nLocal } from '../i18n';
export enum CONFIG_KEYS {
OPENAI_API_KEY = 'OPENAI_API_KEY',
OPENAI_MAX_TOKENS = 'OPENAI_MAX_TOKENS',
OPENAI_BASE_PATH = 'OPENAI_BASE_PATH',
description = 'description',
emoji = 'emoji',
model = 'model',
language = 'language'
}
@@ -61,6 +64,16 @@ export const configValidators = {
return value;
},
[CONFIG_KEYS.OPENAI_MAX_TOKENS](value: any) {
validateConfig(
CONFIG_KEYS.OPENAI_MAX_TOKENS,
typeof value === 'number',
'Must be a number'
);
return value;
},
[CONFIG_KEYS.emoji](value: any) {
validateConfig(
CONFIG_KEYS.emoji,
@@ -78,6 +91,24 @@ export const configValidators = {
`${value} is not supported yet`
);
return getI18nLocal(value);
},
[CONFIG_KEYS.OPENAI_BASE_PATH](value: any) {
validateConfig(
CONFIG_KEYS.OPENAI_BASE_PATH,
typeof value == 'string',
`${value} is not supported yet`
);
return value;
},
[CONFIG_KEYS.model](value: any) {
validateConfig(
CONFIG_KEYS.OPENAI_BASE_PATH,
value === 'gpt-3.5-turbo' || value === 'gpt-4',
`${value} is not supported yet, use 'gpt-4' or 'gpt-3.5-turbo' (default)`
);
return value;
}
};
@@ -128,7 +159,7 @@ export const setConfig = (keyValues: [key: string, value: string][]) => {
writeFileSync(configPath, iniStringify(config), 'utf8');
outro(`${chalk.green('✔')} config successfully set`);
outro(`${chalk.green('✔')} Config successfully set`);
};
export const configCommand = command(

View File

@@ -1,35 +1,33 @@
import fs from 'fs/promises';
import path from 'path';
import { command } from 'cleye';
import { assertGitRepo } from '../utils/git.js';
import { assertGitRepo, getCoreHooksPath } from '../utils/git.js';
import { existsSync } from 'fs';
import chalk from 'chalk';
import { intro, outro } from '@clack/prompts';
import { COMMANDS } from '../CommandsEnum.js';
const platform = process.platform;
let separator = '';
switch (platform) {
case 'win32': // Windows
separator = path.sep;
break;
case 'darwin': // macOS
separator = '';
break;
case 'linux': // Linux
separator = '';
break;
default:
throw new Error(`Unsupported platform: ${platform}`);
}
const HOOK_NAME = 'prepare-commit-msg';
const SYMLINK_URL = path.join(separator, '.git', 'hooks', HOOK_NAME);
const DEFAULT_SYMLINK_URL = path.join('.git', 'hooks', HOOK_NAME);
export const isHookCalled = process.argv[1].endsWith(`${SYMLINK_URL}`);
const getHooksPath = async (): Promise<string> => {
try {
const hooksPath = await getCoreHooksPath();
return path.join(hooksPath, HOOK_NAME);
} catch (error) {
return DEFAULT_SYMLINK_URL;
}
};
const isHookExists = existsSync(SYMLINK_URL);
export const isHookCalled = async (): Promise<boolean> => {
const hooksPath = await getHooksPath();
return process.argv[1].endsWith(hooksPath);
};
const isHookExists = async (): Promise<boolean> => {
const hooksPath = await getHooksPath();
return existsSync(hooksPath);
};
export const hookCommand = command(
{
@@ -38,16 +36,16 @@ export const hookCommand = command(
},
async (argv) => {
const HOOK_URL = __filename;
const SYMLINK_URL = await getHooksPath();
try {
await assertGitRepo();
const { setUnset: mode } = argv._;
if (mode === 'set') {
intro(`setting OpenCommit as '${HOOK_NAME}' hook`);
intro(`setting opencommit as '${HOOK_NAME}' hook at ${SYMLINK_URL}`);
if (isHookExists) {
if (await isHookExists()) {
let realPath;
try {
realPath = await fs.realpath(SYMLINK_URL);
@@ -72,9 +70,11 @@ export const hookCommand = command(
}
if (mode === 'unset') {
intro(`unsetting OpenCommit as '${HOOK_NAME}' hook`);
intro(
`unsetting opencommit as '${HOOK_NAME}' hook from ${SYMLINK_URL}`
);
if (!isHookExists) {
if (!(await isHookExists())) {
return outro(
`OpenCommit wasn't previously set as '${HOOK_NAME}' hook, nothing to remove`
);
@@ -92,7 +92,7 @@ export const hookCommand = command(
}
throw new Error(
`unsupported mode: ${mode}. Supported modes are: 'set' or 'unset'`
`Unsupported mode: ${mode}. Supported modes are: 'set' or 'unset'`
);
} catch (error) {
outro(`${chalk.red('✖')} ${error}`);

View File

@@ -7,7 +7,9 @@ import { generateCommitMessageWithChatCompletion } from '../generateCommitMessag
const [messageFilePath, commitSource] = process.argv.slice(2);
export const prepareCommitMessageHook = async () => {
export const prepareCommitMessageHook = async (
isStageAllFlag: Boolean = false
) => {
try {
if (!messageFilePath) {
throw new Error(
@@ -17,16 +19,16 @@ export const prepareCommitMessageHook = async () => {
if (commitSource) return;
const stagedFiles = await getStagedFiles();
const changedFiles = await getChangedFiles();
if (isStageAllFlag) {
const changedFiles = await getChangedFiles();
if (!stagedFiles && !changedFiles) {
outro('No changes detected, write some code and run `oc` again');
process.exit(1);
if (changedFiles) await gitAdd({ files: changedFiles });
else {
outro('No changes detected, write some code and run `oc` again');
process.exit(1);
}
}
if (!stagedFiles && changedFiles) await gitAdd({ files: changedFiles });
const staged = await getStagedFiles();
if (!staged) return;

View File

@@ -15,7 +15,7 @@ const INIT_MESSAGES_PROMPT: Array<ChatCompletionRequestMessage> = [
{
role: ChatCompletionRequestMessageRoleEnum.System,
// prettier-ignore
content: `You are to act as the author of a commit message in git. Your mission is to create clean and comprehensive commit messages in the conventional commit convention and explain why a change was done. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
content: `You are to act as the author of a commit message in git. Your mission is to create clean and comprehensive commit messages in the conventional commit convention and explain WHAT were the changes and WHY the changes were done. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
${config?.emoji? 'Use GitMoji convention to preface the commit.': 'Do not preface the commit with anything.'}
${config?.description ? 'Add a short description of WHY the changes are done after the commit message. Don\'t start it with "This commit", just describe the changes.': "Don't add any descriptions to the commit, only commit message."}
Use the present tense. Lines must not be longer than 74 characters. Use ${translation.localLanguage} to answer.`

6
src/i18n/cs.json Normal file
View File

@@ -0,0 +1,6 @@
{
"localLanguage": "česky",
"commitFix": "fix(server.ts): zlepšení velikosti proměnné port na velká písmena PORT",
"commitFeat": "feat(server.ts): přidání podpory pro proměnnou prostředí process.env.PORT",
"commitDescription": "Proměnná port se nyní jmenuje PORT, což odpovídá konvenci pojmenování, protože PORT je konstanta. Podpora proměnné prostředí process.env.PORT umožňuje snadnější správu nastavení při spuštění."
}

View File

@@ -1,6 +1,6 @@
{
"localLanguage": "english",
"commitFix": "fix(server.ts): change port variable case from lowercase port to uppercase PORT",
"commitFeat": "feat(server.ts): add support for process.env.PORT environment variable",
"commitFix": "fix(server.ts): change port variable case from lowercase port to uppercase PORT to improve semantics",
"commitFeat": "feat(server.ts): add support for process.env.PORT environment variable to be able to run app on a configurable port",
"commitDescription": "The port variable is now named PORT, which improves consistency with the naming conventions as PORT is a constant. Support for an environment variable allows the application to be more flexible as it can now run on any available port specified via the process.env.PORT environment variable."
}

View File

@@ -1,4 +1,5 @@
import en from '../i18n/en.json' assert { type: 'json' };
import cs from '../i18n/cs.json' assert { type: 'json' };
import de from '../i18n/de.json' assert { type: 'json' };
import fr from '../i18n/fr.json' assert { type: 'json' };
import it from '../i18n/it.json' assert { type: 'json' };
@@ -13,12 +14,16 @@ import sv from '../i18n/sv.json' assert { type: 'json' };
import nl from '../i18n/nl.json' assert { type: 'json' };
import ru from '../i18n/ru.json' assert { type: 'json' };
import id_ID from '../i18n/id_ID.json' assert { type: 'json' };
import pl from '../i18n/pl.json' assert { type: 'json' };
import tr from '../i18n/tr.json' assert { type: 'json' };
import th from '../i18n/th.json' assert { type: 'json' };
export enum I18nLocals {
'en' = 'en',
'zh_CN' = 'zh_CN',
'zh_TW' = 'zh_TW',
'ja' = 'ja',
'cs' = 'cs',
'de' = 'de',
'fr' = 'fr',
'nl' = 'nl',
@@ -28,7 +33,10 @@ export enum I18nLocals {
'es_ES' = 'es_ES',
'sv' = 'sv',
'ru' = 'ru',
'id_ID' = 'id_ID'
'id_ID' = 'id_ID',
'pl' = 'pl',
'tr' = 'tr',
'th' = 'th',
}
export const i18n = {
@@ -36,6 +44,7 @@ export const i18n = {
zh_CN,
zh_TW,
ja,
cs,
de,
fr,
it,
@@ -46,7 +55,10 @@ export const i18n = {
sv,
id_ID,
nl,
ru
ru,
pl,
tr,
th
};
export const I18N_CONFIG_ALIAS: { [key: string]: string[] } = {
@@ -54,6 +66,7 @@ export const I18N_CONFIG_ALIAS: { [key: string]: string[] } = {
zh_TW: ['zh_TW', '繁體中文', '繁體'],
ja: ['ja', 'Japanese', 'にほんご'],
ko: ['ko', 'Korean', '한국어'],
cs: ['cs', 'Czech', 'česky'],
de: ['de', 'German', 'Deutsch'],
fr: ['fr', 'French', 'française'],
it: ['it', 'Italian', 'italiano'],
@@ -64,7 +77,10 @@ export const I18N_CONFIG_ALIAS: { [key: string]: string[] } = {
es_ES: ['es_ES', 'Spanish', 'español'],
sv: ['sv', 'Swedish', 'Svenska'],
ru: ['ru', 'Russian', 'русский'],
id_ID: ['id_ID', 'Bahasa', 'bahasa']
id_ID: ['id_ID', 'Bahasa', 'bahasa'],
pl: ['pl', 'Polish', 'Polski'],
tr: ['tr', 'Turkish', 'Turkish'],
th: ['th', 'Thai', 'ไทย']
};
export function getI18nLocal(value: string): string | boolean {

View File

@@ -1,6 +1,6 @@
{
"localLanguage": "italiano",
"commitFix": "fix(server.ts): cambia il caso della variabile di porta da minuscolo port a maiuscolo PORT",
"commitFeat": "funzionalità(server.ts): aggiungi supporto per la variabile di ambiente process.env.PORT",
"commitDescription": "La variabile di porta è ora chiamata PORT, il che migliora la coerenza con le convenzioni di denominazione in quanto PORT è una costante. Il supporto per una variabile di ambiente consente all'applicazione di essere più flessibile poiché ora può essere eseguita su qualsiasi porta disponibile specificata tramite la variabile di ambiente process.env.PORT."
"commitFix": "fix(server.ts): cambia la grafia della variabile della porta dal minuscolo port al maiuscolo PORT",
"commitFeat": "feat(server.ts): aggiunge il supporto per la variabile di ambiente process.env.PORT",
"commitDescription": "La variabile port è ora chiamata PORT, migliorando la coerenza con le convenzioni di denominazione in quanto PORT è una costante. Il supporto per una variabile di ambiente consente all'applicazione di essere più flessibile poiché ora può essere eseguita su qualsiasi porta disponibile specificata tramite la variabile di ambiente process.env.PORT."
}

View File

@@ -1,6 +1,6 @@
{
"localLanguage": "にほんご",
"commitFix": "修正(server.ts): ポート変数のケースを小文字のポートから大文字のPORTに変更",
"commitFeat": "新機能(server.ts): process.env.PORT環境変数のサポートを追加する",
"commitDescription": "ポート変数は現在PORTという名前になっており、PORTは定数であるため命名規則に一貫性があります。環境変数サポートにより、アプリケーションはより柔軟になり、process.env.PORT環境変数で指定された任意の利用可能なポートで実行できるようになりまし"
"localLanguage": "日本語",
"commitFix": "修正(server.ts): ポート変数を小文字のportから大文字のPORTに変更",
"commitFeat": "新機能(server.ts): 環境変数process.env.PORTのサポートを追加",
"commitDescription": "ポート変数は現在PORTという名前になり、定数であるPORTを使うことで命名規則に一貫性が生まれました。環境変数サポートすることで、環境変数process.env.PORTで指定された任意の利用可能なポートで実行できるようになり、アプリケーションはより柔軟になりました。"
}

6
src/i18n/pl.json Normal file
View File

@@ -0,0 +1,6 @@
{
"localLanguage": "polski",
"commitFix": "fix(server.ts): poprawa wielkości zmiennej port na pisane z dużymi literami PORT",
"commitFeat": "feat(server.ts): dodanie obsługi zmiennej środowiskowej process.env.PORT",
"commitDescription": "Zmienna port jest teraz nazwana PORT, co jest zgodne z konwencją nazewniczą ponieważ PORT jest stałą. Obsługa zmiennej środowiskowej process.env.PORT pozwala łatwiej zarządzać ustawieniami przy starcie."
}

6
src/i18n/th.json Normal file
View File

@@ -0,0 +1,6 @@
{
"localLanguage": "ไทย",
"commitFix": "fix(server.ts): เปลี่ยนตัวพิมพ์ของตัวแปร จากตัวพิมพ์เล็ก port เป็นตัวพิมพ์ใหญ่ PORT",
"commitFeat": "feat(server.ts): เพิ่มการรองรับสำหรับตัวแปรสภาพแวดล้อม process.env.PORT",
"commitDescription": "ตอนนี้ตัวแปรพอร์ตมีชื่อว่า PORT, ซึ่งปรับปรุงความสอดคล้องกับหลักการตั้งชื่อเนื่องจาก PORT เป็นค่าคงที่. การสนับสนุนสำหรับตัวแปรสภาพแวดล้อม ช่วยให้แอปพลิเคชันมีความยืดหยุ่นมากขึ้นเนื่องจาก สามารถทำงานบนพอร์ตใด ๆ ตามที่กำหนด ซึ่งระบุผ่านตัวแปรสภาพแวดล้อม process.env.PORT"
}

6
src/i18n/tr.json Normal file
View File

@@ -0,0 +1,6 @@
{
"localLanguage": "Turkish",
"commitFix": "fix(server.ts): port değişkeni küçük harfli porttan büyük harfli PORT'a değiştirildi",
"commitFeat": "feat(server.ts): process.env.PORT ortam değişkeni için destek eklendi.",
"commitDescription": "Bağlantı noktası değişkeni artık PORT olarak adlandırıldı ve PORT bir sabit değişken olduğu için bu adlandırma tutarlılığı artırır. Ortam değişkeni desteği, artık process.env.PORT ortam değişkeni aracılığıyla belirtilen herhangi bir kullanılabilir bağlantı noktasında çalışabileceğinden uygulamanın daha esnek olmasını sağlar."
}

View File

@@ -25,6 +25,14 @@ export const getOpenCommitIgnore = (): Ignore => {
return ig;
};
export const getCoreHooksPath = async(): Promise<string> => {
const { stdout } = await execa('git', [
'config',
'core.hooksPath']);
return stdout;
}
export const getStagedFiles = async (): Promise<string[]> => {
const { stdout: gitDir } = await execa('git', [
'rev-parse',

View File

@@ -1,14 +1,13 @@
// import { Tiktoken } from '@dqbd/tiktoken/lite';
// import cl100k_base from '@dqbd/tiktoken/encoders/cl100k_base.json' assert { type: 'json' };
import { Tiktoken } from '@dqbd/tiktoken/lite';
import cl100k_base from '@dqbd/tiktoken/encoders/cl100k_base.json' assert { type: 'json' };
export function tokenCount(content: string): number {
// const encoding = new Tiktoken(
// cl100k_base.bpe_ranks,
// cl100k_base.special_tokens,
// cl100k_base.pat_str
// );
// const tokens = encoding.encode(content);
// encoding.free();
return content.length / 2.7;
const encoding = new Tiktoken(
cl100k_base.bpe_ranks,
cl100k_base.special_tokens,
cl100k_base.pat_str
);
const tokens = encoding.encode(content);
encoding.free();
return tokens.length;
}