Skip to content

Commit

Permalink
add detaios
Browse files Browse the repository at this point in the history
  • Loading branch information
wd60622 committed Oct 21, 2024
1 parent b63e3a9 commit 38b1d8f
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 6 deletions.
15 changes: 15 additions & 0 deletions lua/octo/gh/graphql.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2196,11 +2196,18 @@ query($endCursor: String) {
repository(owner: "%s", name: "%s") {
discussion(number: %d) {
id
category {
name
emoji
}
number
closed
isAnswered
title
body
createdAt
closedAt
updatedAt
url
repository { nameWithOwner }
author { login }
Expand All @@ -2210,7 +2217,15 @@ query($endCursor: String) {
name
}
}
reactionGroups {
content
viewerHasReacted
users {
totalCount
}
}
comments(first: 100, after: $endCursor) {
totalCount
nodes {
id
body
Expand Down
6 changes: 3 additions & 3 deletions lua/octo/pickers/telescope/entry_maker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ local function get_icon(entry)
local closed = entry.obj.closed
local isAnswered = entry.obj.isAnswered

if not closed then
return icons.discussion.open
elseif isAnswered then
if isAnswered ~= vim.NIL and isAnswered then
return icons.discussion.answered
elseif not closed then
return icons.discussion.open
else
return icons.discussion.closed
end
Expand Down
11 changes: 9 additions & 2 deletions lua/octo/pickers/telescope/previewers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ local discussion = defaulter(function(opts)
local obj = result.data.repository.discussion

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

-- writers.write_details(bufnr, obj)
writers.write_discussion_details(bufnr, obj)
-- writers.write_body(bufnr, obj)
--
-- local reactions_line = vim.api.nvim_buf_line_count(bufnr) - 1
-- writers.write_block(bufnr, { "", "" }, reactions_line)
-- writers.write_reactions(bufnr, obj.reactionGroups, reactions_line)
--
vim.api.nvim_buf_set_option(bufnr, "filetype", "octo")
end
end,
Expand Down Expand Up @@ -77,6 +83,7 @@ local issue = defaulter(function(opts)
elseif entry.kind == "pull_request" then
obj = result.data.repository.pullRequest
end

writers.write_title(bufnr, obj.title, 1)
writers.write_details(bufnr, obj)
writers.write_body(bufnr, obj)
Expand Down
61 changes: 60 additions & 1 deletion lua/octo/ui/writers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,66 @@ local function add_details_line(details, label, value, kind)
end
end

function M.write_discussion_details(bufnr, discussion)
local details = {}

-- print("This is the discussion")
-- vim.print(discussion)

-- add_details_line(details, "Number", discussion.number)
--
local author_vt = { { "Created by: ", "OctoDetailsLabel" } }
local author_bubble = bubbles.make_user_bubble(discussion.author.login, discussion.viewerDidAuthor)
vim.list_extend(author_vt, author_bubble)
table.insert(details, author_vt)

local category_vt = {
{ "Category: ", "OctoDetailsLabel" },
{ discussion.category.name, "OctoDetailsValue" },
}
table.insert(details, category_vt)

add_details_line(details, "Created at", discussion.createdAt, "date")
add_details_line(details, "Updated at", discussion.updatedAt, "date")

local labels_vt = { { "Labels: ", "OctoDetailsLabel" } }

if #discussion.labels.nodes > 0 then
for _, label in ipairs(discussion.labels.nodes) do
local label_bubble = bubbles.make_label_bubble(label.name, label.color, { right_margin_width = 1 })
vim.list_extend(labels_vt, label_bubble)
end
else
table.insert(labels_vt, { "None yet", "OctoMissingDetails" })
end

table.insert(details, labels_vt)

-- Is answered details
local answered_vt = {
{ "Answered: ", "OctoDetailsLabel" },
}
if discussion.isAnswered ~= vim.NIL and discussion.isAnswered then
table.insert(answered_vt, { "Yes", "OctoGreen" })
else
table.insert(answered_vt, { "Not yet", "OctoMissingDetails" })
end
table.insert(details, answered_vt)

add_details_line(details, "Comments", discussion.comments.totalCount)

local line = 3
local empty_lines = {}
for _ = 1, #details + 1 do
table.insert(empty_lines, "")
end
M.write_block(bufnr, empty_lines, line)
for _, d in ipairs(details) do
M.write_virtual_text(bufnr, constants.OCTO_REPO_VT_NS, line - 1, d)
line = line + 1
end
end

function M.write_repo(bufnr, repo)
bufnr = bufnr or vim.api.nvim_get_current_buf()

Expand Down Expand Up @@ -177,7 +237,6 @@ function M.write_title(bufnr, title, line)
vim.api.nvim_buf_add_highlight(bufnr, -1, "OctoIssueTitle", 0, 0, -1)
local buffer = octo_buffers[bufnr]

vim.print(buffer)
if buffer then
buffer.titleMetadata = TitleMetadata:new {
savedBody = title,
Expand Down

0 comments on commit 38b1d8f

Please sign in to comment.