diff --git a/lua/octo/commands.lua b/lua/octo/commands.lua index ea12d12e..d516718f 100644 --- a/lua/octo/commands.lua +++ b/lua/octo/commands.lua @@ -73,7 +73,7 @@ function M.setup() local buffer = octo_buffers[bufnr] if buffer and buffer.kind and buffer.kind == "issue" then - utils.develop_issue(buffer.node.number) + utils.develop_issue(buffer.repo, buffer.node.number, repo) else local opts = M.process_varargs(repo, ...) picker.issues(opts, true) diff --git a/lua/octo/pickers/telescope/provider.lua b/lua/octo/pickers/telescope/provider.lua index 1fa2d1ad..731dfe65 100644 --- a/lua/octo/pickers/telescope/provider.lua +++ b/lua/octo/pickers/telescope/provider.lua @@ -133,17 +133,10 @@ 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) + utils.develop_issue(selection.repo, selection.obj.number, nil) 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" @@ -157,6 +150,13 @@ function M.issues(opts, develop) return end + local replace + if develop then + replace = develop_issue + else + replace = open_issue_buffer + end + local owner, name = utils.split_repo(opts.repo) local cfg = octo_config.values local order_by = cfg.issues.order_by diff --git a/lua/octo/utils.lua b/lua/octo/utils.lua index d924d0b5..19b0bf10 100644 --- a/lua/octo/utils.lua +++ b/lua/octo/utils.lua @@ -318,18 +318,38 @@ function M.commit_exists(commit, cb) }):start() end -function M.develop_issue(issue_number) +function M.develop_issue(issue_repo, issue_number, branch_repo) if not Job then return end + if M.is_blank(branch_repo) then + branch_repo = M.get_remote_name() + 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) + args = { + "issue", + "develop", + "--repo", + issue_repo, + issue_number, + "--checkout", + "--branch-repo", + branch_repo, + }, + on_exit = vim.schedule_wrap(function(job, code) + if code == 0 then + local output = vim.fn.system "git branch --show-current" + M.info("Switched to " .. output) + else + local stderr = table.concat(job:stderr_result(), "\n") + if not M.is_blank(stderr) then + M.error(stderr) + end + end end), }):start() end