From 7b924818fdf61e059bdca097d760f6057dc48371 Mon Sep 17 00:00:00 2001 From: madkuntilanak Date: Tue, 26 Aug 2025 02:48:35 +0700 Subject: [PATCH 1/4] fix(fzflua): enhanced content listings and updated previewer --- lua/octo/pickers/fzf-lua/entry_maker.lua | 30 +++++-- lua/octo/pickers/fzf-lua/pickers/actions.lua | 33 ++++++-- lua/octo/pickers/fzf-lua/pickers/issues.lua | 19 +++-- lua/octo/pickers/fzf-lua/pickers/prs.lua | 25 +++--- lua/octo/pickers/fzf-lua/pickers/search.lua | 60 +++++++++++--- lua/octo/pickers/fzf-lua/previewers.lua | 83 ++++++++++++-------- 6 files changed, 180 insertions(+), 70 deletions(-) diff --git a/lua/octo/pickers/fzf-lua/entry_maker.lua b/lua/octo/pickers/fzf-lua/entry_maker.lua index d939e806..c5c8e0c3 100644 --- a/lua/octo/pickers/fzf-lua/entry_maker.lua +++ b/lua/octo/pickers/fzf-lua/entry_maker.lua @@ -10,20 +10,38 @@ function M.gen_from_issue(issue_table) if not issue_table or vim.tbl_isempty(issue_table) then return nil end - local kind = issue_table.__typename == "Issue" and "issue" or "pull_request" - local filename ---@type string - if kind == "issue" then + + local kind, filename, repo, ordinal + + if issue_table.__typename == "Issue" then + kind = "issue" filename = utils.get_issue_uri(issue_table.number, issue_table.repository.nameWithOwner) - else + repo = issue_table.repository.nameWithOwner + ordinal = issue_table.number .. " " .. issue_table.title + elseif issue_table.__typename == "PullRequest" then + kind = "pull_request" filename = utils.get_pull_request_uri(issue_table.number, issue_table.repository.nameWithOwner) + repo = issue_table.repository.nameWithOwner + ordinal = issue_table.number .. " " .. issue_table.title + elseif issue_table.__typename == "Discussion" then + kind = "discussion" + filename = utils.get_discussion_uri(issue_table.number, issue_table.repository.nameWithOwner) + repo = issue_table.repository.nameWithOwner + ordinal = issue_table.number .. " " .. issue_table.title + elseif issue_table.__typename == "Repository" then + kind = "repo" + filename = utils.get_repo_uri(nil, issue_table.nameWithOwner) + repo = issue_table.nameWithOwner + ordinal = issue_table.number end + return { filename = filename, kind = kind, value = issue_table.number, - ordinal = issue_table.number .. " " .. issue_table.title, + ordinal = ordinal, obj = issue_table, - repo = issue_table.repository.nameWithOwner, + repo = repo, } end diff --git a/lua/octo/pickers/fzf-lua/pickers/actions.lua b/lua/octo/pickers/fzf-lua/pickers/actions.lua index c4cb1946..fee622dd 100644 --- a/lua/octo/pickers/fzf-lua/pickers/actions.lua +++ b/lua/octo/pickers/fzf-lua/pickers/actions.lua @@ -2,23 +2,42 @@ local entry_maker = require "octo.pickers.fzf-lua.entry_maker" local fzf = require "fzf-lua" local picker_utils = require "octo.pickers.fzf-lua.pickers.utils" +local utils = require "octo.utils" return function(flattened_actions) - local titles = {} + local action_cmds = {} local formatted_actions = {} + local width = 13 -- hard code? + for _, action in ipairs(flattened_actions) do local entry = entry_maker.gen_from_octo_actions(action) - if entry ~= nil then - formatted_actions[entry.ordinal] = entry - table.insert(titles, entry.ordinal) + if not entry or not entry.ordinal then + utils.error("Failed to process: entry is nil or missing ordinal for action: " .. vim.inspect(action)) + return end + + local icon_with_hl = utils.get_icon(entry) + local icon_str = fzf.utils.ansi_from_hl(icon_with_hl[2], icon_with_hl[1]) + + width = math.max(width, #action.object) + + str_split_ordinal = vim.split(entry.ordinal, " ") + str_cmd_action = fzf.utils.ansi_from_hl("OctoStateOpen", str_split_ordinal[1]) + + local entry_string = str_cmd_action .. (" "):rep(width - #str_split_ordinal[1]) .. str_split_ordinal[2] + + entry.ordinal = fzf.utils.strip_ansi_coloring(entry_string) + formatted_actions[entry.ordinal] = entry + + table.insert(action_cmds, entry_string) end - table.sort(titles) + table.sort(action_cmds) - fzf.fzf_exec(titles, { - prompt = picker_utils.get_prompt "Actions", + fzf.fzf_exec(action_cmds, { + -- prompt = picker_utils.get_prompt "Actions", + prompt = " ", fzf_opts = { ["--no-multi"] = "", }, diff --git a/lua/octo/pickers/fzf-lua/pickers/issues.lua b/lua/octo/pickers/fzf-lua/pickers/issues.lua index c4f5cb6d..1ad1d6fb 100644 --- a/lua/octo/pickers/fzf-lua/pickers/issues.lua +++ b/lua/octo/pickers/fzf-lua/pickers/issues.lua @@ -52,12 +52,21 @@ return function(opts) for _, issue in ipairs(issues) do local entry = entry_maker.gen_from_issue(issue) - - if entry ~= nil then - formatted_issues[entry.ordinal] = entry - local prefix = fzf.utils.ansi_from_hl("Comment", entry.value) - fzf_cb(prefix .. " " .. entry.obj.title) + if not entry or not entry.ordinal then + utils.error("Failed to process: entry is nil or missing ordinal for action: " .. vim.inspect(action)) + return end + + local icon_with_hl = utils.get_icon(entry) + local icon_str = fzf.utils.ansi_from_hl(icon_with_hl[2], icon_with_hl[1]) + + local prefix = fzf.utils.ansi_from_hl("Number", entry.value) + local new_formatted_entry = prefix .. " " .. icon_str .. " " .. entry.obj.title + + entry.ordinal = fzf.utils.strip_ansi_coloring(new_formatted_entry) + formatted_issues[entry.ordinal] = entry + + fzf_cb(new_formatted_entry) end end end, diff --git a/lua/octo/pickers/fzf-lua/pickers/prs.lua b/lua/octo/pickers/fzf-lua/pickers/prs.lua index b70757b6..7d6f015d 100644 --- a/lua/octo/pickers/fzf-lua/pickers/prs.lua +++ b/lua/octo/pickers/fzf-lua/pickers/prs.lua @@ -67,18 +67,21 @@ return function(opts) for _, pull in ipairs(pull_requests) do local entry = entry_maker.gen_from_issue(pull) - - if entry ~= nil then - formatted_pulls[entry.ordinal] = entry - local highlight - if entry.obj.isDraft then - highlight = "OctoSymbol" - else - highlight = "OctoStateOpen" - end - local prefix = fzf.utils.ansi_from_hl(highlight, entry.value) - fzf_cb(prefix .. " " .. entry.obj.title) + if not entry or not entry.ordinal then + utils.error("Failed to process: entry is nil or missing ordinal for action: " .. vim.inspect(action)) + return end + + local icon_with_hl = utils.get_icon(entry) + local icon_str = fzf.utils.ansi_from_hl(icon_with_hl[2], icon_with_hl[1]) + + local prefix = fzf.utils.ansi_from_hl("Number", entry.value) + local new_formatted_entry = prefix .. " " .. icon_str .. " " .. entry.obj.title + + entry.ordinal = fzf.utils.strip_ansi_coloring(new_formatted_entry) + formatted_pulls[entry.ordinal] = entry + + fzf_cb(new_formatted_entry) end end end, diff --git a/lua/octo/pickers/fzf-lua/pickers/search.lua b/lua/octo/pickers/fzf-lua/pickers/search.lua index b399df9e..046b0946 100644 --- a/lua/octo/pickers/fzf-lua/pickers/search.lua +++ b/lua/octo/pickers/fzf-lua/pickers/search.lua @@ -15,17 +15,51 @@ local previewers = require "octo.pickers.fzf-lua.previewers" ---@param co thread local function handle_entry(fzf_cb, issue, max_id_length, formatted_issues, co) local entry = entry_maker.gen_from_issue(issue) - if entry ~= nil then - local owner, name = utils.split_repo(entry.repo) + if entry == nil then + return {} + end + + local ordinal_entry, string_entry + + local owner, name = utils.split_repo(entry.repo) + local icon_with_hl = utils.get_icon(entry) + local icon_str = fzf.utils.ansi_from_hl(icon_with_hl[2], icon_with_hl[1]) + + local ordinal_entry, string_entry + + if entry.kind ~= "repo" then local raw_number = picker_utils.pad_string(entry.obj.number, max_id_length) local number = fzf.utils.ansi_from_hl("Comment", raw_number) - local ordinal_entry = string.format("%s %s %s %s %s", entry.kind, owner, name, raw_number, entry.obj.title) - local string_entry = string.format("%s %s %s %s %s", entry.kind, owner, name, number, entry.obj.title) - formatted_issues[ordinal_entry] = entry - fzf_cb(string_entry, function() - coroutine.resume(co) - end) + + ordinal_entry = fzf.utils.strip_ansi_coloring( + string.format("%s %s %s %s %s %s", entry.kind, owner, name, raw_number, icon_str, entry.obj.title) + ) + string_entry = string.format("%s %s %s %s %s %s", entry.kind, owner, name, number, icon_str, entry.obj.title) end + + if entry.kind == "repo" then + ordinal_entry = string.format( + "%s %s %s %s %s", + entry.repo, + owner, + name, + 1, + entry.obj.nameWithOwner .. " f:" .. entry.obj.forkCount .. " s:" .. entry.obj.stargazerCount + ) + string_entry = string.format( + "%s %s %s %s %s", + entry.repo, + owner, + name, + 1, + entry.obj.nameWithOwner .. " f:" .. entry.obj.forkCount .. " s:" .. entry.obj.stargazerCount + ) + end + + formatted_issues[ordinal_entry] = entry + fzf_cb(string_entry, function() + coroutine.resume(co) + end) end return function(opts) @@ -47,13 +81,19 @@ return function(opts) end for _, val in ipairs(opts.prompt) do - local _prompt = query + local _prompt = "" + + if query and type(query) == "table" then + _prompt = query[1] + end + if val then _prompt = string.format("%s %s", val, _prompt) end + local output = gh.api.graphql { query = queries.search, - fields = { prompt = _prompt }, + fields = { prompt = _prompt, type = opts.type }, jq = ".data.search.nodes", opts = { mode = "sync" }, } diff --git a/lua/octo/pickers/fzf-lua/previewers.lua b/lua/octo/pickers/fzf-lua/previewers.lua index 82541129..b1a07341 100644 --- a/lua/octo/pickers/fzf-lua/previewers.lua +++ b/lua/octo/pickers/fzf-lua/previewers.lua @@ -124,38 +124,59 @@ function M.search() local number = tonumber(match()) local query ---@type string - if kind == "issue" then - query = graphql("issue_query", owner, name, number, _G.octo_pv2_fragment) - elseif kind == "pull_request" then - query = graphql("pull_request_query", owner, name, number, _G.octo_pv2_fragment) - end - gh.run { - args = { "api", "graphql", "-f", string.format("query=%s", query) }, - cb = function(output, stderr) - if stderr and not utils.is_blank(stderr) then - utils.print_err(stderr) - elseif output and self.preview_bufnr == tmpbuf and vim.api.nvim_buf_is_valid(tmpbuf) then - local result = vim.json.decode(output) - local obj - if kind == "issue" then - obj = result.data.repository.issue - elseif kind == "pull_request" then - obj = result.data.repository.pullRequest - end - - local state = utils.get_displayed_state(kind == "issue", obj.state, obj.stateReason) + if kind ~= "discussion" then + if kind == "issue" then + query = graphql("issue_query", owner, name, number, _G.octo_pv2_fragment) + end + if kind == "pull_request" then + query = graphql("pull_request_query", owner, name, number, _G.octo_pv2_fragment) + end - writers.write_title(tmpbuf, obj.title, 1) - writers.write_details(tmpbuf, obj) - writers.write_body(tmpbuf, obj) - writers.write_state(tmpbuf, state:upper(), number) - local reactions_line = vim.api.nvim_buf_line_count(tmpbuf) - 1 - writers.write_block(tmpbuf, { "", "" }, reactions_line) - writers.write_reactions(tmpbuf, obj.reactionGroups, reactions_line) - vim.bo[tmpbuf].filetype = "octo" - end - end, - } + gh.run { + args = { "api", "graphql", "-f", string.format("query=%s", query) }, + cb = function(output, stderr) + if stderr and not utils.is_blank(stderr) then + utils.print_err(stderr) + elseif output and self.preview_bufnr == tmpbuf and vim.api.nvim_buf_is_valid(tmpbuf) then + local result = vim.json.decode(output) + local obj + if kind == "issue" then + obj = result.data.repository.issue + elseif kind == "pull_request" then + obj = result.data.repository.pullRequest + end + + local state = utils.get_displayed_state(kind == "issue", obj.state, obj.stateReason) + + writers.write_title(tmpbuf, obj.title, 1) + writers.write_details(tmpbuf, obj) + writers.write_body(tmpbuf, obj) + writers.write_state(tmpbuf, state:upper(), number) + local reactions_line = vim.api.nvim_buf_line_count(tmpbuf) - 1 + writers.write_block(tmpbuf, { "", "" }, reactions_line) + writers.write_reactions(tmpbuf, obj.reactionGroups, reactions_line) + vim.bo[tmpbuf].filetype = "octo" + end + end, + } + else + gh.api.graphql { + query = queries.discussion, + fields = { owner = owner, name = name, number = number }, + jq = ".data.repository.discussion", + opts = { + cb = function(output, stderr) + if stderr and not utils.is_blank(stderr) then + utils.print_err(stderr) + elseif output and self.preview_bufnr == tmpbuf and vim.api.nvim_buf_is_valid(tmpbuf) then + local result = vim.json.decode(output) + + writers.discussion_preview(result, tmpbuf) + end + end, + }, + } + end self:set_preview_buf(tmpbuf) -- self:update_border(number.." "..description) From 97b1da3c0dd11cf7318c4f895c3bedba727cff0f Mon Sep 17 00:00:00 2001 From: madkuntilanak Date: Wed, 27 Aug 2025 01:33:07 +0700 Subject: [PATCH 2/4] fix(fzflua): resolve query issue in `Octo repo search` --- lua/octo/pickers/fzf-lua/pickers/search.lua | 131 +++++++++++++------- 1 file changed, 89 insertions(+), 42 deletions(-) diff --git a/lua/octo/pickers/fzf-lua/pickers/search.lua b/lua/octo/pickers/fzf-lua/pickers/search.lua index 046b0946..5444d252 100644 --- a/lua/octo/pickers/fzf-lua/pickers/search.lua +++ b/lua/octo/pickers/fzf-lua/pickers/search.lua @@ -31,29 +31,31 @@ local function handle_entry(fzf_cb, issue, max_id_length, formatted_issues, co) local raw_number = picker_utils.pad_string(entry.obj.number, max_id_length) local number = fzf.utils.ansi_from_hl("Comment", raw_number) - ordinal_entry = fzf.utils.strip_ansi_coloring( - string.format("%s %s %s %s %s %s", entry.kind, owner, name, raw_number, icon_str, entry.obj.title) - ) - string_entry = string.format("%s %s %s %s %s %s", entry.kind, owner, name, number, icon_str, entry.obj.title) + local str_format = string.format("%s %s %s %s %s %s", entry.kind, owner, name, number, icon_str, entry.obj.title) + string_entry = str_format + ordinal_entry = fzf.utils.strip_ansi_coloring(str_format) end if entry.kind == "repo" then - ordinal_entry = string.format( - "%s %s %s %s %s", - entry.repo, - owner, - name, - 1, - entry.obj.nameWithOwner .. " f:" .. entry.obj.forkCount .. " s:" .. entry.obj.stargazerCount - ) - string_entry = string.format( - "%s %s %s %s %s", + local raw_name_with_owner = picker_utils.pad_string(entry.obj.nameWithOwner, max_id_length) + local name_with_owner = fzf.utils.ansi_from_hl("OctoGreen", raw_name_with_owner) + local description_repo = entry.obj.description and entry.obj.description or "" + + local str_format = string.format( + "%s %s %s %s", entry.repo, owner, name, - 1, - entry.obj.nameWithOwner .. " f:" .. entry.obj.forkCount .. " s:" .. entry.obj.stargazerCount + string.format( + "%s %-" .. (#raw_name_with_owner - max_id_length) .. "s %-20s %-10s", + name_with_owner, + " f:" .. entry.obj.forkCount, + " s:" .. entry.obj.stargazerCount, + tostring(description_repo) + ) ) + string_entry = str_format + ordinal_entry = fzf.utils.strip_ansi_coloring(str_format) end formatted_issues[ordinal_entry] = entry @@ -67,56 +69,98 @@ return function(opts) local formatted_items = {} ---@type table entry.ordinal -> entry + local is_hidden = false + if opts.type == "REPOSITORY" then + is_hidden = true + end + local function contents(query) return function(fzf_cb) coroutine.wrap(function() local co = coroutine.running() - if not opts.prompt and utils.is_blank(query) then - return {} - end + local function process_issues(output) + if utils.is_blank(output) then + return {} + end - if type(opts.prompt) == "string" then - opts.prompt = { opts.prompt } + local issues = vim.json.decode(output) + + local max_id_length = 1 + for _, issue in ipairs(issues) do + local id_length = max_id_length + if opts.type == "REPOSITORY" then + if issue.nameWithOwner then + id_length = #tostring(issue.nameWithOwner) + end + else + if issue.number then + id_length = #tostring(issue.number) + end + end + + if id_length > max_id_length then + max_id_length = id_length + end + end + + for _, issue in ipairs(issues) do + vim.schedule(function() + handle_entry(fzf_cb, issue, max_id_length, formatted_items, co) + end) + coroutine.yield() + end end - for _, val in ipairs(opts.prompt) do - local _prompt = "" + local function build_prompt(base_prompt, query) + local _q = "" + + if query and type(query) == "string" then + _q = query + end if query and type(query) == "table" then - _prompt = query[1] + _q = query[1] end - if val then - _prompt = string.format("%s %s", val, _prompt) + local prompt = string.format("%s %s", base_prompt or "", _q) + if prompt then + return prompt end + return base_prompt or "" + end + + if opts.type == "REPOSITORY" then + local prompt = build_prompt(opts.prompt, query) + local output = gh.api.graphql { query = queries.search, - fields = { prompt = _prompt, type = opts.type }, + f = { prompt = prompt, type = "REPOSITORY" }, + F = { last = 50 }, jq = ".data.search.nodes", opts = { mode = "sync" }, } + process_issues(output) + else + if type(opts.prompt) == "string" then + opts.prompt = { opts.prompt } + end - if utils.is_blank(output) then + if not opts.prompt or (utils.is_blank(query) and not opts.prompt) then return {} end - local issues = vim.json.decode(output) + for _, val in ipairs(opts.prompt) do + local prompt = build_prompt(val, query) - local max_id_length = 1 - for _, issue in ipairs(issues) do - local s = tostring(issue.number) - if #s > max_id_length then - max_id_length = #s - end - end - - for _, issue in ipairs(issues) do - vim.schedule(function() - handle_entry(fzf_cb, issue, max_id_length, formatted_items, co) - end) - coroutine.yield() + local output = gh.api.graphql { + query = queries.search, + fields = { prompt = prompt, type = opts.type }, + jq = ".data.search.nodes", + opts = { mode = "sync" }, + } + process_issues(output) end end @@ -137,6 +181,9 @@ return function(opts) ["--delimiter"] = " ", ["--with-nth"] = "4..", }, + winopts = { + preview = { hidden = is_hidden }, + }, actions = fzf_actions.common_open_actions(formatted_items), }) end From 66eee44f3d96ef0092d0b8d94c75f366c0165933 Mon Sep 17 00:00:00 2001 From: madkuntilanak Date: Wed, 27 Aug 2025 02:30:19 +0700 Subject: [PATCH 3/4] ref(fzflua): add color and width for `Octo repo search` --- lua/octo/pickers/fzf-lua/pickers/search.lua | 33 ++++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/lua/octo/pickers/fzf-lua/pickers/search.lua b/lua/octo/pickers/fzf-lua/pickers/search.lua index 5444d252..d336250e 100644 --- a/lua/octo/pickers/fzf-lua/pickers/search.lua +++ b/lua/octo/pickers/fzf-lua/pickers/search.lua @@ -23,14 +23,15 @@ local function handle_entry(fzf_cb, issue, max_id_length, formatted_issues, co) local owner, name = utils.split_repo(entry.repo) local icon_with_hl = utils.get_icon(entry) - local icon_str = fzf.utils.ansi_from_hl(icon_with_hl[2], icon_with_hl[1]) local ordinal_entry, string_entry if entry.kind ~= "repo" then - local raw_number = picker_utils.pad_string(entry.obj.number, max_id_length) + local raw_number = picker_utils.pad_string(entry.obj.number, max_id_length + 1) local number = fzf.utils.ansi_from_hl("Comment", raw_number) + local icon_str = fzf.utils.ansi_from_hl(icon_with_hl[2], icon_with_hl[1]) + local str_format = string.format("%s %s %s %s %s %s", entry.kind, owner, name, number, icon_str, entry.obj.title) string_entry = str_format ordinal_entry = fzf.utils.strip_ansi_coloring(str_format) @@ -39,7 +40,24 @@ local function handle_entry(fzf_cb, issue, max_id_length, formatted_issues, co) if entry.kind == "repo" then local raw_name_with_owner = picker_utils.pad_string(entry.obj.nameWithOwner, max_id_length) local name_with_owner = fzf.utils.ansi_from_hl("OctoGreen", raw_name_with_owner) - local description_repo = entry.obj.description and entry.obj.description or "" + + local forkcount = entry.obj.forkCount + local len_forkcount = #tostring(forkcount) + local max_width = 7 + local width = math.max(max_width, len_forkcount) + + local raw_forkname = picker_utils.pad_string(entry.obj.forkCount, width) + local fork_name = fzf.utils.ansi_from_hl("OctoBlue", raw_forkname) + + local raw_stargazer_count = picker_utils.pad_string(entry.obj.stargazerCount, width) + local stargazer_count = fzf.utils.ansi_from_hl("OctoYellow", raw_stargazer_count) + + local get_private_or_public = not entry.obj.isPrivate and "Public" or "Private" + local raw_private_or_public = picker_utils.pad_string(get_private_or_public, width) + local private_or_public = fzf.utils.ansi_from_hl("Function", raw_private_or_public) + + local get_description_repo = entry.obj.description and entry.obj.description or "" + local description_repo = fzf.utils.ansi_from_hl("Boolean", get_description_repo) local str_format = string.format( "%s %s %s %s", @@ -47,11 +65,12 @@ local function handle_entry(fzf_cb, issue, max_id_length, formatted_issues, co) owner, name, string.format( - "%s %-" .. (#raw_name_with_owner - max_id_length) .. "s %-20s %-10s", + "%s %s %s %s %s", name_with_owner, - " f:" .. entry.obj.forkCount, - " s:" .. entry.obj.stargazerCount, - tostring(description_repo) + " f:" .. fork_name, + " s:" .. stargazer_count, + private_or_public, + description_repo ) ) string_entry = str_format From 16fdead2e1e8426a6f17454de06468b7d90b4949 Mon Sep 17 00:00:00 2001 From: madkuntilanak Date: Wed, 27 Aug 2025 08:41:11 +0700 Subject: [PATCH 4/4] fix(fzflua): error previewers `Octo repo list` --- lua/octo/pickers/fzf-lua/entry_maker.lua | 15 ++++++++------- lua/octo/pickers/fzf-lua/previewers.lua | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/lua/octo/pickers/fzf-lua/entry_maker.lua b/lua/octo/pickers/fzf-lua/entry_maker.lua index c5c8e0c3..930e1686 100644 --- a/lua/octo/pickers/fzf-lua/entry_maker.lua +++ b/lua/octo/pickers/fzf-lua/entry_maker.lua @@ -31,7 +31,7 @@ function M.gen_from_issue(issue_table) elseif issue_table.__typename == "Repository" then kind = "repo" filename = utils.get_repo_uri(nil, issue_table.nameWithOwner) - repo = issue_table.nameWithOwner + repo = issue_table.nameWithOwner .. "/repo" ordinal = issue_table.number end @@ -263,26 +263,27 @@ function M.gen_from_repo(repo) end local entry = { - filename = utils.get_repo_uri(_, repo), + filename = utils.get_repo_uri(_, repo.nameWithOwner), + repo = repo.nameWithOwner .. "/repo", kind = "repo", value = repo.nameWithOwner, ordinal = repo.nameWithOwner .. " " .. repo.description, - repo = repo, + obj = repo, } - local name = fzf.utils.ansi_from_hl("Directory", entry.repo.nameWithOwner) + local name = fzf.utils.ansi_from_hl("Directory", entry.obj.nameWithOwner) local fork_str = "" - if entry.repo.isFork then + if entry.obj.isFork then fork_str = fzf.utils.ansi_from_hl("Comment", "fork") end local access_str = fzf.utils.ansi_from_hl("Directory", "public") - if entry.repo.isPrivate then + if entry.obj.isPrivate then access_str = fzf.utils.ansi_from_hl("WarningMsg", "private") end local metadata = string.format("(%s)", table.concat({ fork_str, access_str }, ", ")) - local description = fzf.utils.ansi_from_hl("Comment", entry.repo.description) + local description = fzf.utils.ansi_from_hl("Comment", entry.obj.description) local entry_str = table.concat({ name, metadata, diff --git a/lua/octo/pickers/fzf-lua/previewers.lua b/lua/octo/pickers/fzf-lua/previewers.lua index b1a07341..4762e31c 100644 --- a/lua/octo/pickers/fzf-lua/previewers.lua +++ b/lua/octo/pickers/fzf-lua/previewers.lua @@ -340,8 +340,12 @@ function M.repo(formatted_repos) local buffer = OctoBuffer:new { bufnr = tmpbuf, + repo = entry.repo, + node = entry.obj, + kind = entry.kind, } buffer:configure() + local repo_name_owner = vim.split(entry_str, " ")[1] local owner, name = utils.split_repo(repo_name_owner) @@ -350,10 +354,13 @@ function M.repo(formatted_repos) -- and `tmpbuf` within this context is already cleared and invalidated if self.preview_bufnr == tmpbuf and vim.api.nvim_buf_is_valid(tmpbuf) then local resp = vim.json.decode(output) - buffer.node = resp.data.repository - buffer:render_repo() + if resp.data and resp.data.repository then + buffer.node = resp.data.repository + buffer:render_repo() + end end end + gh.api.graphql { query = queries.repository, f = { owner = owner, name = name }, @@ -366,11 +373,11 @@ function M.repo(formatted_repos) ---@type string, string local stargazer, fork if config.values.picker_config.use_emojis then - stargazer = string.format("💫: %s", entry.repo.stargazerCount) - fork = string.format("🔱: %s", entry.repo.forkCount) + stargazer = string.format("💫: %s", entry.obj.stargazerCount) + fork = string.format("🔱: %s", entry.obj.forkCount) else - stargazer = string.format("s: %s", entry.repo.stargazerCount) - fork = string.format("f: %s", entry.repo.forkCount) + stargazer = string.format("s: %s", entry.obj.stargazerCount) + fork = string.format("f: %s", entry.obj.forkCount) end self:update_border(string.format("%s (%s, %s)", repo_name_owner, stargazer, fork)) end