Develop (#3)
Moves build script into separate function and sets up instructions for Packer installs.
This commit is contained in:
committed by
GitHub
parent
6154d4c9f3
commit
899e04082e
29
README.md
29
README.md
@@ -37,9 +37,30 @@ return {
|
|||||||
"MunifTanjim/nui.nvim",
|
"MunifTanjim/nui.nvim",
|
||||||
"nvim-lua/plenary.nvim"
|
"nvim-lua/plenary.nvim"
|
||||||
},
|
},
|
||||||
|
build = function () require("gitlab").build() end, -- Builds the Go binary
|
||||||
config = function()
|
config = function()
|
||||||
local gitlab = require("gitlab")
|
vim.opt.termguicolors = true -- This is required if you aren't already initializing notify
|
||||||
gitlab.setup({ project_id = 3 }) -- This can be found under the project details section of your Gitlab repository.
|
require("notify").setup({ background_colour = "#000000" }) -- This is required if you aren't already initializing notify
|
||||||
|
require("gitlab").setup({ project_id = 3 }) -- This can be found under the project details section of your Gitlab repository.
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
And with Packer:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
use {
|
||||||
|
'harrisoncramer/gitlab.nvim',
|
||||||
|
requires = {
|
||||||
|
"rcarriga/nvim-notify",
|
||||||
|
"MunifTanjim/nui.nvim",
|
||||||
|
"nvim-lua/plenary.nvim"
|
||||||
|
},
|
||||||
|
run = function() require("gitlab").build() end,
|
||||||
|
config = function()
|
||||||
|
vim.opt.termguicolors = true -- This is required if you aren't already initializing notify
|
||||||
|
require("notify").setup({ background_colour = "#000000" }) -- This is required if you aren't already initializing notify
|
||||||
|
require("gitlab").setup({ project_id = 3 }) -- This can be found under the project details section of your Gitlab repository.
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -50,11 +71,9 @@ By default, the tool will look for and interact with MRs against a "main" branch
|
|||||||
require('gitlab').setup({ project_id = 3, base_branch = 'master' })
|
require('gitlab').setup({ project_id = 3, base_branch = 'master' })
|
||||||
```
|
```
|
||||||
|
|
||||||
The first time you call the setup function the Go binary will be built.
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
First, check out the branch that you want to review locally.
|
First, check out the branch that you want to review locally. Then open Neovim and the reviewer will be initialized. The `project_id` you specify in your configuration must match the project_id of the Gitlab project your terminal is inside of.
|
||||||
|
|
||||||
The `summary` command will pull down the MR description into a buffer so that you can read it:
|
The `summary` command will pull down the MR description into a buffer so that you can read it:
|
||||||
|
|
||||||
|
|||||||
@@ -22,31 +22,50 @@ M.reply = discussions.reply
|
|||||||
|
|
||||||
-- Builds the Go binary, initializes the plugin, fetches MR info
|
-- Builds the Go binary, initializes the plugin, fetches MR info
|
||||||
local projectData = {}
|
local projectData = {}
|
||||||
local function current_file_path()
|
|
||||||
local path = debug.getinfo(1, 'S').source:sub(2)
|
M.build = function(args)
|
||||||
return vim.fn.fnamemodify(path, ':p')
|
if args == nil then args = {} end
|
||||||
|
local command = string.format("cd %s && make", state.BIN_PATH)
|
||||||
|
local installCode = os.execute(command .. "> /dev/null")
|
||||||
|
if installCode ~= 0 then
|
||||||
|
notify("Could not install gitlab.nvim!", "error")
|
||||||
|
return
|
||||||
|
else
|
||||||
|
M.setup(args, true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
M.setup = function(args)
|
M.setup = function(args, build_only)
|
||||||
local file_path = current_file_path()
|
local file_path = M.current_file_path()
|
||||||
local parent_dir = vim.fn.fnamemodify(file_path, ":h:h:h")
|
local parent_dir = vim.fn.fnamemodify(file_path, ":h:h:h")
|
||||||
|
|
||||||
state.BIN_PATH = parent_dir
|
state.BIN_PATH = parent_dir
|
||||||
state.BIN = parent_dir .. "/bin"
|
state.BIN = parent_dir .. "/bin"
|
||||||
|
|
||||||
|
if args.dev == true then
|
||||||
|
M.build(args)
|
||||||
|
end
|
||||||
|
|
||||||
local binExists = io.open(state.BIN, "r")
|
local binExists = io.open(state.BIN, "r")
|
||||||
if not binExists or args.dev == true then
|
if not binExists or args.dev == true then
|
||||||
local command = string.format("cd %s && make", state.BIN_PATH)
|
local command = string.format("cd %s && make", state.BIN_PATH)
|
||||||
local installCode = os.execute(command .. "> /dev/null")
|
local installCode = os.execute(command .. "> /dev/null")
|
||||||
if installCode ~= 0 then
|
if installCode ~= 0 then
|
||||||
notify("Could not install gitlab.nvim! Do you have Go installed?", "error")
|
require("notify")("Could not install gitlab.nvim! Do you have Go installed?", "error")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local binary_exists = vim.loop.fs_stat(state.BIN)
|
||||||
|
if binary_exists == nil then
|
||||||
|
return -- Ensure build function completes before initializing plugin
|
||||||
|
end
|
||||||
|
|
||||||
|
if build_only then return end
|
||||||
|
|
||||||
if args.project_id == nil then
|
if args.project_id == nil then
|
||||||
error("No project ID provided!")
|
error("No project ID provided!")
|
||||||
end
|
end
|
||||||
|
|
||||||
state.PROJECT_ID = args.project_id
|
state.PROJECT_ID = args.project_id
|
||||||
|
|
||||||
if args.base_branch ~= nil then
|
if args.base_branch ~= nil then
|
||||||
@@ -77,4 +96,9 @@ M.setup = function(args)
|
|||||||
keymaps.set_keymap_keys(args.keymaps)
|
keymaps.set_keymap_keys(args.keymaps)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M.current_file_path = function()
|
||||||
|
local path = debug.getinfo(1, 'S').source:sub(2)
|
||||||
|
return vim.fn.fnamemodify(path, ':p')
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user