From 27ec4668c1869bd9b7aee523793f0b63406eceaa Mon Sep 17 00:00:00 2001 From: Harrison Cramer Date: Fri, 19 May 2023 18:20:16 -0700 Subject: [PATCH] Modified project_id logic to require .gitlab.nvim file --- README.md | 23 +++++++---------------- lua/gitlab/discussions.lua | 2 +- lua/gitlab/init.lua | 7 ++++--- todo.md | 1 + 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 3a0f1d2..2847435 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ return { 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. + require("gitlab").setup() end, } ``` @@ -58,9 +58,9 @@ use { }, 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. + vim.opt.termguicolors = true + require("notify").setup({ background_colour = "#000000" }) + require("gitlab").setup() -- This can be found under the project details section of your Gitlab repository. 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: ```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 ``` -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: ```lua @@ -93,9 +87,7 @@ require('gitlab').setup() ## 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. - -The `summary` command will pull down the MR description into a buffer so that you can read it: +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: ```lua require("gitlab").summary() @@ -166,7 +158,6 @@ To override the defaults, pass a keymaps table into the setup function with any ```lua local gitlab = require("gitlab") gitlab.setup({ - project_id = 36091024, keymaps = { popup = { exit = "q" diff --git a/lua/gitlab/discussions.lua b/lua/gitlab/discussions.lua index 4f697b6..4e437b6 100644 --- a/lua/gitlab/discussions.lua +++ b/lua/gitlab/discussions.lua @@ -39,7 +39,7 @@ M.list_discussions = function() if u.base_invalid() then return end Job:new({ command = "curl", - args = { "-s", "localhost:8081/" .. "discussions" }, + args = { "-s", string.format("localhost:%s/discussions", state.PORT) }, on_stdout = function(_, output) local data_ok, data = pcall(vim.json.decode, output) if data_ok and data ~= nil then diff --git a/lua/gitlab/init.lua b/lua/gitlab/init.lua index f28382c..8df2233 100644 --- a/lua/gitlab/init.lua +++ b/lua/gitlab/init.lua @@ -60,13 +60,14 @@ M.setup = function(args, build_only) 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_content = u.read_file(config_file_path) - if config_file_content ~= nil then - args.project_id = config_file_content + if config_file_content == nil then + return end + args.project_id = config_file_content + if args.project_id == nil then args.project_id = u.read_file(state.BIN_PATH .. "/.gitlab/project_id") error("No project ID provided!") diff --git a/todo.md b/todo.md index d3aa26f..7043a7a 100644 --- a/todo.md +++ b/todo.md @@ -10,3 +10,4 @@ - [x] Fix gitlab.nvim vs. gitlab namespacing issue - [x] Allow customization of keybindings - [ ] Add logging functionality for all API calls +- [ ] Delete should refresh the tree