From 795d31825fcd3867d3f515dcf01a29d8cfd186cf Mon Sep 17 00:00:00 2001 From: Peter Gundel Date: Wed, 1 Mar 2023 00:37:49 +0100 Subject: [PATCH] Add gh issues develop #ID --checkout This adds the only recently available Github CLI command to create a branch for an issue and checking it locally out. See https://github.com/cli/cli/issues/5469 --- lua/telescope/_extensions/gh_actions.lua | 23 +++++++++++++++++++++++ lua/telescope/_extensions/gh_builtin.lua | 1 + 2 files changed, 24 insertions(+) diff --git a/lua/telescope/_extensions/gh_actions.lua b/lua/telescope/_extensions/gh_actions.lua index 964f72c..4f4648e 100644 --- a/lua/telescope/_extensions/gh_actions.lua +++ b/lua/telescope/_extensions/gh_actions.lua @@ -115,6 +115,29 @@ A.gh_web_view = function(type) end end +A.gh_develop = function() + return function(prompt_bufnr) + local selection = action_state.get_selected_entry() + actions.close(prompt_bufnr) + local tmp_table = vim.split(selection.value, "\t") + if vim.tbl_isempty(tmp_table) then + return + end + local id = tmp_table[1] + -- We can't use os.execute here because it takes a bit + vim.fn.jobstart( + "echo \"Creating a new branch ...\" && gh issue develop " .. id .. " --checkout && echo \"Done!\"", + { + on_stdout = function(_channel_id, data, _name) + if data[1] ~= "" then + print(data[1]) + end + end + } + ) + end +end + A.gh_gist_append = function(prompt_bufnr) local selection = action_state.get_selected_entry() actions.close(prompt_bufnr) diff --git a/lua/telescope/_extensions/gh_builtin.lua b/lua/telescope/_extensions/gh_builtin.lua index f29fd8d..f1eb0c0 100644 --- a/lua/telescope/_extensions/gh_builtin.lua +++ b/lua/telescope/_extensions/gh_builtin.lua @@ -111,6 +111,7 @@ B.gh_issues = function(opts) actions.select_default:replace(gh_a.gh_issue_insert) map("i", "", gh_a.gh_web_view "issue") map("i", "", gh_a.gh_issue_insert_markdown_link) + map("i", "", gh_a.gh_develop "issue") return true end, }):find()