Skip to content

Commit

Permalink
(nvim) Add script that injects AI-generated commit messages
Browse files Browse the repository at this point in the history
  • Loading branch information
malkoG committed Sep 13, 2023
1 parent d29a407 commit 81190cb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions private_dot_config/nvim/after/plugin/neoai-extended.lua
@@ -0,0 +1,20 @@
local inject_commit_message = function()
-- `vim.ui.select` function's behavior is asyncronous.
--
-- So, In order to generate commit message by selected language,
-- we have to place `generate_commit_message` inside of `vim.ui.select` function's callback
vim.ui.select(
{"korean", "english"},
{
prompt = "Select language: ",
},
function(language)
if language ~= nil then
local prompt = require('utilities.prompt-engineering').generate_commit_message(language)
require("neoai").context_inject(prompt, nil)
end
end
)
end

vim.api.nvim_create_user_command("InjectCommitMessage", inject_commit_message, {})
21 changes: 21 additions & 0 deletions private_dot_config/nvim/lua/utilities/prompt-engineering.lua
@@ -0,0 +1,21 @@
local M = {}

M.generate_commit_message = function(language)
local prompt = [[
Using the following git diff generate a consise and
clear git commit message, with a short title summary
that is 75 characters or less
]] .. " and you should generate commit message in " .. language .. [[:
]] .. [[
```
]] .. vim.fn.system("git diff --cached")
.. [[
```
And you shoud give me commit message immediately.
And you don't need to explain unnecessary things.
]]

return prompt
end

return M

0 comments on commit 81190cb

Please sign in to comment.