added a new file First major commit Successful POST of new comment 🚀 Updated README Updated README 📕 Added more infrastructure Creating async job More setup Getting arguments from Neovim -> Lua -> Golang Moved commands Added getProjectInfo command Adding make comment command Setting up arguments for MakeComment command Removed extraneous comments Setup basic function for adding comments Lint fixes Handling bad requests correctly Better formatting Printing success message Adding utility table print Set comment from popup UI Added mappings for closing and sending text Moved popup into separate file Added comment Cleaned up code and added approve command Initialize project information Removed extraneous import Don't initialize project in non-gitlab directories Setup approve command Set up revoke and approve commands correctly Cleaned up redundant code Moved get current branch command Reorganization of the code First attempt to add step installing Go binary Adjusted path to binary Added install bin check Do Lua method Fixed install step Tweaked binPath + bin Added basic readme information 📗 Removed .luarc.json file Adding diffview command Added string_starts function Made base branch configurable Added note to readme Fixed readme Added diffview dep to readme Update README.md Update README.md Update README.md Update README.md Renamed files Set up developer workflow Updated README Removed dev note Refactor and moving around files Fixed ft/after mappings Setup read command Added read summary command Got rid of filetype bindings and set up commands Set correct filetype for comment buffer Added read() command to README Updated review -> summary Fixed issue with diffview buffers Added command for getting and showing all comments (out of order) Better error message Adding more code to handle showing comments Added ability to jump from comment to specific changed buffer line Initial refactor Added simple comment action Fixed error message More cleanup Fixed bug with M.PROJECT_ID Leaving comment refactor Fixed comment Cleaned up old code Added missing exit command Check gitlab repo status before initialization Better help strings Added ListDiscussions command Added Go code Darkened metadata, filtered out non-real discussions Removed dummy log Sort the discussions by most recent activity Grab hash of current discussion Wired up reply action in Lua code Moved to NUI Table Adding basic jump-to-file ability More tweaks Allow jump anywhere in the tree Ability to reply directly in the buffer window Jump to location in file Don't jump if no refresh is set Cleaned up mappings + other code Get rid of gitlab CLI dependency Fixed discussions bug Don't initialize client on main/master branches Moved comment into separate module Moved lua modules into separate files Modularized library and state Slightly better error/exception handling Added license file Updated readme Moved into todo.md file Added todo file Standardized naming conventions (snake_case in Lua, camelCase in Go) Moved common popup state into utils folder Cleaned up keymapping functions Note on install Changing bin path Updated README Chnaged from success to info Redirect output to /dev/null on build Checking install code Removed print statement Slight reorganization Setting up delete comment Set up confirmation modal Passing in node ID to delete_comment Functioning comment deletion Added delete_comment command Updated README Furhter modularized discussion code Cleaned up and refactored reply code Update README.md Added ability to edit comments Updated todos Fixed main/master base branch issue Set up keybinding rules Updated todo.md Removed diffview dependency Slight cleanup 🧹 Trying something out... Trying something for the binary... Trying again Fixed install for non-lazy users Update README.md Update README.md Update README.md Update README.md Update README.md
172 lines
5.5 KiB
Markdown
172 lines
5.5 KiB
Markdown
# gitlab.nvim
|
|
|
|
This Neovim plugin is designed to make it easy to review Gitlab MRs from within the editor. This means you can do things like:
|
|
|
|
- Create, edit, and delete comments on an MR
|
|
- Reply to exisiting comments
|
|
- Read MR summaries
|
|
- Approve an MR
|
|
- Revoke approval for an MR
|
|
|
|
https://user-images.githubusercontent.com/32515581/233739969-216dad6e-fa77-417f-9d2d-5e875ab2fb40.mp4
|
|
|
|
## Requirements
|
|
|
|
- Go
|
|
- <a href="https://github.com/MunifTanjim/nui.nvim">nui.nvim</a>
|
|
- <a href="https://github.com/rcarriga/nvim-notify">nvim-notify</a>
|
|
|
|
## Installation
|
|
|
|
You'll need to have an environment variable available in your shell that you use to authenticate with Gitlab's API. It should look like this:
|
|
|
|
```bash
|
|
export GITLAB_TOKEN="your_gitlab_token"
|
|
```
|
|
|
|
Then install the plugin. Here's what it looks like with <a href="https://github.com/folke/lazy.nvim">Lazy</a>:
|
|
|
|
```lua
|
|
return {
|
|
"harrisoncramer/gitlab.nvim",
|
|
dependencies = {
|
|
"rcarriga/nvim-notify",
|
|
"MunifTanjim/nui.nvim"
|
|
},
|
|
config = function()
|
|
local gitlab = require("gitlab")
|
|
gitlab.setup({ project_id = 3 }) -- This can be found under the project details section of your Gitlab repository.
|
|
end,
|
|
}
|
|
```
|
|
|
|
By default, the tool will look for and interact with MRs against a "main" branch. You can configure this by passing in the `base_branch` option:
|
|
|
|
```lua
|
|
require('gitlab').setup({ project_id = 3, base_branch = 'master' })
|
|
```
|
|
|
|
The first time you call the setup function the Go binary will be built.
|
|
|
|
## Usage
|
|
|
|
First, check out the branch that you want to review locally.
|
|
|
|
The `summary` command will pull down the MR description into a buffer so that you can read it:
|
|
|
|
```lua
|
|
require("gitlab").summary()
|
|
```
|
|
|
|
The `approve` command will approve the merge request for the current branch:
|
|
|
|
```lua
|
|
require("gitlab").approve()
|
|
```
|
|
|
|
The `revoke` command will revoke approval for the merge request for the current branch:
|
|
|
|
```lua
|
|
require("gitlab").revoke()
|
|
```
|
|
|
|
The `comment` command will open up a NUI popover that will allow you to create a Gitlab comment on the current line. To send the comment, use `<leader>s` while the comment popup is open:
|
|
|
|
```lua
|
|
require("gitlab").comment()
|
|
```
|
|
|
|
### Discussions
|
|
|
|
Gitlab groups threads of notes together into "disucssions." To get a list of all the discussions for the current MR, use the `list_discussions` command. This command will open up a split view of all the comments on the current merge request. You can jump to the comment location by using the `o` key in the tree buffer, and you can reply to a thread by using the `r` keybinding in the tree buffer:
|
|
|
|
```lua
|
|
require("gitlab").list_discussions()
|
|
```
|
|
|
|
Within the discussion tree, there are several functions that you can call, however, it's better to use the keybindings provided in the setup function. If you want to call them manually, they are:
|
|
|
|
```lua
|
|
require("gitlab").delete_comment()
|
|
require("gitlab").edit_comment()
|
|
require("gitlab").reply()
|
|
```
|
|
|
|
## Keybindings
|
|
|
|
This plugin does not create any keybindings outside of the plugin-specific buffers by default. These are the default keybindings in those plugin buffers:
|
|
|
|
```lua
|
|
{
|
|
popup = { -- The popup for comment creation, editing, and replying
|
|
exit = "<Esc>",
|
|
perform_action = "<leader>s", -- Once in normal mode, does action
|
|
},
|
|
discussion_tree = { -- The discussion tree that holds all comments
|
|
jump_to_location = "o",
|
|
edit_comment = "e",
|
|
delete_comment = "dd",
|
|
reply_to_comment = "r",
|
|
toggle_node = "t",
|
|
},
|
|
dialogue = { -- The confirmation dialogue for deleting comments
|
|
focus_next = { "j", "<Down>", "<Tab>" },
|
|
focus_prev = { "k", "<Up>", "<S-Tab>" },
|
|
close = { "<Esc>", "<C-c>" },
|
|
submit = { "<CR>", "<Space>" },
|
|
}
|
|
}
|
|
```
|
|
|
|
To override the defaults, pass a keymaps table into the setup function with any keybindings you'd like to change:
|
|
|
|
```lua
|
|
local gitlab = require("gitlab")
|
|
gitlab.setup({
|
|
project_id = 36091024,
|
|
keymaps = {
|
|
popup = {
|
|
exit = "q"
|
|
},
|
|
discussion_tree = {
|
|
reply_to_comment = "<leader>r"
|
|
}
|
|
}
|
|
})
|
|
```
|
|
|
|
The plugin does not set up any keybindings outside of these buffers, you need to set them up yourself. Here's what I'm using:
|
|
|
|
```lua
|
|
local gitlab = require("gitlab")
|
|
vim.keymap.set("n", "<leader>gls", gitlab.summary)
|
|
vim.keymap.set("n", "<leader>glA", gitlab.approve)
|
|
vim.keymap.set("n", "<leader>glR", gitlab.revoke)
|
|
vim.keymap.set("n", "<leader>glc", gitlab.create_comment)
|
|
vim.keymap.set("n", "<leader>gld", gitlab.list_discussions)
|
|
```
|
|
|
|
## Diff Views
|
|
|
|
This plugin does not provide you with a diff view out of the box for viewing changes. That is already handled by other plugins. I highly recommend using Diffview to see which files have changed in an MR. This is the function that I'm using to accomplish this:
|
|
|
|
```lua
|
|
-- Review changes against develop (will break if no develop branch present)
|
|
vim.keymap.set("n", "<leader>gR", function()
|
|
local isDiff = vim.fn.getwinvar(nil, "&diff")
|
|
local bufName = vim.api.nvim_buf_get_name(0)
|
|
if isDiff ~= 0 or u.string_starts(bufName, "diff") then
|
|
vim.cmd.tabclose()
|
|
vim.cmd.tabprev()
|
|
else
|
|
vim.cmd.DiffviewOpen("main")
|
|
end
|
|
end)
|
|
```
|
|
|
|
Which looks like this in my editor:
|
|
|
|
<img width="1727" alt="Screenshot 2023-04-21 at 6 37 39 PM" src="https://user-images.githubusercontent.com/32515581/233744560-0d718c92-f810-4fde-b40d-8b6f42eb6f0e.png">
|
|
|
|
This is useful if you plan to leave comments on the diff, because this plugin currently only supports leaving comments on lines that have been added or modified. I'm currenly working on adding functionality to allow users to leave comments on any lines, including those that have been deleted or untouched.
|