1
+ local entry_maker = require " octo.pickers.fzf-lua.entry_maker"
1
2
local octo_config = require " octo.config"
2
3
local queries = require " octo.gh.queries"
3
4
local fzf = require " fzf-lua"
@@ -6,15 +7,17 @@ local graphql = require "octo.gh.graphql"
6
7
local picker_utils = require " octo.pickers.fzf-lua.pickers.utils"
7
8
local utils = require " octo.utils"
8
9
10
+ local M = { orgs = {} }
11
+
9
12
local delimiter = " \t "
10
13
11
14
local fzf_opts = {
12
15
[" --delimiter" ] = delimiter ,
13
- [" --with-nth" ] = " 2 .." ,
16
+ [" --with-nth" ] = " 3 .." ,
14
17
}
15
18
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
18
21
if thing .name and thing .name ~= vim .NIL then
19
22
str = string.format (" %s (%s)" , str , thing .name )
20
23
end
@@ -35,7 +38,6 @@ local function get_user_requester(prompt)
35
38
return {}
36
39
end
37
40
local users = {}
38
- local orgs = {}
39
41
-- check if the output has }{ and if so, split it and parse each part
40
42
local end_idx = output :find " }{"
41
43
-- add a newline after }{ if it exists
@@ -60,31 +62,30 @@ local function get_user_requester(prompt)
60
62
end
61
63
end
62
64
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 ] = {
66
68
id = user .id ,
67
69
login = user .login ,
68
70
teams = user .teams .nodes ,
69
71
}
70
72
else
71
- vim .list_extend (orgs [user .login ].teams , user .teams .nodes )
73
+ vim .list_extend (M . orgs [user .login ].teams , user .teams .nodes )
72
74
end
73
75
end
74
76
end
75
77
end
76
78
end
77
- vim .print (" orgs: " .. vim .inspect (orgs ))
78
79
79
80
local results = {}
80
81
-- process orgs with teams
81
82
for _ , user in pairs (users ) do
82
- user .ordinal = format_display (user )
83
+ user .ordinal = format_display (user , " user " )
83
84
table.insert (results , user .ordinal )
84
85
end
85
- for _ , org in pairs (orgs ) do
86
+ for _ , org in pairs (M . orgs ) do
86
87
org .login = string.format (" %s (%d)" , org .login , # org .teams )
87
- org .ordinal = format_display (org )
88
+ org .ordinal = format_display (org , " org " )
88
89
table.insert (results , org .ordinal )
89
90
end
90
91
return results
@@ -107,7 +108,7 @@ local function get_users(query_name, node_name)
107
108
local results = {}
108
109
local flattened = utils .get_flatten_pages (output )
109
110
for _ , user in ipairs (flattened ) do
110
- user .ordinal = format_display (user )
111
+ user .ordinal = format_display (user , " user " )
111
112
table.insert (results , user .ordinal )
112
113
end
113
114
return results
@@ -121,8 +122,9 @@ local function get_mentionable_users()
121
122
return get_users (" mentionable_users" , " mentionableUsers" )
122
123
end
123
124
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 ]
126
128
end
127
129
128
130
return function (cb )
@@ -135,7 +137,35 @@ return function(cb)
135
137
actions = {
136
138
[" default" ] = {
137
139
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
139
169
end ,
140
170
},
141
171
},
@@ -161,7 +191,8 @@ return function(cb)
161
191
fzf_opts = fzf_opts ,
162
192
actions = {
163
193
[" 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 )
165
196
end ,
166
197
},
167
198
})
0 commit comments