Modified project_id logic to require .gitlab.nvim file

This commit is contained in:
Harrison Cramer
2023-05-19 18:20:16 -07:00
parent ca7c702fd0
commit 27ec4668c1
4 changed files with 13 additions and 20 deletions

View File

@@ -41,7 +41,7 @@ return {
config = function() config = function()
vim.opt.termguicolors = true -- This is required if you aren't already initializing notify 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("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. require("gitlab").setup()
end, end,
} }
``` ```
@@ -58,9 +58,9 @@ use {
}, },
run = function() require("gitlab").build() end, run = function() require("gitlab").build() end,
config = function() config = function()
vim.opt.termguicolors = true -- This is required if you aren't already initializing notify vim.opt.termguicolors = true
require("notify").setup({ background_colour = "#000000" }) -- This is required if you aren't already initializing notify require("notify").setup({ background_colour = "#000000" })
require("gitlab").setup({ project_id = 3 }) -- This can be found under the project details section of your Gitlab repository. require("gitlab").setup() -- This can be found under the project details section of your Gitlab repository.
end, end,
} }
``` ```
@@ -70,21 +70,15 @@ use {
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: 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 ```lua
require('gitlab').setup({ project_id = 3, base_branch = 'master' }) require('gitlab').setup({ base_branch = 'master' })
``` ```
By default, the plugin will read the `project_id` provided in the setup call. However, if you add a `.gitlab.nvim` file to the root of your directory, the plugin will read that and use it as the project_id instead. The file should only contain the ID of the project: By default, the plugin will not connect to a gitlab repository. You must add a `.gitlab.nvim` file to the root of your directory. The plugin will read that file and use it as the project ID. The file should only contain the ID of the project:
``` ```
112415 112415
``` ```
Which is effectively like calling the setup function like this:
```lua
require('gitlab').setup({ project_id = 112415, base_branch = 'master' })
```
If you are using `main` as your branch and you add a `.gitlab.nvim` configuration file, you can call an empty setup function and the plugin will work: If you are using `main` as your branch and you add a `.gitlab.nvim` configuration file, you can call an empty setup function and the plugin will work:
```lua ```lua
@@ -93,9 +87,7 @@ require('gitlab').setup()
## Usage ## Usage
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. 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 file 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:
```lua ```lua
require("gitlab").summary() require("gitlab").summary()
@@ -166,7 +158,6 @@ To override the defaults, pass a keymaps table into the setup function with any
```lua ```lua
local gitlab = require("gitlab") local gitlab = require("gitlab")
gitlab.setup({ gitlab.setup({
project_id = 36091024,
keymaps = { keymaps = {
popup = { popup = {
exit = "q" exit = "q"

View File

@@ -39,7 +39,7 @@ M.list_discussions = function()
if u.base_invalid() then return end if u.base_invalid() then return end
Job:new({ Job:new({
command = "curl", command = "curl",
args = { "-s", "localhost:8081/" .. "discussions" }, args = { "-s", string.format("localhost:%s/discussions", state.PORT) },
on_stdout = function(_, output) on_stdout = function(_, output)
local data_ok, data = pcall(vim.json.decode, output) local data_ok, data = pcall(vim.json.decode, output)
if data_ok and data ~= nil then if data_ok and data ~= nil then

View File

@@ -60,13 +60,14 @@ M.setup = function(args, build_only)
if build_only then return end if build_only then return end
-- Override project_id in setup call if configuration file is present
local config_file_path = vim.fn.getcwd() .. "/.gitlab.nvim" local config_file_path = vim.fn.getcwd() .. "/.gitlab.nvim"
local config_file_content = u.read_file(config_file_path) local config_file_content = u.read_file(config_file_path)
if config_file_content ~= nil then if config_file_content == nil then
args.project_id = config_file_content return
end end
args.project_id = config_file_content
if args.project_id == nil then if args.project_id == nil then
args.project_id = u.read_file(state.BIN_PATH .. "/.gitlab/project_id") args.project_id = u.read_file(state.BIN_PATH .. "/.gitlab/project_id")
error("No project ID provided!") error("No project ID provided!")

View File

@@ -10,3 +10,4 @@
- [x] Fix gitlab.nvim vs. gitlab namespacing issue - [x] Fix gitlab.nvim vs. gitlab namespacing issue
- [x] Allow customization of keybindings - [x] Allow customization of keybindings
- [ ] Add logging functionality for all API calls - [ ] Add logging functionality for all API calls
- [ ] Delete should refresh the tree