Skip to content

Commit

Permalink
Merge branch 'master' into feat/octo-run-list
Browse files Browse the repository at this point in the history
  • Loading branch information
wd60622 authored Feb 23, 2025
2 parents 7bfe613 + 8deff2b commit 1dde8cb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
56 changes: 33 additions & 23 deletions lua/octo/gh/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -279,12 +279,15 @@ 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 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,
Expand All @@ -305,7 +308,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,
Expand All @@ -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, {
Expand All @@ -346,6 +350,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 {}
Expand All @@ -360,7 +370,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,
Expand Down
6 changes: 3 additions & 3 deletions lua/octo/pickers/telescope/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -1391,7 +1391,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,
Expand All @@ -1418,7 +1418,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,
Expand Down

0 comments on commit 1dde8cb

Please sign in to comment.