Skip to content

Commit

Permalink
Favor gh.api.graphql and deprecate gh.graphql (#885)
Browse files Browse the repository at this point in the history
* favor gh.api.graphql over gh.graphql

* favor gh.api.graphql over gh.graphql
  • Loading branch information
wd60622 authored Feb 23, 2025
1 parent b03ebee commit 8deff2b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
42 changes: 23 additions & 19 deletions lua/octo/gh/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 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 @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 8deff2b

Please sign in to comment.