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
43 changes: 31 additions & 12 deletions lua/octo/pickers/fzf-lua/entry_maker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 .. "/repo"
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

Expand Down Expand Up @@ -245,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,
Expand Down
33 changes: 26 additions & 7 deletions lua/octo/pickers/fzf-lua/pickers/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = "",
},
Expand Down
19 changes: 14 additions & 5 deletions lua/octo/pickers/fzf-lua/pickers/issues.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 14 additions & 11 deletions lua/octo/pickers/fzf-lua/pickers/prs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading