Skip to content

Commit 52431d7

Browse files
committed
☘️ work in progress Wed Jun 18 15:42:44 2025
1 parent c474730 commit 52431d7

File tree

1 file changed

+48
-17
lines changed

1 file changed

+48
-17
lines changed

lua/octo/pickers/fzf-lua/pickers/users.lua

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local entry_maker = require "octo.pickers.fzf-lua.entry_maker"
12
local octo_config = require "octo.config"
23
local queries = require "octo.gh.queries"
34
local fzf = require "fzf-lua"
@@ -6,15 +7,17 @@ local graphql = require "octo.gh.graphql"
67
local picker_utils = require "octo.pickers.fzf-lua.pickers.utils"
78
local utils = require "octo.utils"
89

10+
local M = { orgs = {} }
11+
912
local delimiter = "\t"
1013

1114
local fzf_opts = {
1215
["--delimiter"] = delimiter,
13-
["--with-nth"] = "2..",
16+
["--with-nth"] = "3..",
1417
}
1518

16-
local function format_display(thing)
17-
local str = thing.id .. delimiter .. thing.login
19+
local function format_display(thing, type)
20+
local str = thing.id .. delimiter .. type .. delimiter .. thing.login
1821
if thing.name and thing.name ~= vim.NIL then
1922
str = string.format("%s (%s)", str, thing.name)
2023
end
@@ -35,7 +38,6 @@ local function get_user_requester(prompt)
3538
return {}
3639
end
3740
local users = {}
38-
local orgs = {}
3941
-- check if the output has }{ and if so, split it and parse each part
4042
local end_idx = output:find "}{"
4143
-- add a newline after }{ if it exists
@@ -60,31 +62,30 @@ local function get_user_requester(prompt)
6062
end
6163
end
6264
elseif user.teams and user.teams.totalCount > 0 then
63-
-- organization, collect all teams
64-
if not vim.tbl_contains(vim.tbl_keys(orgs), user.login) then
65-
orgs[user.login] = {
65+
-- organization, collect orgs
66+
if not vim.tbl_contains(vim.tbl_keys(M.orgs), user.login) then
67+
M.orgs[user.id] = {
6668
id = user.id,
6769
login = user.login,
6870
teams = user.teams.nodes,
6971
}
7072
else
71-
vim.list_extend(orgs[user.login].teams, user.teams.nodes)
73+
vim.list_extend(M.orgs[user.login].teams, user.teams.nodes)
7274
end
7375
end
7476
end
7577
end
7678
end
77-
vim.print("orgs: " .. vim.inspect(orgs))
7879

7980
local results = {}
8081
-- process orgs with teams
8182
for _, user in pairs(users) do
82-
user.ordinal = format_display(user)
83+
user.ordinal = format_display(user, "user")
8384
table.insert(results, user.ordinal)
8485
end
85-
for _, org in pairs(orgs) do
86+
for _, org in pairs(M.orgs) do
8687
org.login = string.format("%s (%d)", org.login, #org.teams)
87-
org.ordinal = format_display(org)
88+
org.ordinal = format_display(org, "org")
8889
table.insert(results, org.ordinal)
8990
end
9091
return results
@@ -107,7 +108,7 @@ local function get_users(query_name, node_name)
107108
local results = {}
108109
local flattened = utils.get_flatten_pages(output)
109110
for _, user in ipairs(flattened) do
110-
user.ordinal = format_display(user)
111+
user.ordinal = format_display(user, "user")
111112
table.insert(results, user.ordinal)
112113
end
113114
return results
@@ -121,8 +122,9 @@ local function get_mentionable_users()
121122
return get_users("mentionable_users", "mentionableUsers")
122123
end
123124

124-
local function get_user_id(selection)
125-
return vim.split(selection[1], delimiter)[1]
125+
local function get_user_id_type(selection)
126+
local spl = vim.split(selection[1], delimiter)
127+
return spl[1], spl[2]
126128
end
127129

128130
return function(cb)
@@ -135,7 +137,35 @@ return function(cb)
135137
actions = {
136138
["default"] = {
137139
function(user_selected)
138-
cb(get_user_id(user_selected))
140+
local user_id, user_type = get_user_id_type(user_selected)
141+
if user_type == "user" then
142+
cb(user_id)
143+
else
144+
-- handle org
145+
local formatted_teams = {}
146+
local team_titles = {}
147+
148+
for _, team in ipairs(M.orgs[user_id].teams) do
149+
local team_entry = entry_maker.gen_from_team(team)
150+
151+
if team_entry ~= nil then
152+
formatted_teams[team_entry.ordinal] = team_entry
153+
table.insert(team_titles, team_entry.ordinal)
154+
end
155+
end
156+
157+
fzf.fzf_exec(
158+
team_titles,
159+
vim.tbl_deep_extend("force", picker_utils.dropdown_opts, {
160+
actions = {
161+
["default"] = function(team_selected)
162+
local team_entry = formatted_teams[team_selected[1]]
163+
cb(team_entry.team.id)
164+
end,
165+
},
166+
})
167+
)
168+
end
139169
end,
140170
},
141171
},
@@ -161,7 +191,8 @@ return function(cb)
161191
fzf_opts = fzf_opts,
162192
actions = {
163193
["default"] = function(user_selected)
164-
cb(get_user_id(user_selected))
194+
local user_id, _ = get_user_id_type(user_selected)
195+
cb(user_id)
165196
end,
166197
},
167198
})

0 commit comments

Comments
 (0)