Skip to content

Commit 1abc33d

Browse files
Feat: Customize Config Path (#117)
Provide the option to configure the location of the `.gitlab.nvim` file
1 parent b8c386a commit 1abc33d

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

.github/workflows/tag-and-release.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ jobs:
3939
with:
4040
token: ${{ secrets.GITHUB_TOKEN }}
4141
tag: ${{ needs.tag.outputs.tag }}
42+
body: ${{ github.event.head_commit.message }}

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,22 @@ use {
8787

8888
This plugin requires an <a href="https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#create-a-personal-access-token">auth token</a> to connect to Gitlab. The token can be set in the root directory of the project in a `.gitlab.nvim` environment file, or can be set via a shell environment variable called `GITLAB_TOKEN` instead. If both are present, the `.gitlab.nvim` file will take precedence.
8989

90-
Optionally provide a GITLAB_URL environment variable (or gitlab_url value in the `.gitlab.nvim` file) to connect to a self-hosted Gitlab instance. This is optional, use ONLY for self-hosted instances.
90+
Optionally provide a GITLAB_URL environment variable (or gitlab_url value in the `.gitlab.nvim` file) to connect to a self-hosted Gitlab instance. This is optional, use ONLY for self-hosted instances. Here's what they'd look like as environment variables:
91+
92+
```bash
93+
export GITLAB_TOKEN="your_gitlab_token"
94+
export GITLAB_URL="https://my-personal-gitlab-instance.com/"
95+
```
96+
97+
And as a `.gitlab.nvim` file:
9198

9299
```
93100
auth_token=your_gitlab_token
94101
gitlab_url=https://my-personal-gitlab-instance.com/
95102
```
96103

97-
If you don't want to write these into a dotfile, you may provide them via shell variables. These will be overridden by the dotfile if it is present:
104+
The plugin will look for the `.gitlab.nvim` file in the root of the current project by default. However, you may provide a custom path to the configuration file via the `config_path` option. This must be an absolute path to the directory that holds your `.gitlab.nvim` file.
98105

99-
```bash
100-
export GITLAB_TOKEN="your_gitlab_token"
101-
export GITLAB_URL="https://my-personal-gitlab-instance.com/"
102-
```
103106

104107
## Configuring the Plugin
105108

@@ -109,6 +112,7 @@ Here is the default setup function. All of these values are optional, and if you
109112
require("gitlab").setup({
110113
port = nil, -- The port of the Go server, which runs in the background, if omitted or `nil` the port will be chosen automatically
111114
log_path = vim.fn.stdpath("cache") .. "/gitlab.nvim.log", -- Log path for the Go server
115+
config_path = nil, -- Custom path for `.gitlab.nvim` file, please read the "Connecting to Gitlab" section
112116
debug = { go_request = false, go_response = false }, -- Which values to log
113117
attachment_dir = nil, -- The local directory for files (see the "summary" section)
114118
popup = { -- The popup for comment creation, editing, and replying

lua/gitlab/state.lua

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ M.settings = {
1111
port = nil, -- choose random port
1212
debug = { go_request = false, go_response = false },
1313
log_path = (vim.fn.stdpath("cache") .. "/gitlab.nvim.log"),
14+
config_path = nil,
1415
reviewer = "diffview",
1516
attachment_dir = "",
1617
popup = {
@@ -133,14 +134,18 @@ M.setPluginConfiguration = function()
133134
return true
134135
end
135136

136-
local base_path = vim.fn.trim(vim.fn.system({ "git", "rev-parse", "--show-toplevel" }))
137-
if vim.v.shell_error ~= 0 then
138-
u.notify(string.format("Could not get base directory: %s", base_path), vim.log.levels.ERROR)
139-
return false
137+
local base_path
138+
if M.settings.config_path ~= nil then
139+
base_path = M.settings.config_path
140+
else
141+
base_path = vim.fn.trim(vim.fn.system({ "git", "rev-parse", "--show-toplevel" }))
142+
if vim.v.shell_error ~= 0 then
143+
u.notify(string.format("Could not get base directory: %s", base_path), vim.log.levels.ERROR)
144+
return false
145+
end
140146
end
141147

142148
local config_file_path = base_path .. M.settings.file_separator .. ".gitlab.nvim"
143-
144149
local config_file_content = u.read_file(config_file_path)
145150

146151
local file_properties = {}

0 commit comments

Comments
 (0)