Skip to content

Commit e29909c

Browse files
harrisoncramerjakubbortlikduckbrain
authored
Bugfixes, Etc. (#502)
* Fix: Jumping to renamed files (#484) * fix: prevent "cursor position outside buffer" error * fix: swap file_name and old_file_name in reviewer data `old_file_name` is not set to the empty string for un-renamed files anymore, because then we can remove the empty-line check in `comment_helpers.go` which was used to replace the empty string with the current file name anyway. * fix: add old_file_name to discussion root node data * fix: also consider old_file_name when jumping to the reviewer This fixes jumping to renamed files, however, may not work for comments that were created on renamed files with the previous version of `gitlab.nvim` as that version assigned the `file_name` and `old_file_name` incorrectly. * refactor: don't shadow variable * fix: check file_name or old_file_name based on which SHA comment belongs to * Fix: Store reviewer data before creating comment popup (#476) * Fix: Make publishing drafts more robust (#483) * Fix: Swap file_name and old_file_name in reviewer data (#485) * Feat: Enable toggling date format between relative and absolute (#491) * Fix: Add opts to help popup (#492) * Fix: Force start_line for jumping to diagnostic to be inside buffer (#494) * fix: redefine colors after reloading colorscheme (#500) * Fix: Use path instead of oldpath as fallback for unrenamed files (#496) * Fix: Use file_name when old_file_name is not set (#495) * fix(ci): fix lua tests (#501) * Proxy Support (#499) This is a #MINOR release. --------- Co-authored-by: Jakub F. Bortlík <jakub.bortlik@proton.me> Co-authored-by: Jonathan Duck <Duckbrain30@gmail.com>
1 parent a260f64 commit e29909c

File tree

15 files changed

+107
-66
lines changed

15 files changed

+107
-66
lines changed

.github/workflows/lua.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ jobs:
4545
with:
4646
neovim: true
4747
version: ${{ matrix.nvim_version }}
48-
- name: Install luajit
49-
uses: leafo/gh-actions-lua@v10
48+
- uses: leafo/gh-actions-lua@v11
5049
with:
5150
luaVersion: "luajit-openresty"
52-
- name: Install luarocks
53-
uses: leafo/gh-actions-luarocks@v4
51+
- uses: hishamhm/gh-actions-luarocks@master
52+
with:
53+
luaRocksVersion: "3.12.0"
54+
- name: build
55+
run: |
56+
luarocks install busted
5457
- name: Run tests
5558
shell: bash
5659
run: |

after/syntax/gitlab.vim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ endif
55
let expanders = '^\s*\%(' . g:gitlab_discussion_tree_expander_open . '\|' . g:gitlab_discussion_tree_expander_closed . '\)'
66
let username = '@[a-zA-Z0-9.]\+'
77

8-
" Covers times like '14 days ago', 'just now', as well as 'October 3, 2024'
8+
" Covers times like '14 days ago', 'just now', as well as 'October 3, 2024', and '02/28/2025 at 00:50'
99
let time_ago = '\d\+ \w\+ ago'
1010
let formatted_date = '\w\+ \{1,2}\d\{1,2}, \d\{4}'
11-
let date = '\%(' . time_ago . '\|' . formatted_date . '\|just now\)'
11+
let absolute_time = '\d\{2}/\d\{2}/\d\{4} at \d\{2}:\d\{2}'
12+
let date = '\%(' . time_ago . '\|' . formatted_date . '\|' . absolute_time . '\|just now\)'
1213

1314
let published = date . ' \%(' . g:gitlab_discussion_tree_resolved . '\|' . g:gitlab_discussion_tree_unresolved . '\|' . g:gitlab_discussion_tree_unlinked . '\)\?'
1415
let state = ' \%(' . published . '\|' . g:gitlab_discussion_tree_draft . '\)'

cmd/app/client.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"net/http"
9+
"net/url"
910

1011
"github.com/harrisoncramer/gitlab.nvim/cmd/app/git"
1112
"github.com/hashicorp/go-retryablehttp"
@@ -66,6 +67,14 @@ func NewClient() (*Client, error) {
6667
},
6768
}
6869

70+
if proxy := pluginOptions.ConnectionSettings.Proxy; proxy != "" {
71+
u, err := url.Parse(proxy)
72+
if err != nil {
73+
return nil, fmt.Errorf("parse proxy url: %w", err)
74+
}
75+
tr.Proxy = http.ProxyURL(u)
76+
}
77+
6978
retryClient := retryablehttp.NewClient()
7079
retryClient.HTTPClient.Transport = tr
7180
gitlabOptions = append(gitlabOptions, gitlab.WithHTTPClient(retryClient.HTTPClient))
@@ -99,11 +108,11 @@ func InitProjectSettings(c *Client, gitInfo git.GitData) (*ProjectInfo, error) {
99108
project, _, err := c.GetProject(gitInfo.ProjectPath(), &opt)
100109

101110
if err != nil {
102-
return nil, fmt.Errorf(fmt.Sprintf("Error getting project at %s", gitInfo.RemoteUrl), err)
111+
return nil, fmt.Errorf("error getting project at %s: %w", gitInfo.RemoteUrl, err)
103112
}
104113

105114
if project == nil {
106-
return nil, fmt.Errorf(fmt.Sprintf("Could not find project at %s", gitInfo.RemoteUrl), err)
115+
return nil, fmt.Errorf("could not find project at %s", gitInfo.RemoteUrl)
107116
}
108117

109118
projectId := fmt.Sprint(project.ID)

cmd/app/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type PluginOptions struct {
1313
} `json:"debug"`
1414
ChosenMrIID int `json:"chosen_mr_iid"`
1515
ConnectionSettings struct {
16+
Proxy string `json:"proxy"`
1617
Insecure bool `json:"insecure"`
1718
Remote string `json:"remote"`
1819
} `json:"connection_settings"`

doc/gitlab.nvim.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ you call this function with no values the defaults will be used:
161161
},
162162
},
163163
connection_settings = {
164+
proxy = "", -- Configure a proxy URL to use when connecting to GitLab. Supports URL schemes: http, https, socks5
164165
insecure = false, -- Like curl's --insecure option, ignore bad x509 certificates on connection
165166
remote = "origin", -- The default remote that your MRs target
166167
},
@@ -213,6 +214,7 @@ you call this function with no values the defaults will be used:
213214
switch_view = "c", -- Toggle between the notes and discussions views
214215
toggle_tree_type = "i", -- Toggle type of discussion tree - "simple", or "by_file_name"
215216
publish_draft = "P", -- Publish the currently focused note/comment
217+
toggle_date_format = "dt", -- Toggle between date formats: relative (e.g., "5 days ago", "just now", "October 13, 2024" for dates more than a month ago) and absolute (e.g., "03/01/2024 at 11:43")
216218
toggle_draft_mode = "D", -- Toggle between draft mode (comments posted as drafts) and live mode (comments are posted immediately)
217219
toggle_sort_method = "st", -- Toggle whether discussions are sorted by the "latest_reply", or by "original_comment", see `:h gitlab.nvim.toggle_sort_method`
218220
toggle_node = "t", -- Open or close the discussion
@@ -267,6 +269,7 @@ you call this function with no values the defaults will be used:
267269
draft = "✎", -- Symbol to show next to draft comments/notes
268270
tree_type = "simple", -- Type of discussion tree - "simple" means just list of discussions, "by_file_name" means file tree with discussions under file
269271
draft_mode = false, -- Whether comments are posted as drafts as part of a review
272+
relative_date = true, -- Whether to show relative time like "5 days ago" or absolute time like "03/01/2025 at 01:43"
270273
winbar = nil, -- Custom function to return winbar title, should return a string. Provided with WinbarTable (defined in annotations.lua)
271274
-- If using lualine, please add "gitlab" to disabled file types, otherwise you will not see the winbar.
272275
},

lua-test.sh

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,44 @@
11
#!/usr/bin/env bash
22
#
33
# Setup and run tests for lua part of gitlab.nvim.
4-
#
5-
# In order to run tests you need to have `luarocks` and `git` installed. This script will check if
6-
# environment is already setup, if not it will initialize current directory with `luarocks`,
7-
# install `busted` framework and download plugin dependencies.
8-
#
4+
# Requires `luarocks`, `git`, and `nvim` installed.
95
#
10-
set -e
116

12-
LUA_VERSION="5.1"
7+
set -euo pipefail
8+
139
PLUGINS_FOLDER="tests/plugins"
1410
PLUGINS=(
15-
"https://github.com/MunifTanjim/nui.nvim"
16-
"https://github.com/nvim-lua/plenary.nvim"
17-
"https://github.com/sindrets/diffview.nvim"
11+
"https://github.com/MunifTanjim/nui.nvim"
12+
"https://github.com/nvim-lua/plenary.nvim"
13+
"https://github.com/sindrets/diffview.nvim"
1814
)
1915

20-
if ! command -v luarocks > /dev/null 2>&1; then
21-
echo "You need to have luarocks installed in order to run tests."
22-
exit 1
23-
fi
24-
25-
if ! command -v git > /dev/null 2>&1; then
26-
echo "You need to have git installed in order to run tests."
27-
exit 1
16+
if ! command -v luarocks >/dev/null 2>&1; then
17+
echo "Error: luarocks not found. Please install LuaRocks." >&2
18+
exit 1
2819
fi
2920

30-
if ! luarocks --lua-version=$LUA_VERSION which busted > /dev/null 2>&1; then
31-
echo "Installing busted."
32-
luarocks init
33-
luarocks config --scope project lua_version "$LUA_VERSION"
34-
luarocks install --lua-version="$LUA_VERSION" busted
21+
if ! command -v git >/dev/null 2>&1; then
22+
echo "Error: git not found. Please install Git." >&2
23+
exit 1
3524
fi
3625

37-
for arg in "$@"; do
38-
if [[ $arg =~ "--coverage" ]] && ! luarocks --lua-version=$LUA_VERSION which luacov > /dev/null 2>&1; then
39-
luarocks install --lua-version="$LUA_VERSION" luacov
40-
# lcov reporter for luacov - lcov format is supported by `nvim-coverage`
41-
luarocks install --lua-version="$LUA_VERSION" luacov-reporter-lcov
26+
if ! command -v nvim >/dev/null 2>&1; then
27+
echo "Error: nvim not found. Please install Neovim." >&2
28+
exit 1
4229
fi
43-
done
4430

31+
# Clone test plugin dependencies
32+
mkdir -p "$PLUGINS_FOLDER"
4533
for plugin in "${PLUGINS[@]}"; do
46-
plugin_name=${plugin##*/}
47-
plugin_folder="$PLUGINS_FOLDER/$plugin_name"
48-
49-
# Check if plugin was already downloaded
50-
if [[ -d "$plugin_folder/.git" ]]; then
51-
# We could also try to pull here but I am not sure if that wouldn't slow down tests too much.
52-
continue
53-
fi
54-
34+
plugin_name="${plugin##*/}"
35+
plugin_folder="$PLUGINS_FOLDER/$plugin_name"
36+
if [[ ! -d "$plugin_folder/.git" ]]; then
37+
echo "Cloning $plugin..."
5538
git clone --depth 1 "$plugin" "$plugin_folder"
56-
39+
fi
5740
done
5841

59-
nvim -u NONE -U NONE -N -i NONE -l tests/init.lua "$@"
42+
# Run tests
43+
echo "Running tests with Neovim..."
44+
nvim -u NONE -U NONE -N -i NONE -l tests/init.lua "$@"

lua/gitlab/actions/common.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ M.build_note_header = function(note)
1515
if note.note then
1616
return "@" .. state.USER.username .. " " .. state.settings.discussion_tree.draft
1717
end
18-
return "@" .. note.author.username .. " " .. u.time_since(note.created_at)
18+
local time = state.settings.discussion_tree.relative_date and u.time_since(note.created_at)
19+
or u.format_to_local(note.created_at, vim.fn.strftime("%z"))
20+
return "@" .. note.author.username .. " " .. time
1921
end
2022

2123
M.switch_can_edit_bufs = function(bool, ...)
@@ -240,7 +242,9 @@ M.get_line_numbers_for_range = function(old_line, new_line, start_line_code, end
240242
return (old_line - range), old_line, false
241243
elseif new_line ~= nil then
242244
local range = new_end_line - new_start_line
243-
return (new_line - range), new_line, true
245+
-- Force start_line to be greater than 0
246+
local start_line = (new_line - range > 0) and (new_line - range) or 1
247+
return start_line, new_line, true
244248
else
245249
u.notify("Error getting new or old line for range", vim.log.levels.ERROR)
246250
return 1, 1, false

lua/gitlab/actions/discussions/init.lua

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,16 @@ M.set_tree_keymaps = function(tree, bufnr, unlinked)
649649
})
650650
end
651651

652+
if keymaps.discussion_tree.toggle_date_format then
653+
vim.keymap.set("n", keymaps.discussion_tree.toggle_date_format, function()
654+
M.toggle_date_format()
655+
end, {
656+
buffer = bufnr,
657+
desc = "Toggle date format",
658+
nowait = keymaps.discussion_tree.toggle_date_format_nowait,
659+
})
660+
end
661+
652662
if keymaps.discussion_tree.toggle_resolved then
653663
vim.keymap.set("n", keymaps.discussion_tree.toggle_resolved, function()
654664
if M.is_current_node_note(tree) and not M.is_draft_note(tree) then
@@ -725,7 +735,7 @@ M.set_tree_keymaps = function(tree, bufnr, unlinked)
725735

726736
if keymaps.help then
727737
vim.keymap.set("n", keymaps.help, function()
728-
help.open()
738+
help.open({ discussion_tree = true })
729739
end, { buffer = bufnr, desc = "Open help popup", nowait = keymaps.help_nowait })
730740
end
731741

@@ -809,6 +819,13 @@ M.toggle_sort_method = function()
809819
M.rebuild_view(false, true)
810820
end
811821

822+
---Toggle between displaying relative time (e.g., "5 days ago") and absolute time (e.g., "04/10/2025 at 22:49")
823+
M.toggle_date_format = function()
824+
state.settings.discussion_tree.relative_date = not state.settings.discussion_tree.relative_date
825+
M.rebuild_unlinked_discussion_tree()
826+
M.rebuild_discussion_tree()
827+
end
828+
812829
---Indicates whether the node under the cursor is a draft note or not
813830
---@param tree NuiTree
814831
---@return boolean

lua/gitlab/actions/draft_notes/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ M.build_root_draft_note = function(note)
155155
id = note.id,
156156
root_note_id = note.id,
157157
file_name = (type(note.position) == "table" and note.position.new_path or nil),
158+
old_file_name = (type(note.position) == "table" and note.position.old_path or nil),
158159
new_line = (type(note.position) == "table" and note.position.new_line or nil),
159160
old_line = (type(note.position) == "table" and note.position.old_line or nil),
160161
resolvable = false,

lua/gitlab/actions/help.lua

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ local state = require("gitlab.state")
66
local List = require("gitlab.utils.list")
77
local Popup = require("nui.popup")
88

9-
M.open = function()
9+
---@class HelpPopupOpts
10+
---@field discussion_tree boolean|nil Whether help popup is for the discussion tree
11+
12+
--- @param opts HelpPopupOpts|nil Table with options for the help popup
13+
M.open = function(opts)
14+
local help_opts = opts or {}
1015
local bufnr = vim.api.nvim_get_current_buf()
1116
local keymaps = vim.api.nvim_buf_get_keymap(bufnr, "n")
1217
local help_content_lines = List.new(keymaps):reduce(function(agg, keymap)
@@ -17,26 +22,28 @@ M.open = function()
1722
return agg
1823
end, {})
1924

20-
table.insert(help_content_lines, "")
21-
table.insert(
22-
help_content_lines,
23-
string.format(
24-
"%s = draft; %s = unlinked comment; %s = resolved",
25-
state.settings.discussion_tree.draft,
26-
state.settings.discussion_tree.unlinked,
27-
state.settings.discussion_tree.resolved
25+
if help_opts.discussion_tree then
26+
table.insert(help_content_lines, "")
27+
table.insert(
28+
help_content_lines,
29+
string.format(
30+
"%s = draft; %s = unlinked comment; %s = resolved",
31+
state.settings.discussion_tree.draft,
32+
state.settings.discussion_tree.unlinked,
33+
state.settings.discussion_tree.resolved
34+
)
2835
)
29-
)
36+
end
3037

3138
local longest_line = u.get_longest_string(help_content_lines)
32-
local opts = { "Help", state.settings.popup.help, longest_line + 3, #help_content_lines, 70 }
33-
local help_popup = Popup(popup.create_popup_state(unpack(opts)))
39+
local popup_opts = { "Help", state.settings.popup.help, longest_line + 3, #help_content_lines, 70 }
40+
local help_popup = Popup(popup.create_popup_state(unpack(popup_opts)))
3441

3542
help_popup:on(event.BufLeave, function()
3643
help_popup:unmount()
3744
end)
3845

39-
popup.set_up_autocommands(help_popup, nil, vim.api.nvim_get_current_win(), opts)
46+
popup.set_up_autocommands(help_popup, nil, vim.api.nvim_get_current_win(), popup_opts)
4047

4148
help_popup:mount()
4249

0 commit comments

Comments
 (0)