diff --git a/README.md b/README.md index 64fc1ff..77b5a28 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ Telescope gh issues author=windwp label=bug | `` | insert a reference to the issue | | `` | open web | | `` | insert a markdown-link to the issue | +| `` | create a branch for the issue and check it out locally | ### Gist #### Options Filter diff --git a/lua/telescope/_extensions/gh_actions.lua b/lua/telescope/_extensions/gh_actions.lua index 964f72c..0080d89 100644 --- a/lua/telescope/_extensions/gh_actions.lua +++ b/lua/telescope/_extensions/gh_actions.lua @@ -16,13 +16,13 @@ local function close_telescope_prompt(prompt_bufnr) end return tmp_table[1] end -local function gh_qf_action(pr_number, action, msg) - if pr_number == nil then +local function gh_qf_action(type, pr_or_issue_number, action, msg) + if pr_or_issue_number == nil then return end local qf_entry = { { - text = msg .. pr_number .. ", please wait ...", + text = msg .. pr_or_issue_number .. ", please wait ...", } } local on_output = function(_, line) @@ -36,7 +36,7 @@ local function gh_qf_action(pr_number, action, msg) local job = Job:new { enable_recording = true, command = "gh", - args = flatten { "pr", action, pr_number }, + args = flatten { type, action, pr_or_issue_number }, on_stdout = on_output, on_stderr = on_output, @@ -45,7 +45,7 @@ local function gh_qf_action(pr_number, action, msg) pcall(vim.schedule_wrap(function() vim.cmd [[cclose]] end)) - print "Pull request completed" + print "Done!" end end, } @@ -92,9 +92,21 @@ A.gh_issue_insert_markdown_link = function(prompt_bufnr) end end +A.gh_issue_develop = 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 issue_number = tmp_table[1] + gh_qf_action("issue", issue_number, { "develop", "--checkout" }, "Create and checkout branch for issue #") +end + + A.gh_pr_checkout = function(prompt_bufnr) local pr_number = close_telescope_prompt(prompt_bufnr) - gh_qf_action(pr_number, "checkout", "Checking out pull request #") + gh_qf_action("pr", pr_number, "checkout", "Checking out pull request #") end A.gh_web_view = function(type) @@ -227,13 +239,13 @@ A.gh_pr_merge = function(prompt_bufnr) action = "-s" end if action ~= nil then - gh_qf_action(pr_number, { "merge", action }, "Merge pull request #") + gh_qf_action("pr", pr_number, { "merge", action }, "Merge pull request #") end end A.gh_pr_approve = function(prompt_bufnr) local pr_number = close_telescope_prompt(prompt_bufnr) - gh_qf_action(pr_number, { "review", "--approve" }, "Approve pull request #") + gh_qf_action("pr", pr_number, { "review", "--approve" }, "Approve pull request #") end A.gh_run_web_view = function(prompt_bufnr) diff --git a/lua/telescope/_extensions/gh_builtin.lua b/lua/telescope/_extensions/gh_builtin.lua index f29fd8d..599b6cf 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_issue_develop) return true end, }):find()