di-sukharev / opencommit Goto Github PK
View Code? Open in Web Editor NEWGenerate conventional git commit messages with AI in 1 second π€―π«
Home Page: https://www.npmjs.com/package/opencommit
License: MIT License
Generate conventional git commit messages with AI in 1 second π€―π«
Home Page: https://www.npmjs.com/package/opencommit
License: MIT License
This tool is too awesome to use for free.
A feature request.
Currently, if we don't like the generated commit message we would select "No" in the confirm prompt then rerun oc
to generate a new message.
Would be nice and convenient to just press TAB
to generate a new one.
The tool looks promising, but as an avid remote dev environment (think github codespaces, gitpod) user I find it hard to install and store config globally.
I would probably need to make a custom image in order to restore the global environment each time I open the workspace.
Would you consider an .env fallback for the config values or something of sort in order to make this easier?
Hi and thanks for this amazing tool!! it changes my life!! (really).
I just have a suggestion for git pushes.
I often use other divergent streams for "git push" as you can get if you type "git remote -v".
My projects have streams for deploys or just for github for example. (origin main or heroku main)
Could we maybe add something like this on line 48 of file "commit.ts"? :
const { stdout } = await execa('git', ['push', '-u', 'origin', 'HEAD']);
Would be nice to have the opportunity to configure a unique message for a batch of files.
Concrete example:
In the exampel below, I introduced a new enum and started using it inside 4 existing files. Then I would like to have a single message in a single commit that is simply "refactor: added SvgElementType constants"
So instead of:
β
β 4 staged files:
src/features/Picture/screens/CanvasEdit/SvgCanvasDrawMode.js
src/features/Picture/screens/CanvasEdit/SvgViewer.js
src/features/Picture/screens/CanvasEdit/__tests__/SvgViewer.test.js
src/features/Picture/screens/CanvasEdit/constants.js
β
β π Commit message generated
β
β Commit message:
ββββββββββββββββββ
feat(SvgCanvasDrawMode.js): add SvgElementType constant to newElement object
feat(SvgViewer.js): add support for SvgElementType constants in ELEMENT_VIEWERS map
test(SvgViewer.test.js): add tests for SvgElementType constants
feat(constants.js): add SvgElementType constants for SVG elements
ββββββββββββββββββ
β
β Confirm the commit message
β No
β
β β process cancelled
I would like something generating:
git commit -m"refactor: added SvgElementType constants"
Generating the commit message
β
β β Error: Request failed with status code 429
It would be nice to have the most important messages first. I noticed that the current order is set by code occurrence which is not always desired
The current prompt summarizes all changes in several CC commits. This is not very helpful when skimming the gitlog, as information gets lost. Also the the CC Website suggests to only use one type.
What do I do if the commit conforms to more than one of the commit types?
Go back and make multiple commits whenever possible. Part of the benefit of Conventional Commits is its ability to drive us to make more organized commits and PRs.
In addition to sort the text by importance - like Issue #71 suggested - I would like to see the first line summarize the changes in their entirety and/or give me the possibility to edit the text instead of just accepting or rejecting it.
oc
β open-commit
β
β 1 staged files:
.config/hyprland/hyprland.conf
/home/abc/.node_modules/lib/node_modules/opencommit/out/cli.cjs:17320
error = new Error(message);
^
Error: Command failed with exit code 128: git diff --staged .config/hyprland/hyprland.
conf
fatal: ambiguous argument '.config/hyprland/hyprland.conf': unknown revision or path n
ot in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
at makeError (/home/abc/.node_modules/lib/node_modules/opencommit/out/cli.cjs:1732
0:13)
at handlePromise (/home/abc/.node_modules/lib/node_modules/opencommit/out/cli.cjs:
17635:29)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async getDiff (/home/abc/.node_modules/lib/node_modules/opencommit/out/cli.cjs:
17724:28)
at async commit (/home/abc/.node_modules/lib/node_modules/opencommit/out/cli.cjs:2
0939:38) {
shortMessage: 'Command failed with exit code 128: git diff --staged .config/hyprland
/hyprland.conf',
command: 'git diff --staged .config/hyprland/hyprland.conf',
escapedCommand: 'git diff --staged ".config/hyprland/hyprland.conf"',
exitCode: 128,
signal: undefined,
signalDescription: undefined,
stdout: '',
stderr: "fatal: ambiguous argument '.config/hyprland/hyprland.conf': unknown revisio
n or path not in the working tree.\n" +
"Use '--' to separate paths from revisions, like this:\n" +
"'git <command> [<revision>...] -- [<file>...]'",
failed: true,
timedOut: false,
isCanceled: false,
killed: false
}
Node.js v19.8.1
# env
GIT_WORK_TREE=/home/abc
GIT_DIR=/home/abc/dotfiles
The tool did a great job of generating the message. I would have liked to add a note about who suggested the fix.
Also, another time, it got a huge amount right but also got something wrong. I would have liked to fix it without losing the AI contribution. (In that case, I copied the message, said No and did a conventional commit with edited text.)
Hey, first of all awesome tool
I want to know if there is something about conventional commits (or any other preset like angular) into the tool, would be awesome for workflows that use extensively commit lint.
Also, there is some way that you can choose the scope? Would be great for monorepos where scopes usually belongs to the package that is being modified.
Finally, would be great if this tool can amend the commit after the manual writing of the commit, this could help for integration with other git tools like commitizen.
Keep the awesome work!!
I'm thinking about changing some message patterns on the lib configurations, ie removing the *
from the beginning of the messages. Is that doable?
Allow to use other API offerings like the one from AzureOpenAi- which shall have compatible api but private model which is especially relevant if source code is not OS. Configuring another non default API url might already be sufficient
Hello. I entered a repository/project. Installed opencommit (oc) globally via yarn add global opencommit
, and when I go to assign api key or emoji to true, I receive the above error: zsh: command not found: oc
OR zsh: command not found: opencommit
. I am using wsl 2 on Windows 11. I am not sure if that is the problem. I went through the same process running zsh on my MacBook and it works fine.
First of all: wow it works great in the CLI, this is going to save me a lot of time.
Is it possible to make it work in GitKraken as well? I have set the hook, and it is recognized by the client, but I need to type a commit message before I can click the commit button.
GitKraken then says that the hook exited with error code 127. In the logs I see this: /usr/bin/env 'node': file or folder doesn't exist
. When I execute /usr/bin/env node
in my terminal it works, so GitKraken seems to have some sort of other context.
I tried changing the first line of the hook to #!/home/lars/.nvm/versions/node/v16.18.1/bin/node
(since that is the full path to my node executable). GitKraken then says that the hook executed succesfully, but it didn't change the commit text that I needed to type to be able to click on the commit button...
What to do to fix this? Or what can I do to debug this further?
Does it make sense to add a dry run mode to the oc
command?
It goes like:
input:
oc --dry-run
output:
commit message:
feat(someFeature): some message
git command:
git commit -m "feat(someFeature): some message"
Set support for Spanish Language. I will solve this issue.
I have a commit lint config file before every commits it follows the guideline of my commit rules. so how can I ensure that your opeancommit message follows the rules of my commit config.
my commit rules is :
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'body-leading-blank': [2, 'always'], // enforce a blank line between subject and body
'footer-leading-blank': [2, 'always'], // enforce a blank line between body and footer
'header-max-length': [2, 'always', 100], // enforce a maximum header length of 100 characters
'body-empty': [2, 'never'], // enforce to write a body
'scope-empty': [2, 'never'], // enforce a non-empty scope
'subject-empty': [2, 'never'], // enforce a non-empty subject
'subject-full-stop': [2, 'never', '.'], // enforce no trailing period in subject
'type-empty': [2, 'never'], // enforce a non-empty type
'type-enum': [
2,
'always',
['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore'],
], // enforce a list of valid types
},
};
We use semanic branchnames like:
feature/PROJECT-123-a-nice-new-feature
or bug/PROJECT-456-oh-no-a-bug
that will contain the Project ID and its Ticket Number.
The Project ID and Ticket-number are also referenced in the Commits, making it easy to link them in the Ticket. So a commit would look like the following:
PROJECT-123
chore(package.json) updates some dependencies.
feat(src/components/someComponent.tsx) Implement awesome feature
It would be nice to be able to do that with opencommit
I know that the purpose of the CLI is to help create commit messages, but it would be nice to have the option to suggest pull request titles based on differences in modified files.
In this example, the user should copy the suggested title, I don't think there's a simple way to automate this.
β opencommit --pull-request
β open-commit
β
β 1 staged files:
example-repo/test.js
β
β π Commit message generated
β
β Commit message:
ββββββββββββββββββ
* feat(test.js): add test file
ββββββββββββββββββ
β
β Confirm the commit message
β Yes
β
β β successfully committed
β
β [main] * feat(test.js): add test file
1 files changed, 1 insertions(+), 0 deletions(-)
β
β π Pull Request title generated
β
β Pull Request title:
ββββββββββββββββββ
* feat: Create sample test file
ββββββββββββββββββ
β
β Do you want to run `git push`?
β Yes
β
β β successfully pushed all commits
Hi, I'm happy to contribute to this. My work requires that the ticket be referenced in all commit messages e.g. foo-1243-feature-button-component
. I'm wondering if it is viable to make the commits reference the ticket number from the branch name e.g. feat/foo-1234-button
would result in commit messages being prefixed with foo-1234: blah blah
?
How is this use case supported? I am often doing git add -p
with an initial git commit
and then iterate with git add -p
and git commit --amend
until happy - how to generate the final commit message?
the function checkIsLatestVersion
always returns that version is not latest..
Very cool tool!
As far as I can tell are only the git diff sent to ChatGPT? Am I correct or is there more?
oc
.
These all seem like great things to add as options IMHO.
Would it be possible to integrate it into VSCode? In this way, when making the commits from there, we would not have to go through the terminal.
I use vs code and hook and generated message has fist line 177 characters long but imho git has limit 72
Thanks
Currently one can only Accept or Reject the proposed commit message - add an option to edit the message (using $EDITOR)
I followed the setup steps
When I get to this step :
opencommit config set OPENAI_API_KEY=XXXXX
I get this error :
.nvm/versions/node/v12.13.0/lib/node_modules/opencommit/out/cli.cjs:15050
throw new Error(`${n} cannot contain ${h(r2?.[0])}`);
^
SyntaxError: Unexpected token '.'
at Module._compile (internal/modules/cjs/loader.js:892:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
at internal/main/run_main_module.js:17:11
I tried to generate a new API key from OpenAI but it does the same.
Error running config api key command:
opencommit config set sk-iQixtQCJ61k8jbqsENVnT3Bl****************
β opencommit β config
β
β β Error: Unsupported config key: sk-iQixtQCJ61k8jbqsENVnT3Bl****************
I am encountering an internal error when trying to generating commit message. The error message I received is " β internal error, try again."
I am using OpenCommit version v1.1.10 and from VSCode bash terminal. I have already tried restart and reinstalling, but the error persists.
Error changed to :
Can someone please provide guidance on how to resolve this issue? Thank you.
Don't know if this is intended or not, or if there is a config flag to disable the behavior. It seems as though making a commit in which there are some untracked files, still references the untracked files.
To reproduce:
git commit
to activate the hookIn my case it generated a commit message that mentioned the untracked files, as well as the one file that was tracked and had changes.
β Generating the commit message.
β
β β Error: Request failed with status code 400
It may be that the country I am in is not supported.
I can't find where to set it the proxy.
It would be good if the configuration file could be located somewhere else. In particular, it would be nice to have it located where the XDG specification states (https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html), so you can have all your files under $XDG_CONFIG_HOME.
It should not be a difficult change and will allow us to have a cleaner home and an easier configuration backup.
The ability of setting the config file via environment variable (like OC_CONFIG=~/.opencommit), or using an environment variable to configure the software (like OPENAI_API_KEY=MyKey) would also be welcomed.
It looks like this currently uses gpt-3.5-turbo
. If someone has access to gpt-4
, I think they should be able to set this with config.
Config: VS Code on Windows 11
Getting error ERR_TTY_INIT_FAILED when generating commit.
οΏ½[90mβοΏ½[39m Commit message:
ββββββββββββββββββ
fix(AppMailUseCase.ts): add notEmpty filter to notifications array in deleteMail method
ββββββββββββββββββ
node:internal/errors:477
ErrorCaptureStackTrace(err);
^
SystemError [ERR_TTY_INIT_FAILED]: TTY initialization failed: uv_tty_init returned EBADF (bad file descriptor)
at new SystemError (node:internal/errors:238:5)
at new NodeError (node:internal/errors:349:7)
at new WriteStream (node:tty:94:11)
at sD2.prompt (C:\Users\svad\AppData\Roaming\npm\node_modules\opencommit\out\cli.cjs:15719:16)
at Q3 (C:\Users\svad\AppData\Roaming\npm\node_modules\opencommit\out\cli.cjs:15891:8)
at generateCommitMessageFromGitDiff (C:\Users\svad\AppData\Roaming\npm\node_modules\opencommit\out\cli.cjs:17756:41)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async commit (C:\Users\svad\AppData\Roaming\npm\node_modules\opencommit\out\cli.cjs:17807:3) {
code: 'ERR_TTY_INIT_FAILED',
info: {
errno: -4083,
code: 'EBADF',
message: 'bad file descriptor',
syscall: 'uv_tty_init'
},
errno: [Getter/Setter],
syscall: [Getter/Setter]
}
I have same error when using command oc, or using VS Code commit button with git hook set.
Opencommit only works with git hooks.
Refactor the code to add some dynamic logic to the tool
Identify hooks' path in the repo you are working in. This can be accomplished with the following command:
git config core.hooksPath
This needed to be translated into a util function for git so I wrote the following function:
export const getCoreHooksPath = async(): Promise<string> => {
const { stdout } = await execa('git', [
'config',
'core.hooksPath']);
return stdout;
}
Note: the function throws an error when there is no set path that needs to be caught when used.
Determine the path by invoking getCoreHooksPath
catch the error and give the DEFAULT_SYMLINK_URL
if core.hooksPath
is not set.
const getHooksPath = async (): Promise<string> => {
try {
const hooksPath = await getCoreHooksPath();
return `${hooksPath}/${HOOK_NAME}`;
} catch (error) {
return DEFAULT_SYMLINK_URL;
}
};
Refactor our two helper functions to utilize the getHooksPath
function.
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);
};
Replace the variable calls isHookCalled
and isHookExists
with the function call await isHookCalled()
and await isHookExists()
respectively.
When core.hooksPath is not set
When core.hooksPath is set to .husky
What you thing would it be a good idea to translate this project to Swedish?
β Generating the commit message.
β
β β Error: Request failed with status code 429
Introducing a minor modification (adding two new rows) to a compact file,
which consists of approximately 25 lines of code, results in an error.
Hello,
is it possible to add feature to set language of commit message?
There are possibilities to change conversation's language in ChatGPT.
Thank you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.