Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Telescope gh issues author=windwp label=bug
| `<cr>` | insert a reference to the issue |
| `<c-t>` | open web |
| `<c-l>` | insert a markdown-link to the issue |
| `<c-z>` | create a branch for the issue and check it out locally |

### Gist
#### Options Filter
Expand Down
28 changes: 20 additions & 8 deletions lua/telescope/_extensions/gh_actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,

Expand All @@ -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,
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lua/telescope/_extensions/gh_builtin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ B.gh_issues = function(opts)
actions.select_default:replace(gh_a.gh_issue_insert)
map("i", "<c-t>", gh_a.gh_web_view "issue")
map("i", "<c-l>", gh_a.gh_issue_insert_markdown_link)
map("i", "<c-z>", gh_a.gh_issue_develop)
return true
end,
}):find()
Expand Down