Feat: Customize Config Path (#117)
Provide the option to configure the location of the `.gitlab.nvim` file
This commit is contained in:
committed by
GitHub
parent
b8c386ac6b
commit
1abc33d149
1
.github/workflows/tag-and-release.yaml
vendored
1
.github/workflows/tag-and-release.yaml
vendored
@@ -39,3 +39,4 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
tag: ${{ needs.tag.outputs.tag }}
|
tag: ${{ needs.tag.outputs.tag }}
|
||||||
|
body: ${{ github.event.head_commit.message }}
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -87,19 +87,22 @@ use {
|
|||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
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.
|
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:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export GITLAB_TOKEN="your_gitlab_token"
|
||||||
|
export GITLAB_URL="https://my-personal-gitlab-instance.com/"
|
||||||
|
```
|
||||||
|
|
||||||
|
And as a `.gitlab.nvim` file:
|
||||||
|
|
||||||
```
|
```
|
||||||
auth_token=your_gitlab_token
|
auth_token=your_gitlab_token
|
||||||
gitlab_url=https://my-personal-gitlab-instance.com/
|
gitlab_url=https://my-personal-gitlab-instance.com/
|
||||||
```
|
```
|
||||||
|
|
||||||
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:
|
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.
|
||||||
|
|
||||||
```bash
|
|
||||||
export GITLAB_TOKEN="your_gitlab_token"
|
|
||||||
export GITLAB_URL="https://my-personal-gitlab-instance.com/"
|
|
||||||
```
|
|
||||||
|
|
||||||
## Configuring the Plugin
|
## Configuring the Plugin
|
||||||
|
|
||||||
@@ -109,6 +112,7 @@ Here is the default setup function. All of these values are optional, and if you
|
|||||||
require("gitlab").setup({
|
require("gitlab").setup({
|
||||||
port = nil, -- The port of the Go server, which runs in the background, if omitted or `nil` the port will be chosen automatically
|
port = nil, -- The port of the Go server, which runs in the background, if omitted or `nil` the port will be chosen automatically
|
||||||
log_path = vim.fn.stdpath("cache") .. "/gitlab.nvim.log", -- Log path for the Go server
|
log_path = vim.fn.stdpath("cache") .. "/gitlab.nvim.log", -- Log path for the Go server
|
||||||
|
config_path = nil, -- Custom path for `.gitlab.nvim` file, please read the "Connecting to Gitlab" section
|
||||||
debug = { go_request = false, go_response = false }, -- Which values to log
|
debug = { go_request = false, go_response = false }, -- Which values to log
|
||||||
attachment_dir = nil, -- The local directory for files (see the "summary" section)
|
attachment_dir = nil, -- The local directory for files (see the "summary" section)
|
||||||
popup = { -- The popup for comment creation, editing, and replying
|
popup = { -- The popup for comment creation, editing, and replying
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ M.settings = {
|
|||||||
port = nil, -- choose random port
|
port = nil, -- choose random port
|
||||||
debug = { go_request = false, go_response = false },
|
debug = { go_request = false, go_response = false },
|
||||||
log_path = (vim.fn.stdpath("cache") .. "/gitlab.nvim.log"),
|
log_path = (vim.fn.stdpath("cache") .. "/gitlab.nvim.log"),
|
||||||
|
config_path = nil,
|
||||||
reviewer = "diffview",
|
reviewer = "diffview",
|
||||||
attachment_dir = "",
|
attachment_dir = "",
|
||||||
popup = {
|
popup = {
|
||||||
@@ -133,14 +134,18 @@ M.setPluginConfiguration = function()
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local base_path = vim.fn.trim(vim.fn.system({ "git", "rev-parse", "--show-toplevel" }))
|
local base_path
|
||||||
|
if M.settings.config_path ~= nil then
|
||||||
|
base_path = M.settings.config_path
|
||||||
|
else
|
||||||
|
base_path = vim.fn.trim(vim.fn.system({ "git", "rev-parse", "--show-toplevel" }))
|
||||||
if vim.v.shell_error ~= 0 then
|
if vim.v.shell_error ~= 0 then
|
||||||
u.notify(string.format("Could not get base directory: %s", base_path), vim.log.levels.ERROR)
|
u.notify(string.format("Could not get base directory: %s", base_path), vim.log.levels.ERROR)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local config_file_path = base_path .. M.settings.file_separator .. ".gitlab.nvim"
|
local config_file_path = base_path .. M.settings.file_separator .. ".gitlab.nvim"
|
||||||
|
|
||||||
local config_file_content = u.read_file(config_file_path)
|
local config_file_content = u.read_file(config_file_path)
|
||||||
|
|
||||||
local file_properties = {}
|
local file_properties = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user