Skip to content

Commit

Permalink
add develop command
Browse files Browse the repository at this point in the history
  • Loading branch information
wd60622 committed Sep 19, 2024
1 parent 955f0fd commit 0993202
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
12 changes: 12 additions & 0 deletions lua/octo/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ function M.setup()
close = function()
M.change_state "CLOSED"
end,
develop = function(repo, ...)
local bufnr = vim.api.nvim_get_current_buf()
local buffer = octo_buffers[bufnr]

if not buffer then
local opts = M.process_varargs(repo, ...)
picker.issues(opts, true)
return
end

utils.develop_issue(buffer.node.number)
end,
reopen = function()
M.change_state "OPEN"
end,
Expand Down
24 changes: 20 additions & 4 deletions lua/octo/pickers/telescope/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,25 @@ end
--
-- ISSUES
--
function M.issues(opts)
local function open_issue_buffer(prompt_bufnr, type)
open(type)(prompt_bufnr)
end

local function develop_issue(prompt_bufnr, type)
local selection = action_state.get_selected_entry(prompt_bufnr)
actions.close(prompt_bufnr)

utils.develop_issue(selection.obj.number)
end

function M.issues(opts, develop)
local replace
if develop then
replace = develop_issue
else
replace = open_issue_buffer
end

opts = opts or {}
if not opts.states then
opts.states = "OPEN"
Expand Down Expand Up @@ -172,9 +190,7 @@ function M.issues(opts)
sorter = conf.generic_sorter(opts),
previewer = previewers.issue.new(opts),
attach_mappings = function(_, map)
action_set.select:replace(function(prompt_bufnr, type)
open(type)(prompt_bufnr)
end)
action_set.select:replace(replace)
map("i", cfg.picker_config.mappings.open_in_browser.lhs, open_in_browser())
map("i", cfg.picker_config.mappings.copy_url.lhs, copy_url())
return true
Expand Down
16 changes: 16 additions & 0 deletions lua/octo/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,22 @@ function M.commit_exists(commit, cb)
}):start()
end

function M.develop_issue(issue_number)
if not Job then
return
end

Job:new({
enable_recording = true,
command = "gh",
args = { "issue", "develop", issue_number, "--checkout" },
on_exit = vim.schedule_wrap(function()
local output = vim.fn.system "git branch --show-current"
M.info("Switched to " .. output)
end),
}):start()
end

function M.get_file_at_commit(path, commit, cb)
if not Job then
return
Expand Down

0 comments on commit 0993202

Please sign in to comment.