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

Add discussion list support #643

Merged
merged 27 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7c2803c
initial support
wd60622 Oct 16, 2024
6a3133d
consolidate changes
wd60622 Oct 21, 2024
5f239b8
add a callback
wd60622 Oct 21, 2024
a8e91b8
add copy URL command
wd60622 Oct 21, 2024
b63e3a9
add crude previewer
wd60622 Oct 21, 2024
38b1d8f
add detaios
wd60622 Oct 21, 2024
e4b5a76
add default sorting by creation
wd60622 Oct 21, 2024
778ccb7
add a body to the previewer
wd60622 Oct 21, 2024
88d9fe8
add answer to discussion query
wd60622 Oct 21, 2024
e7ca9c5
only get open discussions
wd60622 Oct 28, 2024
8e9758b
add answer to query
wd60622 Oct 28, 2024
5687081
check if viewer was author
wd60622 Oct 28, 2024
f594b7d
move logic into writer file
wd60622 Oct 28, 2024
b8dbd03
get upvoters
wd60622 Oct 28, 2024
fd92122
write the answer
wd60622 Oct 28, 2024
de0ac90
Merge branch 'master' into discussion-list
wd60622 Oct 29, 2024
19378bb
Merge branch 'master' of github.com:pwntester/octo.nvim into discussi…
wd60622 Oct 30, 2024
7210a39
Merge branch 'master' into discussion-list
wd60622 Nov 5, 2024
e0ddad2
Merge branch 'master' into discussion-list
wd60622 Nov 6, 2024
ffd768d
remove url register
wd60622 Nov 10, 2024
be94a4e
switch to open in browser
wd60622 Nov 10, 2024
cfe3ce4
Merge branch 'discussion-list' of github.com:wd60622/octo.nvim into d…
wd60622 Nov 10, 2024
c98ce16
Remove draft work
wd60622 Nov 10, 2024
dad0b21
Merge branch 'master' into discussion-list
wd60622 Nov 10, 2024
8ee348a
run pre-commit
wd60622 Nov 10, 2024
627d935
Merge branch 'master' of github.com:pwntester/octo.nvim into discussi…
wd60622 Nov 14, 2024
59698f3
Merge branch 'master' into discussion-list
pwntester Nov 28, 2024
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: 6 additions & 0 deletions lua/octo/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ function M.setup()
search = function(...)
M.search(...)
end,
discussion = {
list = function(repo, ...)
local opts = M.process_varargs(repo, ...)
picker.discussions(opts)
end,
},
issue = {
create = function(repo)
M.create_issue(repo)
Expand Down
10 changes: 10 additions & 0 deletions lua/octo/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ local M = {}
---@class OctoConfigReviews
---@field auto_show_threads boolean

---@class OctoConfigDiscussions
---@field order_by OctoConfigOrderBy

---@class OctoConfigPR
---@field order_by OctoConfigOrderBy
---@field always_select_remote_on_create boolean
Expand Down Expand Up @@ -83,6 +86,7 @@ local M = {}
---@field colors OctoConfigColors
---@field mappings { [OctoMappingsWindow]: OctoMappingsList}
---@field mappings_disable_default boolean
---@field discussions OctoConfigDiscussions

--- Returns the default octo config values
---@return OctoConfig
Expand Down Expand Up @@ -134,6 +138,12 @@ function M.get_default_values()
direction = "DESC",
},
},
discussions = {
order_by = {
field = "CREATED_AT",
direction = "DESC",
},
},
reviews = {
auto_show_threads = true,
},
Expand Down
105 changes: 105 additions & 0 deletions lua/octo/gh/graphql.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2174,6 +2174,111 @@ query {
}
]]

M.discussions_query = [[
query($endCursor: String) {
repository(owner: "%s", name: "%s") {
discussions(first: 100, after: $endCursor, states: OPEN, orderBy: {field: %s, direction: %s}) {
nodes {
__typename
number
title
url
closed
isAnswered
answer {
author { login }
body
}
repository { nameWithOwner }
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
]]

M.discussion_query = [[
query($endCursor: String) {
repository(owner: "%s", name: "%s") {
discussion(number: %d) {
id
category {
name
emoji
}
number
closed
isAnswered
answer {
author { login }
body
createdAt
viewerDidAuthor
}
title
body
createdAt
closedAt
updatedAt
url
repository { nameWithOwner }
author { login }
labels(first: 20) {
nodes {
color
name
}
}
upvoteCount
viewerHasUpvoted
reactionGroups {
content
viewerHasReacted
users {
totalCount
}
}
comments(first: 100, after: $endCursor) {
totalCount
nodes {
id
body
createdAt
lastEditedAt
reactionGroups {
content
viewerHasReacted
reactors {
totalCount
}
}
author {
login
}
viewerDidAuthor
viewerCanUpdate
viewerCanDelete
replies(first: 10) {
totalCount
nodes {
body
author { login }
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
}
]]

-- https://docs.github.com/en/graphql/reference/objects#project
M.projects_query = [[
query {
Expand Down
3 changes: 3 additions & 0 deletions lua/octo/navigation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ local gh = require "octo.gh"
local graphql = require "octo.gh.graphql"
local utils = require "octo.utils"

local vim = vim

local M = {}

--[[
Expand Down Expand Up @@ -29,6 +31,7 @@ function M.open_in_browser(kind, repo, number)
utils.error "Cannot find repo remote host"
return
end

if not kind and not repo then
local bufnr = vim.api.nvim_get_current_buf()
local buffer = octo_buffers[bufnr]
Expand Down
7 changes: 7 additions & 0 deletions lua/octo/pickers/fzf-lua/provider.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
local utils = require "octo.utils"

local M = {}

function M.not_implemented()
utils.error "Not implemented yet"
end

M.picker = {
actions = require "octo.pickers.fzf-lua.pickers.actions",
assigned_labels = require "octo.pickers.fzf-lua.pickers.assigned_labels",
assignees = require "octo.pickers.fzf-lua.pickers.assignees",
changed_files = require "octo.pickers.fzf-lua.pickers.changed_files",
discussions = M.not_implemented,
commits = require "octo.pickers.fzf-lua.pickers.commits",
gists = require "octo.pickers.fzf-lua.pickers.gists",
issue_templates = require "octo.pickers.fzf-lua.pickers.issue_templates",
Expand Down
90 changes: 85 additions & 5 deletions lua/octo/pickers/telescope/entry_maker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ local entry_display = require "telescope.pickers.entry_display"
local bubbles = require "octo.ui.bubbles"
local utils = require "octo.utils"

local vim = vim

local M = {}

--- @class EntryObject
--- @field state string
--- @field isDraft boolean
--- @field stateReason string
--- @field isAnswered boolean
--- @field closed boolean

--- @class Entry
--- @field kind string
Expand All @@ -31,6 +35,11 @@ local icons = {
merged = { " ", "OctoPurple" },
closed = { " ", "OctoRed" },
},
discussion = {
open = { " ", "OctoGrey" },
answered = { " ", "OctoGreen" },
closed = { " ", "OctoRed" },
},
unknown = { " " },
}

Expand All @@ -39,11 +48,11 @@ local icons = {
---@return Icon: The icon for the entry
local function get_icon(entry)
local kind = entry.kind
local state = entry.obj.state
local isDraft = entry.obj.isDraft
local stateReason = entry.obj.stateReason

if kind == "issue" then
local state = entry.obj.state
local stateReason = entry.obj.stateReason

if state == "OPEN" then
return icons.issue.open
elseif state == "CLOSED" and stateReason == "NOT_PLANNED" then
Expand All @@ -52,6 +61,9 @@ local function get_icon(entry)
return icons.issue.closed
end
elseif kind == "pull_request" then
local state = entry.obj.state
local isDraft = entry.obj.isDraft

if state == "MERGED" then
return icons.pull_request.merged
elseif state == "CLOSED" then
Expand All @@ -61,11 +73,66 @@ local function get_icon(entry)
elseif state == "OPEN" then
return icons.pull_request.open
end
elseif kind == "discussion" then
local closed = entry.obj.closed
local isAnswered = entry.obj.isAnswered

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
end

return icons.unknown
end

function M.gen_from_discussions(max_number)
local make_display = function(entry)
if not entry then
return nil
end

local columns = {
{ entry.value, "TelescopeResultsNumber" },
get_icon(entry),
{ entry.obj.title },
}
local layout = {
separator = " ",
items = {
{ width = max_number },
{ width = 2 },
{ remaining = true },
},
}
local displayer = entry_display.create(layout)

return displayer(columns)
end

return function(obj)
if not obj or vim.tbl_isempty(obj) then
return nil
end

local kind = "discussion"
local filename = utils.get_discussion_uri(obj.repository.nameWithOwner, obj.number)

return {
filename = filename,
kind = kind,
value = obj.number,
ordinal = obj.number .. " " .. obj.title,
display = make_display,
obj = obj,
repo = obj.repository.nameWithOwner,
}
end
end

function M.gen_from_issue(max_number, print_repo)
local make_display = function(entry)
if not entry then
Expand Down Expand Up @@ -112,13 +179,26 @@ function M.gen_from_issue(max_number, print_repo)
if not obj or vim.tbl_isempty(obj) then
return nil
end
local kind = obj.__typename == "Issue" and "issue" or "pull_request"

local kind
local typename = obj.__typename
if typename == "Issue" then
kind = "issue"
elseif typename == "PullRequest" then
kind = "pull_request"
else
kind = "discussion"
end

local filename
if kind == "issue" then
filename = utils.get_issue_uri(obj.repository.nameWithOwner, obj.number)
else
elseif kind == "pull_request" then
filename = utils.get_pull_request_uri(obj.repository.nameWithOwner, obj.number)
else
filename = utils.get_discussion_uri(obj.respository.nameWithOwner, obj.number)
end

return {
filename = filename,
kind = kind,
Expand Down
Loading
Loading