From b03ebee2041bcabbaa2d76f7ffb335963e750904 Mon Sep 17 00:00:00 2001 From: Will Dean <57733339+wd60622@users.noreply.github.com> Date: Sun, 23 Feb 2025 04:19:30 +0100 Subject: [PATCH 1/2] allow for gh run commands as well as previous run function (#884) * allow for gh run commands as well as previous run function * add a comment --- lua/octo/gh/init.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lua/octo/gh/init.lua b/lua/octo/gh/init.lua index 1356d3fa..2446feb4 100644 --- a/lua/octo/gh/init.lua +++ b/lua/octo/gh/init.lua @@ -141,7 +141,7 @@ end ---Run a gh command ---@param opts RunOpts ---@return string[]|nil -function M.run(opts) +local function run(opts) if not Job then return end @@ -284,7 +284,7 @@ end ---@return table|nil function M.graphql(opts) local run_opts = opts.opts or {} - return M.run { + return run { args = create_graphql_args(opts.query, opts.fields, opts.paginate, opts.slurp, opts.jq), mode = run_opts.mode, cb = run_opts.cb, @@ -305,7 +305,7 @@ local rest = function(method, opts) opts.opts = nil args = M.insert_args(args, opts) - M.run { + run { args = args, mode = run_opts.mode, cb = run_opts.cb, @@ -346,6 +346,12 @@ local create_subcommand = function(command) subcommand.command = command setmetatable(subcommand, { + __call = function(_, opts) + --- Allow for backwards compatibility with the old API gh.run { ... } + if command == "run" then + return run(opts) + end + end, __index = function(t, key) return function(opts) opts = opts or {} @@ -360,7 +366,7 @@ local create_subcommand = function(command) opts.opts = nil args = M.insert_args(args, opts, { ["_"] = "-" }) - return M.run { + return run { args = args, mode = run_opts.mode, cb = run_opts.cb, From 8deff2b9c1a09af89a9bea041403d46dbe632fe8 Mon Sep 17 00:00:00 2001 From: Will Dean <57733339+wd60622@users.noreply.github.com> Date: Sun, 23 Feb 2025 04:45:35 +0100 Subject: [PATCH 2/2] Favor gh.api.graphql and deprecate gh.graphql (#885) * favor gh.api.graphql over gh.graphql * favor gh.api.graphql over gh.graphql --- lua/octo/gh/init.lua | 42 ++++++++++++++----------- lua/octo/pickers/telescope/provider.lua | 6 ++-- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/lua/octo/gh/init.lua b/lua/octo/gh/init.lua index 2446feb4..536cb9f2 100644 --- a/lua/octo/gh/init.lua +++ b/lua/octo/gh/init.lua @@ -279,10 +279,13 @@ local create_graphql_args = function(query, fields, paginate, slurp, jq) return M.insert_args(args, opts) end +--- The gh.api commands +M.api = {} + ---Run a graphql query ---@param opts table the options for the graphql query ---@return table|nil -function M.graphql(opts) +function M.api.graphql(opts) local run_opts = opts.opts or {} return run { args = create_graphql_args(opts.query, opts.fields, opts.paginate, opts.slurp, opts.jq), @@ -315,24 +318,25 @@ local rest = function(method, opts) } end -M.api = { - graphql = M.graphql, - get = function(opts) - return rest("GET", opts) - end, - post = function(opts) - return rest("POST", opts) - end, - patch = function(opts) - return rest("PATCH", opts) - end, - delete = function(opts) - return rest("DELETE", opts) - end, - put = function(opts) - return rest("PUT", opts) - end, -} +M.api.get = function(opts) + return rest("GET", opts) +end + +M.api.post = function(opts) + return rest("POST", opts) +end + +M.api.patch = function(opts) + return rest("PATCH", opts) +end + +M.api.delete = function(opts) + return rest("DELETE", opts) +end + +M.api.put = function(opts) + return rest("PUT", opts) +end ---Call the api without specifying the method. GitHub CLI determines the method based on the arguments setmetatable(M.api, { diff --git a/lua/octo/pickers/telescope/provider.lua b/lua/octo/pickers/telescope/provider.lua index 76fb2d16..49390abc 100644 --- a/lua/octo/pickers/telescope/provider.lua +++ b/lua/octo/pickers/telescope/provider.lua @@ -522,7 +522,7 @@ end local function get_search_size(prompt) local query = graphql("search_count_query", prompt) - return gh.graphql { + return gh.api.graphql { query = query, jq = ".data.search.issueCount", opts = { @@ -1367,7 +1367,7 @@ function M.discussions(opts) local query = graphql "discussions_query" utils.info "Fetching discussions (this may take a while) ..." - gh.graphql { + gh.api.graphql { query = query, fields = { owner = owner, @@ -1394,7 +1394,7 @@ function M.milestones(opts) local owner, name = utils.split_repo(repo) local query = graphql "open_milestones_query" - gh.graphql { + gh.api.graphql { query = query, fields = { owner = owner,