Skip to content

Commit 95ba45f

Browse files
committed
Feat: Fetch remote branch before publishing single draft
1 parent c4ef505 commit 95ba45f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lua/gitlab/actions/draft_notes/init.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ end
108108
---and re-render it.
109109
---@param tree NuiTree
110110
M.confirm_publish_draft = function(tree)
111+
if not git.check_current_branch_up_to_date_on_remote(vim.log.levels.ERROR) then
112+
return
113+
end
111114
local current_node = tree:get_node()
112115
local note_node = common.get_note_node(tree, current_node)
113116
local root_node = common.get_root_node(tree, current_node)
@@ -120,12 +123,16 @@ M.confirm_publish_draft = function(tree)
120123
---@type integer
121124
local note_id = note_node.is_root and root_node.id or note_node.id
122125
local body = { note = note_id }
126+
local unlinked = tree.bufnr == require("gitlab.actions.discussions").unlinked_bufnr
123127
job.run_job("/mr/draft_notes/publish", "POST", body, function(data)
124128
u.notify(data.message, vim.log.levels.INFO)
125-
126-
local discussions = require("gitlab.actions.discussions")
127-
local unlinked = tree.bufnr == discussions.unlinked_bufnr
128129
M.rebuild_view(unlinked)
130+
end, function()
131+
M.rebuild_view(unlinked)
132+
u.notify(
133+
"Draft may have been published despite the error. Check the discussion tree.",
134+
vim.log.levels.WARN
135+
)
129136
end)
130137
end
131138

0 commit comments

Comments
 (0)