Feat: Add and Remove Labels from an MR (#159)

This MR adds the ability to add or remove labels to a merge request. These labels are visible in the summary panel and are colored the same way as they would be in the Gitlab UI.

This is a MINOR release.
This commit is contained in:
Harrison (Harry) Cramer
2024-01-13 10:37:05 -05:00
committed by GitHub
parent 67f09e559a
commit 50e06ceff6
12 changed files with 306 additions and 3 deletions

View File

@@ -89,6 +89,8 @@ M.summary = function()
vim.api.nvim_set_option_value("readonly", false, { buf = info_popup.bufnr })
end
M.color_labels(info_popup.bufnr) -- Color labels in details popup
state.set_popup_keymaps(
description_popup,
M.edit_summary,
@@ -128,8 +130,9 @@ M.build_info_lines = function()
assignees = { title = "Assignees", content = u.make_readable_list(info.assignees, "name") },
reviewers = { title = "Reviewers", content = u.make_readable_list(info.reviewers, "name") },
branch = { title = "Branch", content = info.source_branch },
labels = { title = "Labels", content = u.make_comma_separated_readable(info.labels) },
pipeline = {
title = "Pipeline Status:",
title = "Pipeline Status",
content = function()
return pipeline.get_pipeline_status()
end,
@@ -230,8 +233,25 @@ M.create_layout = function(info_lines)
}, internal_layout)
layout:mount()
return layout, title_popup, description_popup, details_popup
end
M.color_labels = function(bufnr)
local label_namespace = vim.api.nvim_create_namespace("Labels")
for i, v in ipairs(state.settings.info.fields) do
if v == "labels" then
local line_content = u.get_line_content(bufnr, i)
vim.print(line_content)
for j, label in ipairs(state.LABELS) do
local start_idx, end_idx = line_content:find(label.Name)
if start_idx ~= nil and end_idx ~= nil then
vim.cmd("highlight " .. "label" .. j .. " guifg=white")
vim.api.nvim_set_hl(0, ("label" .. j), { fg = label.Color })
vim.api.nvim_buf_add_highlight(bufnr, label_namespace, ("label" .. j), i - 1, start_idx - 1, end_idx)
end
end
end
end
end
return M