Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4ff27c2
fix: Fixes issues w/ shared pointers to structs (#378)
harrisoncramer Sep 16, 2024
87e224a
feat: adds even better debugging and linting support (#376)
harrisoncramer Sep 16, 2024
e17d713
fix: error messages and run all tests (#381)
gkze Sep 21, 2024
523bdd4
feat: Automatically open fold under cursor (#380)
jakubbortlik Sep 23, 2024
6ac8895
Merge branch 'main' into develop
harrisoncramer Sep 24, 2024
879ee20
fix: discussion ID is not required (#383)
harrisoncramer Sep 26, 2024
125cfbb
Chore: Add more emojis (#384)
jakubbortlik Oct 4, 2024
7171f4c
Fix: Publish all drafts (#391)
jakubbortlik Oct 10, 2024
0e19857
fix: make discussion tree buffers nomodifiable (#394)
jakubbortlik Oct 11, 2024
96efdc2
fix: Incorrect warning about commits (#395)
harrisoncramer Oct 12, 2024
b359b47
Fix: Show draft replies in the correct tree (#396)
jakubbortlik Oct 13, 2024
a63823c
fix: Cannot choose merge requests (#398)
harrisoncramer Oct 13, 2024
0f3841f
fix: parse dates without timezone offset (#404)
harrisoncramer Oct 14, 2024
04976db
Fix: Use correct name for emoji
jakubbortlik Oct 15, 2024
cd8a404
Merge pull request #405 from jakubbortlik/fix-party-emoji
jakubbortlik Oct 18, 2024
c8c0395
fix: enable replying if tree is in a different tab (#407)
jakubbortlik Oct 25, 2024
e4c9dbe
fix: wrong get url (#413)
OscarCreator Nov 5, 2024
5f657fd
Fix: Restore cursor when updating from outside of tree (#406)
jakubbortlik Nov 5, 2024
a03b2f6
Merge branch 'main' into develop
harrisoncramer Nov 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cmd/app/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Extracts information about the current repository and returns
it to the client for initialization. The current directory must be a valid
Gitlab project and the branch must be a feature branch
*/
func NewGitData(remote string, g GitManager) (GitData, error) {
func NewGitData(remote string, gitlabUrl string, g GitManager) (GitData, error) {
err := g.RefreshProjectInfo(remote)
if err != nil {
return GitData{}, fmt.Errorf("could not get latest information from remote: %v", err)
Expand Down Expand Up @@ -65,7 +65,14 @@ func NewGitData(remote string, g GitManager) (GitData, error) {
return GitData{}, fmt.Errorf("invalid git URL format: %s", url)
}

namespace := matches[1]
// remove part of the hostname from the parsed namespace
url_re := regexp.MustCompile(`[^\/]\/([^\/].*)$`)
url_matches := url_re.FindStringSubmatch(gitlabUrl)
var namespace string = matches[1]
if len(url_matches) == 2 {
namespace = strings.TrimLeft(strings.TrimPrefix(namespace, url_matches[1]), "/")
}

projectName := matches[2]

branchName, err := g.GetCurrentBranchNameFromNativeGitCmd()
Expand Down
47 changes: 44 additions & 3 deletions cmd/app/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (f FakeGitManager) GetProjectUrlFromNativeGitCmd(string) (url string, err e

type TestCase struct {
desc string
url string
branch string
projectName string
namespace string
Expand All @@ -40,116 +41,156 @@ func TestExtractGitInfo_Success(t *testing.T) {
testCases := []TestCase{
{
desc: "Project configured in SSH under a single folder",
url: "git@custom-gitlab.com",
remote: "git@custom-gitlab.com:namespace-1/project-name.git",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1",
},
{
desc: "Project configured in SSH under a single folder without .git extension",
url: "git@custom-gitlab.com",
remote: "git@custom-gitlab.com:namespace-1/project-name",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1",
},
{
desc: "Project configured in SSH under one nested folder",
url: "git@custom-gitlab.com",
remote: "git@custom-gitlab.com:namespace-1/namespace-2/project-name.git",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1/namespace-2",
},
{
desc: "Project configured in SSH under two nested folders",
url: "git@custom-gitlab.com",
remote: "git@custom-gitlab.com:namespace-1/namespace-2/namespace-3/project-name.git",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1/namespace-2/namespace-3",
},
{
desc: "Project configured in SSH:// under a single folder",
url: "ssh://custom-gitlab.com",
remote: "ssh://custom-gitlab.com/namespace-1/project-name.git",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1",
},
{
desc: "Project configured in SSH:// under a single folder without .git extension",
url: "ssh://custom-gitlab.com",
remote: "ssh://custom-gitlab.com/namespace-1/project-name",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1",
},
{
desc: "Project configured in SSH:// under two nested folders",
url: "ssh://custom-gitlab.com",
remote: "ssh://custom-gitlab.com/namespace-1/namespace-2/namespace-3/project-name.git",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1/namespace-2/namespace-3",
},
{
desc: "Project configured in SSH:// and have a custom port",
url: "ssh://custom-gitlab.com",
remote: "ssh://custom-gitlab.com:2222/namespace-1/project-name",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1",
},
{
desc: "Project configured in SSH:// and have a custom port (with gitlab url namespace)",
url: "ssh://custom-gitlab.com/a",
remote: "ssh://custom-gitlab.com:2222/a/namespace-1/project-name",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1",
},
{
desc: "Project configured in HTTP and under a single folder without .git extension",
url: "http://custom-gitlab.com",
remote: "http://custom-gitlab.com/namespace-1/project-name",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1",
},
{
desc: "Project configured in HTTP and under a single folder without .git extension (with embedded credentials)",
url: "http://custom-gitlab.com",
remote: "http://username:password@custom-gitlab.com/namespace-1/project-name",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1",
},
{
desc: "Project configured in HTTPS and under a single folder",
url: "https://custom-gitlab.com",
remote: "https://custom-gitlab.com/namespace-1/project-name.git",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1",
},
{
desc: "Project configured in HTTPS and under a single folder (with embedded credentials)",
url: "https://custom-gitlab.com",
remote: "https://username:password@custom-gitlab.com/namespace-1/project-name.git",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1",
},
{
desc: "Project configured in HTTPS and under a nested folder",
url: "https://custom-gitlab.com",
remote: "https://custom-gitlab.com/namespace-1/namespace-2/project-name.git",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1/namespace-2",
},
{
desc: "Project configured in HTTPS and under a nested folder (with embedded credentials)",
url: "https://custom-gitlab.com",
remote: "https://username:password@custom-gitlab.com/namespace-1/namespace-2/project-name.git",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1/namespace-2",
},
{
desc: "Project configured in HTTPS and under two nested folders",
url: "https://custom-gitlab.com",
remote: "https://custom-gitlab.com/namespace-1/namespace-2/namespace-3/project-name.git",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1/namespace-2/namespace-3",
},
{
desc: "Project configured in HTTPS and under two nested folders (with embedded credentials)",
url: "https://custom-gitlab.com",
remote: "https://username:password@custom-gitlab.com/namespace-1/namespace-2/namespace-3/project-name.git",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-1/namespace-2/namespace-3",
},
{
desc: "Project configured in HTTPS and under one nested folders (with gitlab url namespace)",
url: "https://custom-gitlab.com/gitlab",
remote: "https://username:password@custom-gitlab.com/gitlab/namespace-2/namespace-3/project-name.git",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-2/namespace-3",
},
{
desc: "Project configured in HTTPS and under one nested folders (with gitlab url namespace + extra slash)",
url: "https://custom-gitlab.com/gitlab/",
remote: "https://username:password@custom-gitlab.com/gitlab/namespace-2/namespace-3/project-name.git",
branch: "feature/abc",
projectName: "project-name",
namespace: "namespace-2/namespace-3",
},
}
for _, tC := range testCases {
t.Run(tC.desc, func(t *testing.T) {
Expand All @@ -159,7 +200,7 @@ func TestExtractGitInfo_Success(t *testing.T) {
BranchName: tC.branch,
RemoteUrl: tC.remote,
}
data, err := NewGitData(tC.remote, g)
data, err := NewGitData(tC.remote, tC.url, g)
if err != nil {
t.Errorf("No error was expected, got %s", err)
}
Expand Down Expand Up @@ -204,7 +245,7 @@ func TestExtractGitInfo_FailToGetProjectRemoteUrl(t *testing.T) {
g := failingUrlManager{
errMsg: tC.errMsg,
}
_, err := NewGitData("", g)
_, err := NewGitData("", "", g)
if err == nil {
t.Errorf("Expected an error, got none")
}
Expand Down Expand Up @@ -236,7 +277,7 @@ func TestExtractGitInfo_FailToGetCurrentBranchName(t *testing.T) {
},
errMsg: tC.errMsg,
}
_, err := NewGitData("", g)
_, err := NewGitData("", "", g)
if err == nil {
t.Errorf("Expected an error, got none")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
}

gitManager := git.Git{}
gitData, err := git.NewGitData(pluginOptions.ConnectionSettings.Remote, gitManager)
gitData, err := git.NewGitData(pluginOptions.ConnectionSettings.Remote, pluginOptions.GitlabUrl, gitManager)

if err != nil {
log.Fatalf("Failure initializing plugin: %v", err)
Expand Down
19 changes: 19 additions & 0 deletions config/emojis.json
Original file line number Diff line number Diff line change
Expand Up @@ -9661,6 +9661,25 @@
],
"moji": "😅"
},
"tada": {
"unicode": "1F389",
"unicode_alternates": [],
"name": "party popper as a 'tada' celebration",
"shortname": ":tada:",
"category": "people",
"aliases": [
":party_popper:"
],
"aliases_ascii": [],
"keywords": [
"celebrate",
"celebration",
"hooray",
"hurrah",
"hurray"
],
"moji": "🎉"
},
"thermometer_face": {
"unicode": "1F912",
"unicode_alternates": [],
Expand Down
14 changes: 3 additions & 11 deletions lua/gitlab/actions/comment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,7 @@ local confirm_create_comment = function(text, visual_range, unlinked, discussion
local body = { discussion_id = discussion_id, reply = text, draft = is_draft }
job.run_job("/mr/reply", "POST", body, function()
u.notify("Sent reply!", vim.log.levels.INFO)
if is_draft then
draft_notes.load_draft_notes(function()
discussions.rebuild_view(unlinked)
end)
else
discussions.rebuild_view(unlinked)
end
discussions.rebuild_view(unlinked)
end)
return
end
Expand All @@ -69,8 +63,6 @@ local confirm_create_comment = function(text, visual_range, unlinked, discussion
return
end

vim.print("Here: ", unlinked, discussion_id)

local reviewer_data = reviewer.get_reviewer_data()
if reviewer_data == nil then
u.notify("Error getting reviewer data", vim.log.levels.ERROR)
Expand Down Expand Up @@ -102,7 +94,7 @@ local confirm_create_comment = function(text, visual_range, unlinked, discussion
job.run_job("/mr/draft_notes/", "POST", body, function()
u.notify("Draft reply created!", vim.log.levels.INFO)
draft_notes.load_draft_notes(function()
discussions.rebuild_view(false, true)
discussions.rebuild_view(unlinked)
end)
end)
return
Expand Down Expand Up @@ -166,7 +158,7 @@ end
---@param opts LayoutOpts
---@return NuiLayout|nil
M.create_comment_layout = function(opts)
if opts.unlinked ~= true then
if opts.unlinked ~= true and opts.discussion_id == nil then
-- Check that diffview is initialized
if reviewer.tabnr == nil then
u.notify("Reviewer must be initialized first", vim.log.levels.ERROR)
Expand Down
21 changes: 19 additions & 2 deletions lua/gitlab/actions/discussions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ M.open = function(callback)
local current_window = vim.api.nvim_get_current_win() -- Save user's current window in case they switched while content was loading
vim.api.nvim_set_current_win(M.split.winid)

common.switch_can_edit_bufs(true, M.linked_bufnr, M.unliked_bufnr)
common.switch_can_edit_bufs(true, M.linked_bufnr, M.unlinked_bufnr)
M.rebuild_discussion_tree()
M.rebuild_unlinked_discussion_tree()

Expand Down Expand Up @@ -432,6 +432,9 @@ M.rebuild_discussion_tree = function()
if M.linked_bufnr == nil then
return
end

local current_node = discussions_tree.get_node_at_cursor(M.discussion_tree, M.last_node_at_cursor)

local expanded_node_ids = M.gather_expanded_node_ids(M.discussion_tree)
common.switch_can_edit_bufs(true, M.linked_bufnr, M.unlinked_bufnr)

Expand All @@ -447,12 +450,14 @@ M.rebuild_discussion_tree = function()
bufnr = M.linked_bufnr,
prepare_node = tree_utils.nui_tree_prepare_node,
})

-- Re-expand already expanded nodes
for _, id in ipairs(expanded_node_ids) do
tree_utils.open_node_by_id(discussion_tree, id)
end

discussion_tree:render()
discussions_tree.restore_cursor_position(M.split.winid, discussion_tree, current_node)

M.set_tree_keymaps(discussion_tree, M.linked_bufnr, false)
M.discussion_tree = discussion_tree
common.switch_can_edit_bufs(false, M.linked_bufnr, M.unlinked_bufnr)
Expand All @@ -466,6 +471,9 @@ M.rebuild_unlinked_discussion_tree = function()
if M.unlinked_bufnr == nil then
return
end

local current_node = discussions_tree.get_node_at_cursor(M.unlinked_discussion_tree, M.last_node_at_cursor)

local expanded_node_ids = M.gather_expanded_node_ids(M.unlinked_discussion_tree)
common.switch_can_edit_bufs(true, M.linked_bufnr, M.unlinked_bufnr)
vim.api.nvim_buf_set_lines(M.unlinked_bufnr, 0, -1, false, {})
Expand All @@ -487,6 +495,7 @@ M.rebuild_unlinked_discussion_tree = function()
tree_utils.open_node_by_id(unlinked_discussion_tree, id)
end
unlinked_discussion_tree:render()
discussions_tree.restore_cursor_position(M.split.winid, unlinked_discussion_tree, current_node)

M.set_tree_keymaps(unlinked_discussion_tree, M.unlinked_bufnr, true)
M.unlinked_discussion_tree = unlinked_discussion_tree
Expand Down Expand Up @@ -535,6 +544,14 @@ M.create_split_and_bufs = function()
buffer = linked_bufnr,
callback = function()
M.last_row, M.last_column = unpack(vim.api.nvim_win_get_cursor(0))
M.last_node_at_cursor = M.discussion_tree and M.discussion_tree:get_node() or nil
end,
})

vim.api.nvim_create_autocmd("WinLeave", {
buffer = unlinked_bufnr,
callback = function()
M.last_node_at_cursor = M.unlinked_discussion_tree and M.unlinked_discussion_tree:get_node() or nil
end,
})

Expand Down
Loading
Loading