Skip to content

Commit

Permalink
refactor issue navigation (#895)
Browse files Browse the repository at this point in the history
* parameterize query

* use the new api
  • Loading branch information
wd60622 authored Feb 24, 2025
1 parent 65ba35c commit 1619301
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
6 changes: 3 additions & 3 deletions lua/octo/gh/graphql.lua
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,9 @@ query($endCursor: String) {

-- https://docs.github.com/en/graphql/reference/unions#issueorpullrequest
M.issue_kind_query = [[
query {
repository(owner: "%s", name: "%s") {
issueOrPullRequest(number: %d) {
query($owner: String!, $name: String!, $number: Int!) {
repository(owner: $owner, name: $name) {
issueOrPullRequest(number: $number) {
__typename
}
}
Expand Down
33 changes: 17 additions & 16 deletions lua/octo/navigation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,23 @@ function M.go_to_issue()
return
end
local owner, name = utils.split_repo(repo)
local query = graphql("issue_kind_query", owner, name, number)
gh.run {
args = { "api", "graphql", "-f", string.format("query=%s", query) },
cb = function(output, stderr)
if stderr and not utils.is_blank(stderr) then
vim.api.nvim_err_writeln(stderr)
elseif output then
local resp = vim.json.decode(output)
local kind = resp.data.repository.issueOrPullRequest.__typename
if kind == "Issue" then
utils.get_issue(number, repo)
elseif kind == "PullRequest" then
utils.get_pull_request(number, repo)
end
end
end,

gh.api.graphql {
query = graphql "issue_kind_query",
fields = { owner = owner, name = name, number = number },
jq = ".data.repository.issueOrPullRequest.__typename",
opts = {
cb = gh.create_callback {
failure = vim.api.nvim_err_writeln,
success = function(kind)
if kind == "Issue" then
utils.get_issue(number, repo)
elseif kind == "PullRequest" then
utils.get_pull_request(number, repo)
end
end,
},
},
}
end

Expand Down

0 comments on commit 1619301

Please sign in to comment.