Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ add conventional commits, and gitmoji cli flags #163

Closed
wants to merge 35 commits into from

Conversation

NorkzYT
Copy link

@NorkzYT NorkzYT commented Mar 20, 2023

Built on-top of the current PR of #160.

Commands to use after forking repo and switching to this PR:

pnpm i
pnpm build
node ./dist/cli.mjs

New flag information:

Flag for conventional commits:
Entire flag =--conventional
Alias = -c

Flag for gitmoji:
Entire flag = --gitmoji
Alias = -m

These are listed as Booleans in the code, although I could not figure out how to allow the use of true or `false.

To use conventional commits and gitmoji, run the following command:

node ./dist/cli.mjs -c -m

Example output 1:

Command:
node ./dist/cli.mjs

Add prompt for commit message formatting in generateCommitMessage function

This commit adds a prompt for commit message formatting in the generateCommitMessage function. The prompt is added after the base prompt and before the gitMojiExtraContext. This change helps ensure that commit messages conform to a consistent format. The text-davinci-003 model has a token limit of 4000, and this change does not affect this limit.

Example output 2:

Command:
node ./dist/cli.mjs -c

feat(openai): add prompt for generating commit messages

This commit adds a prompt for generating commit messages using OpenAI's GPT-3 API. The prompt includes a base prompt, a commit message format prompt, and an extra context prompt using gitMoji. The text-davinci-003 model has a token limit of 4000, and the prompt was updated to include an empty line for better readability.

Example output 3:

Command:
node ./dist/cli.mjs -c -m

🚀 feat: add base prompt and gitmoji context to commit message generation

This commit updates the `generateCommitMessage` function to include the `basePrompt` and `gitMojiExtraContext` in the `prompt` variable. The `prompt` variable 
is used to generate the commit message. This change allows for more information to be included in the commit message, making it more descriptive and helpful. 

Currently, the way that the prompt uses gitmoji's is insufficient, thus I will work on a way to retrieve the gitmoji's from the official api, and parse the prompt.

ThijSlim and others added 15 commits March 16, 2023 22:49
…ource code, paving the way for adding Gitmoji in a similar way.
…adds support for using Gitmoji and Conventional Commits in the CLI by introducing two new flags
This commit fixes a bug where an unnecessary whitespace was added in the commit message prompt in aicommits.ts file. The code was cleaned up by removing the whitespace to make the prompt more visually appealing.
This commit increases the timeout for https request from 10s to 20s to account for longer response times.
@NorkzYT NorkzYT changed the title feat: conventional commits, and gitmoji cli flags feat: add conventional commits, and gitmoji cli flags Mar 20, 2023
@ThijSlim
Copy link
Contributor

ThijSlim commented Mar 20, 2023

Very nice :D

I think passing it with just arguments without true and false is nice. If you look at https://github.com/folke/devmoji they put gitmoji after the conventional commit. Probably because conventional commits can be grouped by convention type and having the emoji in front of the message probably makes that harder.

<contentional commit type>: <gitmoji> <message>

I think it is a good idea to get the gitmoji from the official api. From a user perspective, I think Gitmoji users are used to selecting a Gitmoji from a list, when they are committing. Perhaps we can give 3 - 4 Gitmoji suggestions (with the AI Model) that most relate to the commit message, for the user to choose from.

I also think we should mark Gitmoji and Conventional as (experimental) in the flag description and maybe some documentation. Or we can Dark launch it by not documenting it.

@NorkzYT
Copy link
Author

NorkzYT commented Mar 20, 2023

Thank you for the explanation, I was wondering why you had <contentional commit type>: <gitmoji> <message>, and now I know. I will revert back. I did make a way to get the Gitmoji from the API, although I am messing with the prompt since it's not always accurate with the conventional commit scope, such as feat:.

I say it would be best to push as experimental and add documentation.

@ThijSlim
Copy link
Contributor

ThijSlim commented Mar 20, 2023

I also wonder if you ran the tests after all your changes. a lot of them are now failing. Also I created some tests that should correspond to a certain conventional commit type. I also saw that you removed the extra context for conventional commit types. That was there on purpose for GPT to be more accurate on selecting the types.

pnpm build
OPENAI_KEY=<OPENAI_KEY> pnpm test

@ThijSlim
Copy link
Contributor

pnpm build
OPENAI_KEY=<OPENAI_KEY> pnpm test

@NorkzYT
Copy link
Author

NorkzYT commented Mar 20, 2023

Strange, I ran pnpm test, and all 5 checks have passed.

I needed to temporarily remove the conventional commit types to experiment with a different prompt since it was very long. I will add it back.

@ThijSlim
Copy link
Contributor

There are 16 tests now, so maybe some of them didn't run on your machine :)

@NorkzYT
Copy link
Author

NorkzYT commented Mar 20, 2023

Do you receive Skipping tests on Windows because Node.js spawn cant open TTYs in your console when you run pnpm test?

Currently I do not see all the 16 tests. Do I copy your tests folder from your fork to get up to date?

@ThijSlim
Copy link
Contributor

ThijSlim commented Mar 20, 2023

I do see them in this PR diff. I am using a Macbook.

tests/specs/cli.ts

@NorkzYT
Copy link
Author

NorkzYT commented Mar 20, 2023

Understood, I am going to switch to a Linux system.

NorkzYT added 3 commits March 20, 2023 16:10
This commit updates the .editorconfig file to use single quotes for strings by adding the `quote_type` property and setting it to `single`. This improves the consistency of the codebase and makes it easier to read and maintain.
This commit adds a new function to retrieve gitmojis by calling an external API with a fetch request. The function returns an array of objects with the properties `emoji` and `description`.
This commit updates the httpsPost timeout to 30 seconds and adds a new gitmoji to the prompt. The prompt now includes a new "🧐" gitmoji to signify data exploration/inspection.
@NorkzYT
Copy link
Author

NorkzYT commented Mar 20, 2023

@thijslimmen

I will keep working on this later, or tomorrow. I re-added the extra context for conventional commit types. Added the gitmoji api, and changed the prompt.

The commit message generation function had an extra '}' in the title, which was causing a syntax error. This has been fixed by removing the extra character.
Update the function getCommitTitleFormatPrompt in openai.ts to include a required gitmoji in the commit title.
Update the README file with information about the --generate flag, --gitmoji flag, --conventional flag, combine flags, and configure default flags
@ThijSlim
Copy link
Contributor

ThijSlim commented Mar 22, 2023

I am really happy about the current PR. I will improve on unit testing this evening (GMT+1). Shall we then think about releasing it? 🚀

Update wording of the conventional commit descriptions to be grammatically correct.
type: Boolean,
description: '(Experimental) Enable the use of Gitmoji',
alias: 'm',
},
Copy link
Contributor

@ThijSlim ThijSlim Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This alias overlaps with -m in git commit

Reading this commit above:
/**
* Since this is a wrapper around git commit,
* flags should not overlap with it
* https://git-scm.com/docs/git-commit
*/

@NorkzYT
Copy link
Author

NorkzYT commented Mar 22, 2023

I am really happy about the current PR. I will improve on unit testing this evening (GMT+1). Shall we then think about releasing it? 🚀

I agree. Although before that I would like to work on adding the GPT4 model option in this GitHub PR.

I am in the GMT -4/UTC -4 time zone.

@NorkzYT NorkzYT changed the title feat: add conventional commits, and gitmoji cli flags feat: ✨ add conventional commits, and gitmoji cli flags Mar 22, 2023
@ThijSlim
Copy link
Contributor

In my opinion we should complete this with GPT3.5. Also GPT4 is not publicly available and heavily throttled, so for now it is a nice to have which we can implement in a new PR

@NorkzYT
Copy link
Author

NorkzYT commented Mar 22, 2023

Understood. Agreed.

Rename the test files for better code organization and maintainability.
Add a new test case in the openai.spec.ts file to test the generateCommitMessage function. The test generates the git diff message and logs it for testing purposes.
@ThijSlim ThijSlim force-pushed the conventional-commits branch from 57860f9 to a86fbbf Compare March 22, 2023 18:18
…sting a React application 🔬

The git diff contains changes related to testing a React application. The conventional commit type should be "test".
Update test timeout to 20 seconds in vitest.config.ts
@ThijSlim
Copy link
Contributor

@NorkzYT I've done the following things.

  • Added vitest as unit test library which makes it possible to run tests concurrently, really fast feedback now
  • Added unit tests for just the openai.ts class. I am using ChatGPT to generate a git diff based on some description to validate if correct conventional types are being used. This works really good! also pretty easy to setup a test case.

You should run, tests are really fast 💯 :

pnpm build; OPENAI_KEY=<OPENAI_KEY>pnpm test

I do see some things that are not working too often:

  • Gitmoji is provided 70% of the time
  • When using conventional commits, the japanese language is sometimes not applied, also sometimes without conventional commits

I think the above happens, because the prompt is getting bigger and the subtle context is lost. We have to find a way to add some weight to certain things to make sure it is always applied.

We could also use a Semantic kernal pattern which validates the output and does some retrying until a certain condition is meet.

https://github.com/microsoft/semantic-kernel

@privatenumber
Copy link
Collaborator

Thanks for submitting the PR! I appreciate the effort you've put into making these changes. While some of them are quite beneficial, a few may require further discussion before we can proceed.

To smoothen the review process, would you mind dividing up the changes into smaller PRs? For each PR, please provide a brief explanation of the issue you're addressing, as this will offer context for review.

@ThijSlim
Copy link
Contributor

@privatenumber Sure! I will create some smaller PRs. I think that will help you review the changes

@NorkzYT
Copy link
Author

NorkzYT commented Mar 23, 2023

@thijslimmen

Great work mate!

I will look into the prompt issue to find a way to weigh the prompt to increase accuracy of both the issues you mentioned.

@ThijSlim
Copy link
Contributor

ThijSlim commented Mar 23, 2023

I think with splitting this PR we will find the issues eventually. I already saw that with the way we did the new prompt, the original prompting was broken. I am now making a PR for just conventional commits. This will make reviewing and adding features in the feature even better

@NorkzYT
Copy link
Author

NorkzYT commented Mar 23, 2023

Understood, and agreed.

@privatenumber
Copy link
Collaborator

Sounds good! Just so we're on the same page, smaller PRs ideally consist of 1~3 files. That should streamline review to deploy and help get your contributions in faster.

Additionally, it would be helpful if you could separate any large or non-essential changes, such as refactors, into a separate PR. This way, we can ensure that high-priority features are not delayed by lower-priority modifications.

Thanks again, your contribution is greatly appreciated!

@ThijSlim
Copy link
Contributor

I continued in PR #168

The Source code is now +- 4 files (including config files). Only code is updated that is related to supporting conventional commits.

I did improve a lot on the testing strategy, because it was really hard to test my changes. These changes are a bit bigger, but these should make reviewing easier.

I hope this helps :)

@ThijSlim
Copy link
Contributor

ThijSlim commented Mar 23, 2023

@Nutlope you can close this PR. It will remain as reference for future changes like Gitmoji and Commit Title + Description

@NorkzYT NorkzYT closed this Mar 23, 2023
@NorkzYT NorkzYT deleted the conventional-commits branch March 8, 2024 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants