Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a TODO list with tasks that need to be completed. These tasks include building for both mjs and cjs, configuring esbuild to make the bundle smaller, adding // TODOs in the code, batching small files in one request, adding tests, and making the hook work. * β¨ feat(api.ts): add OpenAI class with generateCommitMessage method This commit adds a new OpenAI class with a generateCommitMessage method that uses the OpenAI API to generate a commit message based on an array of messages. The method takes an array of ChatCompletionRequestMessage objects and returns a Promise that resolves to a ChatCompletionResponseMessage object. The OpenAI class is exported as a singleton instance named api. * β¨ feat(prepare-commit-msg-hook.ts): add support for generating commit messages with chat completion This commit adds support for generating commit messages with chat completion. The `prepare-commit-msg-hook.ts` file now imports the `generateCommitMessageWithChatCompletion` function from the `generateCommitMessageFromGitDiff` module. The function generates a commit message based on the staged git diff and appends it to the commit message file. If the `OPENAI_API_KEY` environment variable is not set, an error is thrown. If the commit source is specified, the function returns without generating a commit message. * π feat(generateCommitMessageFromGitDiff.ts): add functionality to generate commit messages from git diff This commit adds a new file, generateCommitMessageFromGitDiff.ts, which contains a function that generates commit messages from the output of the 'git diff --staged' command. The function uses the OpenAI API to prompt the user to create a commit message in the conventional commit convention. The user can choose to use Gitmoji convention to preface the commit and add a short description of what the commit is about. * π fix(server.ts): change port variable case from lowercase port to uppercase PORT * β¨ feat(server.ts): add support for process.env.PORT environment variable 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. * π feat: add function to generate commit messages from diff This commit adds a new function that generates commit messages from a diff. The function takes a diff as input and splits it into files. It then generates commit messages for each file and returns them as a concatenated string. If the total length of the commit message exceeds the maximum allowed length, the function skips the file. If the commit message is empty, the function skips the file. If an error occurs during the process, the function returns an error. * β¨ feat(git.ts): add function to assert git repository existence * β¨ feat(git.ts): add function to get staged git diff The assertGitRepo function checks if the current directory is a git repository by running the 'git rev-parse' command. If the command fails, an error is thrown. The getStagedGitDiff function returns the staged diff of the git repository. It takes an optional boolean argument isStageAllFlag, which when true stages all changes before getting the diff. The function uses the 'git diff --staged' command to get the diff and excludes big files from the diff. The function returns an object with two properties: files, which is an array of the names of the files that have changes, and diff, which is the diff of the staged changes.
- Loading branch information