Files
gitlab.nvim/lua/gitlab/actions/labels.lua
Harrison (Harry) Cramer 495e64c8bc Release (#440)
* Feat: Enable sorting discussions by original comment (#422)
* Feat: Improve popup UX (#426)
* Feat: Automatically update MR summary details (#427)
* Feat: Show update progress in winbar (#432)
* Feat: Abbreviate winbar (#439)
* Fix: Note Creation Bug (#441)
* Fix: Checking whether comment can be created (#434)
* Fix: Syntax in discussion tree (#433)
* fix: improve indication of resolved threads and drafts (#442)
* Docs: Various minor improvements (#445)

---------

Co-authored-by: Jakub F. Bortlík <jakub.bortlik@proton.me>
2024-12-11 14:21:50 -05:00

68 lines
1.7 KiB
Lua

-- This module is responsible for the creation, deletion,
-- and assignment and removeal of labels.
local u = require("gitlab.utils")
local job = require("gitlab.job")
local state = require("gitlab.state")
local List = require("gitlab.utils.list")
local M = {}
M.add_label = function()
M.add_popup("label")
end
M.delete_label = function()
M.delete_popup("label")
end
local refresh_label_state = function(labels, message)
u.notify(message, vim.log.levels.INFO)
state.INFO.labels = labels
require("gitlab.actions.summary").update_summary_details()
end
local get_current_labels = function()
return state.INFO.labels
end
local get_all_labels = function()
return List.new(state.LABELS):map(function(label)
return label.Name
end)
end
M.add_popup = function(type)
local all_labels = get_all_labels()
local current_labels = get_current_labels()
local unused_labels = u.difference(all_labels, current_labels)
vim.ui.select(unused_labels, {
prompt = "Choose label to add",
}, function(choice)
if not choice then
return
end
table.insert(current_labels, choice)
local body = { labels = current_labels }
job.run_job("/mr/" .. type, "PUT", body, function(data)
refresh_label_state(data.labels, data.message)
end)
end)
end
M.delete_popup = function(type)
local current_labels = get_current_labels()
vim.ui.select(current_labels, {
prompt = "Choose label to delete",
}, function(choice)
if not choice then
return
end
local filtered_labels = u.filter(current_labels, choice)
local body = { labels = filtered_labels }
job.run_job("/mr/" .. type, "PUT", body, function(data)
refresh_label_state(data.labels, data.message)
end)
end)
end
return M