Skip to content

Commit

Permalink
fix: Allow reply on Gitlab buffer (#375)
Browse files Browse the repository at this point in the history
Fixes issue where we were blocking reply creation due to a recent update

This is a #PATCH release
  • Loading branch information
harrisoncramer authored Sep 15, 2024
1 parent dba1512 commit c3d7f26
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
11 changes: 4 additions & 7 deletions cmd/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,14 @@ func CreateRouter(gitlabClient *Client, projectInfo *ProjectInfo, s *shutdownSer
withMethodCheck(http.MethodPost),
))

m.Handle("/ping", http.HandlerFunc(pingHandler))
m.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, "pong")
})

return LoggingServer{handler: m}
}

/* Used to check whether the server has started yet */
func pingHandler(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, "pong")
}

/* checkServer pings the server repeatedly for 1 full second after startup in order to notify the plugin that the server is ready */
func checkServer(port int) error {
for i := 0; i < 10; i++ {
Expand Down
5 changes: 3 additions & 2 deletions lua/gitlab/actions/comment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ end
---@field ranged boolean
---@field unlinked boolean
---@field discussion_id string|nil
---@field reply boolean|nil

---This function sets up the layout and popups needed to create a comment, note and
---multi-line comment. It also sets up the basic keybindings for switching between
Expand All @@ -172,7 +173,7 @@ M.create_comment_layout = function(opts)

-- Check that Diffview is the current view
local view = diffview_lib.get_current_view()
if view == nil then
if view == nil and not opts.reply then
u.notify("Comments should be left in the reviewer pane", vim.log.levels.ERROR)
return
end
Expand All @@ -186,7 +187,7 @@ M.create_comment_layout = function(opts)

-- Check that we are hovering over the code
local filetype = vim.bo[0].filetype
if filetype == "DiffviewFiles" or filetype == "gitlab" then
if not opts.reply and (filetype == "DiffviewFiles" or filetype == "gitlab") then
u.notify(
"Comments can only be left on the code. To leave unlinked comments, use gitlab.create_note() instead",
vim.log.levels.ERROR
Expand Down
12 changes: 10 additions & 2 deletions lua/gitlab/actions/discussions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,16 @@ M.reply = function(tree)
local discussion_id = tostring(discussion_node.id)
local comment = require("gitlab.actions.comment")
local unlinked = tree.bufnr == M.unlinked_bufnr
local layout = comment.create_comment_layout({ ranged = false, discussion_id = discussion_id, unlinked = unlinked })
layout:mount()
local layout = comment.create_comment_layout({
ranged = false,
discussion_id = discussion_id,
unlinked = unlinked,
reply = true,
})

if layout then
layout:mount()
end
end

-- This function (settings.keymaps.discussion_tree.delete_comment) will trigger a popup prompting you to delete the current comment
Expand Down

0 comments on commit c3d7f26

Please sign in to comment.