From b690c12eaf509c9455ad6a57c6744cbd6e094543 Mon Sep 17 00:00:00 2001 From: Will Dean <57733339+wd60622@users.noreply.github.com> Date: Wed, 19 Feb 2025 13:28:21 +0100 Subject: [PATCH] Add `:Octo label delete` command (#867) * support label delete * add to the documentation --- README.md | 1 + doc/octo.txt | 1 + lua/octo/commands.lua | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/README.md b/README.md index cb8ca59e..79edbb1f 100644 --- a/README.md +++ b/README.md @@ -359,6 +359,7 @@ If no command is passed, the argument to `Octo` is treated as a URL from where a | label | add [label] | Add a label from available label menu | | | remove [label] | Remove a label | | | create [label] | Create a new label | +| | delete [label] | Delete an existing label from repo | | milestone | add [milestone] | Add a milestone to current Issue or PR | | | remove | Remove a milestone from current Issue or PR | | | create [milestone] | Create a new milestone | diff --git a/doc/octo.txt b/doc/octo.txt index 3c7e98b9..985b434f 100644 --- a/doc/octo.txt +++ b/doc/octo.txt @@ -124,6 +124,7 @@ See |octo-command-examples| for examples. add [label] Add specified label or from the available label menu. remove [label] Remove the specified label or from the menu. create [label] Create a new label. + delete [label] Delete the specific label or from the available label menu. :Octo assignee [action] *octo-commands-assignee* diff --git a/lua/octo/commands.lua b/lua/octo/commands.lua index f26ff856..8ff75917 100644 --- a/lua/octo/commands.lua +++ b/lua/octo/commands.lua @@ -384,6 +384,44 @@ function M.setup() remove = function(label) M.remove_label(label) end, + delete = function(label) + local delete_labels = function(labels) + for _, label in ipairs(labels) do + if vim.fn.confirm("Delete label: " .. label.name .. "?", "&Yes\n&No", 2) == 1 then + gh.label.delete { + label.name, + yes = true, + opts = { + cb = gh.create_callback { + success = function() + utils.info("Deleted label: " .. label.name) + end, + }, + }, + } + else + utils.info("Skipped deleting label: " .. label.name) + end + end + end + + local delete_labels_callback = function(labels) + if #labels == 0 then + utils.info "Nothing to delete" + return + end + + delete_labels(labels) + end + + if utils.is_blank(label) then + picker.labels { + cb = delete_labels_callback, + } + else + delete_labels { { name = label } } + end + end, }, assignee = { add = function(login)