Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor discussion query #894

Merged
merged 3 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lua/octo/gh/graphql.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1076,9 +1076,9 @@ query(
]] .. fragments.discussion_info

M.discussion_query = [[
query($endCursor: String) {
repository(owner: "%s", name: "%s") {
discussion(number: %d) {
query($owner: String!, $name: String!, $number: Int!, $endCursor: String) {
repository(owner: $owner, name: $name) {
discussion(number: $number) {
...DiscussionDetailsFragment
labels(first: 20) {
...LabelConnectionFragment
Expand Down
50 changes: 25 additions & 25 deletions lua/octo/pickers/telescope/previewers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@ local discussion = defaulter(function(opts)

local number = entry.value
local owner, name = utils.split_repo(entry.repo)
local query = graphql("discussion_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 and vim.api.nvim_buf_is_valid(bufnr) then
-- clear the buffer
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {})

local result = vim.json.decode(output)
local obj = result.data.repository.discussion

writers.write_title(bufnr, tostring(obj.title), 1)
writers.write_discussion_details(bufnr, obj)
writers.write_body(bufnr, obj, 11)

if obj.answer ~= vim.NIL then
local line = vim.api.nvim_buf_line_count(bufnr) + 1
writers.write_discussion_answer(bufnr, obj, line)
end

vim.api.nvim_buf_set_option(bufnr, "filetype", "octo")
end
end,
gh.api.graphql {
query = graphql "discussion_query",
fields = { owner = owner, name = name, number = number },
jq = ".data.repository.discussion",
opts = {
cb = gh.create_callback {
failure = vim.api.nvim_err_writeln,
success = function(output)
-- clear the buffer
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {})

local obj = vim.json.decode(output)
writers.write_title(bufnr, tostring(obj.title), 1)
writers.write_discussion_details(bufnr, obj)
writers.write_body(bufnr, obj, 11)

if obj.answer ~= vim.NIL then
local line = vim.api.nvim_buf_line_count(bufnr) + 1
writers.write_discussion_answer(bufnr, obj, line)
end

vim.api.nvim_buf_set_option(bufnr, "filetype", "octo")
end,
},
},
}
end,
}
Expand Down
Loading