@@ -81,77 +81,90 @@ function M.issuesAndPrs(opts)
8181 if u .notInGitRepo () then return end
8282 local repo = M .getGithubRemote ()
8383 if not repo then return end
84- if vim .fn .executable (" curl" ) == 0 then
85- u .notify (" `curl` cannot be found." , " warn" )
86- return
87- end
8884
8985 local defaultOpts = { state = " all" , type = " all" }
9086 opts = vim .tbl_deep_extend (" force" , defaultOpts , opts or {})
9187
9288 -- DOCS https://docs.github.com/en/free-pro-team@latest/rest/issues/issues?apiVersion=2022-11-28#list-repository-issues
9389 local baseUrl = (" https://api.github.com/repos/%s/issues" ):format (repo )
9490 local rawJsonUrl = baseUrl .. (" ?per_page=100&state=%s&sort=updated" ):format (opts .state )
95- local rawJSON = vim .system ({ " curl " , " -sL " , rawJsonUrl }): wait (). stdout or " "
96- local issues = vim . json . decode ( rawJSON )
97- if not issues then
98- u . notify ( " Failed to fetch issues. " , " warn " )
99- return
100- end
101- if issues and opts . type ~= " all " then
102- issues = vim . tbl_filter ( function ( issue )
103- local isPR = issue . pull_request ~= nil
104- local isRightKind = ( isPR and opts . type == " pr " ) or ( not isPR and opts . type == " issue " )
105- return isRightKind
106- end , issues )
107- end
91+ vim .net . request (
92+ rawJsonUrl ,
93+ {},
94+ vim . schedule_wrap ( function ( err , res )
95+ if err then
96+ u . notify (( " Failed to fetch issues: %s " ): format ( err ), " warn " )
97+ return
98+ end
99+ local issues = vim . json . decode ( res . body )
100+ if not issues then
101+ u . notify ( " Failed to decode GitHub response. " , " warn " )
102+ return
103+ end
108104
109- if # issues == 0 then
110- local state = opts .state == " all" and " " or opts .state .. " "
111- local type = opts .type == " all" and " issues or PRs " or opts .type .. " s "
112- local msg = (" There are no %s%sfor this repo." ):format (state , type )
113- u .notify (msg , " warn" )
114- return
115- end
105+ if opts .type ~= " all" then
106+ issues = vim .tbl_filter (function (issue )
107+ local isPR = issue .pull_request ~= nil
108+ local isRightKind = (isPR and opts .type == " pr" )
109+ or (not isPR and opts .type == " issue" )
110+ return isRightKind
111+ end , issues )
112+ end
116113
117- local type = opts .type == " all" and " Issue/PR" or opts .type
118- local mainIcon = require (" tinygit.config" ).config .appearance .mainIcon
119- local prompt = vim .trim ((" %s Select %s (%s)" ):format (mainIcon , type , opts .state ))
120- local onChoice = function (choice ) vim .ui .open (choice .html_url ) end
121- local stylingFunc = function ()
122- local highlights = require (" tinygit.shared.highlights" )
123- highlights .commitType ()
124- highlights .inlineCodeAndIssueNumbers ()
125- vim .fn .matchadd (" DiagnosticError" , [[ \v[Bb]ug]] )
126- vim .fn .matchadd (" DiagnosticInfo" , [[ \v[Ff]eature [Rr]equest|FR]] )
127- vim .fn .matchadd (" Comment" , [[ \vby [A-Za-z0-9-]+\s*$]] )
128- end
129- local function issueListFormatter (issue )
130- local icons = require (" tinygit.config" ).config .github .icons
131- local icon
132- if issue .pull_request then
133- if issue .draft then
134- icon = icons .draftPR
135- elseif issue .state == " open" then
136- icon = icons .openPR
137- elseif issue .pull_request .merged_at then
138- icon = icons .mergedPR
139- else
140- icon = icons .closedPR
114+ if # issues == 0 then
115+ local state = opts .state == " all" and " " or opts .state .. " "
116+ local type = opts .type == " all" and " issues or PRs " or opts .type .. " s "
117+ local msg = (" There are no %s%sfor this repo." ):format (state , type )
118+ u .notify (msg , " warn" )
119+ return
141120 end
142- else
143- if issue .state == " open" then
144- icon = icons .openIssue
145- elseif issue .state_reason == " completed" then
146- icon = icons .closedIssue
147- elseif issue .state_reason == " not_planned" then
148- icon = icons .notPlannedIssue
121+
122+ local type = opts .type == " all" and " Issue/PR" or opts .type
123+ local mainIcon = require (" tinygit.config" ).config .appearance .mainIcon
124+ local prompt = vim .trim ((" %s Select %s (%s)" ):format (mainIcon , type , opts .state ))
125+ local onChoice = function (choice ) vim .ui .open (choice .html_url ) end
126+ local stylingFunc = function ()
127+ local highlights = require (" tinygit.shared.highlights" )
128+ highlights .commitType ()
129+ highlights .inlineCodeAndIssueNumbers ()
130+ vim .fn .matchadd (" DiagnosticError" , [[ \v[Bb]ug]] )
131+ vim .fn .matchadd (" DiagnosticInfo" , [[ \v[Ff]eature [Rr]equest|FR]] )
132+ vim .fn .matchadd (" Comment" , [[ \vby [A-Za-z0-9-]+\s*$]] )
133+ end
134+ local function issueListFormatter (issue )
135+ local icons = require (" tinygit.config" ).config .github .icons
136+ local icon
137+ if issue .pull_request then
138+ if issue .draft then
139+ icon = icons .draftPR
140+ elseif issue .state == " open" then
141+ icon = icons .openPR
142+ elseif issue .pull_request .merged_at then
143+ icon = icons .mergedPR
144+ else
145+ icon = icons .closedPR
146+ end
147+ else
148+ if issue .state == " open" then
149+ icon = icons .openIssue
150+ elseif issue .state_reason == " completed" then
151+ icon = icons .closedIssue
152+ elseif issue .state_reason == " not_planned" then
153+ icon = icons .notPlannedIssue
154+ end
155+ end
156+ return (" %s #%s %s by %s" ):format (icon , issue .number , issue .title , issue .user .login )
149157 end
150- end
151- return (" %s #%s %s by %s" ):format (icon , issue .number , issue .title , issue .user .login )
152- end
153158
154- require (" tinygit.shared.picker" ).pick (prompt , issues , issueListFormatter , stylingFunc , onChoice )
159+ require (" tinygit.shared.picker" ).pick (
160+ prompt ,
161+ issues ,
162+ issueListFormatter ,
163+ stylingFunc ,
164+ onChoice
165+ )
166+ end )
167+ )
155168end
156169
157170function M .openIssueUnderCursor ()
0 commit comments