GithubHelp home page GithubHelp logo

di-sukharev / opencommit Goto Github PK

View Code? Open in Web Editor NEW
5.4K 23.0 272.0 4.13 MB

Auto-generate impressive commits with AI in 1 second πŸ€―πŸ”«

Home Page: https://www.npmjs.com/package/opencommit

License: MIT License

TypeScript 1.70% JavaScript 98.30%
ai ai-commit artificial-intelligence chatgpt git gpt productivity ai-commits

opencommit's People

Contributors

adrielbento avatar alexcgomez avatar avighnac avatar bennycode avatar di-sukharev avatar dmazlum avatar ericklima-ca avatar esmerlinjm avatar ewiththebowtie avatar gamoreli avatar imload avatar ingwarsw avatar jaroslaw-weber avatar jeroensmink98 avatar jessicakuijer avatar jlopezlira avatar jlukic avatar joshuahamlet avatar km-tr avatar linhdangquang avatar malpou avatar mathsgod avatar matt-degraffenreid avatar moret84 avatar nader-zouaoui avatar openefit avatar sectex avatar superstructor avatar takuya-o avatar willyw0nka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opencommit's Issues

Accept / Reject + Edit

Currently one can only Accept or Reject the proposed commit message - add an option to edit the message (using $EDITOR)

[Feature Request] Pull request title based on files diff

Context

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.

Example

➜ 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

Bug: Use '--' to separate paths from revisions

image

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

POV

# env
GIT_WORK_TREE=/home/abc
GIT_DIR=/home/abc/dotfiles

FEAT: Support to enforce conventional commits, custom scopes and amend other tool commits

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!!

Feature request: add a dry run mode

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"

Feature: How to commit with the rules of commitlint config file

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
  },
};

Error after generating commit : ERR_TTY_INIT_FAILED

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.

press `TAB` to generate new commit message/s

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.

Feature: Commit-message Prefix

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

[FEATURE REQUEST] `push` automatically with a config FORCE_PUSH

  • I do not want to be asked to push commits and do not want the commits pushed by oc.
    • Alternatively, some people may want the option to automatically push commits without being asked.
  • Some people, not me, but some people may want the commit message used automatically without confirmation.

These all seem like great things to add as options IMHO.

Language settings feature

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.

Option to edit the commit before accepting

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.

FAQ from ConventionalCommits

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.

Error: Request failed with status code 400

β—“  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.

Error when commits are done

Howdy, thank you very much for this amazing tool.

I am using it, but I encountered an error when the commit finished, here is the error.

image

Internal error when generating commit message

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 :
image

Can someone please provide guidance on how to resolve this issue? Thank you.

Request failed with status code 429

β—“  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.

zsh: command not found: oc

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.

Configurable API endpoint

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

Suggestion for improving "git push"

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']);

Commits in GitKraken

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?

Feature: Work with husky

Problem:

Opencommit only works with git hooks.

Solution:

Refactor the code to add some dynamic logic to the tool

Explanation:

  1. 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.

  2. 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;
      }
    };
    
  3. 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);
    };
    
  4. Replace the variable calls isHookCalled and isHookExists with the function call await isHookCalled() and await isHookExists() respectively.

Scenarios Tested

When core.hooksPath is not set

  • Can you run opencommit from the command line - Yes
  • Can you set opencommit as a hook - Yes
  • Can you run open commit as a hook - Yes
  • Can you unset opencommit as a hook - Yes

When core.hooksPath is set to .husky

  • Can you run opencommit from the command line - Yes
  • Can you set opencommit as a hook - Yes
  • Can you run open commit as a hook - Yes
  • Can you unset opencommit as a hook - Yes

What code is sent where?

Very cool tool!

As far as I can tell are only the git diff sent to ChatGPT? Am I correct or is there more?

Setting OPENAI_API_KEY throws an error : SyntaxError: Unexpected token '.'

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.

Infinite loop setting the key

  • When adding the openAI token, the code show the same error message.

  • My machine is a macbook pro m2 , running on Ventura 13.12.1

Screenshot 2023-03-10 at 15 50 51

Bug?: Untracked files still end up in the commit context

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:

  • Make some changes to a file
  • Add a file, but don't add it to git
  • Run git commit to activate the hook

In my case it generated a commit message that mentioned the untracked files, as well as the one file that was tracked and had changes.

XDG config location

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.

Allow opencommit to be installed as a devDependency

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?

git commit --amend

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?

One message for a group of x files

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"

Suggest adding 'Edit' option to the Yes/No confirmation

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.)

Feature: Support git commit prefixes

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?

Commits in VSCode

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.