Skip to content

Commit

Permalink
Merge branch 'multiselect-labels' of github.com:wd60622/octo.nvim int…
Browse files Browse the repository at this point in the history
…o multiselect-labels
  • Loading branch information
wd60622 committed Dec 16, 2024
2 parents 707f1bb + 7e07df9 commit b43fac4
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 11 deletions.
13 changes: 8 additions & 5 deletions lua/octo/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -754,12 +754,15 @@ function M.change_state(state)
obj = resp.data.updatePullRequest.pullRequest
new_state = obj.state
end
if state == new_state then
buffer.node.state = new_state
writers.write_state(bufnr, new_state:upper(), buffer.number)
writers.write_details(bufnr, obj, true)
utils.info("Issue state changed to: " .. new_state)
if state ~= new_state then
return
end
buffer.node.state = new_state

local updated_state = utils.get_displayed_state(buffer:isIssue(), new_state, obj.stateReason)
writers.write_state(bufnr, updated_state:upper(), buffer.number)
writers.write_details(bufnr, obj, true)
utils.info("Issue state changed to: " .. updated_state)
end
end,
}
Expand Down
3 changes: 3 additions & 0 deletions lua/octo/gh/graphql.lua
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@ M.update_issue_state_mutation = [[
id
number
state
stateReason
title
body
createdAt
Expand Down Expand Up @@ -1896,6 +1897,7 @@ query($endCursor: String) {
id
number
state
stateReason
title
body
createdAt
Expand Down Expand Up @@ -2076,6 +2078,7 @@ query {
__typename
createdAt
state
stateReason
number
title
body
Expand Down
3 changes: 2 additions & 1 deletion lua/octo/model/octo-buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ function OctoBuffer:render_issue()
writers.write_details(self.bufnr, self.node)

-- write issue/pr status
writers.write_state(self.bufnr, self.node.state:upper(), self.number)
local state = utils.get_displayed_state(self.kind == "issue", self.node.state, self.node.stateReason)
writers.write_state(self.bufnr, state:upper(), self.number)

-- write body
writers.write_body(self.bufnr, self.node)
Expand Down
10 changes: 8 additions & 2 deletions lua/octo/pickers/fzf-lua/previewers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ M.issue = function(formatted_issues)
elseif entry.kind == "pull_request" then
obj = result.data.repository.pullRequest
end

local state = utils.get_displayed_state(entry.kind == "issue", obj.state, obj.stateReason)

writers.write_title(tmpbuf, obj.title, 1)
writers.write_details(tmpbuf, obj)
writers.write_body(tmpbuf, obj)
writers.write_state(tmpbuf, obj.state:upper(), number)
writers.write_state(tmpbuf, state:upper(), number)
local reactions_line = vim.api.nvim_buf_line_count(tmpbuf) - 1
writers.write_block(tmpbuf, { "", "" }, reactions_line)
writers.write_reactions(tmpbuf, obj.reactionGroups, reactions_line)
Expand Down Expand Up @@ -139,10 +142,13 @@ M.search = function()
elseif kind == "pull_request" then
obj = result.data.repository.pullRequest
end

local state = utils.get_displayed_state(kind == "issue", obj.state, obj.stateReason)

writers.write_title(tmpbuf, obj.title, 1)
writers.write_details(tmpbuf, obj)
writers.write_body(tmpbuf, obj)
writers.write_state(tmpbuf, obj.state:upper(), number)
writers.write_state(tmpbuf, state:upper(), number)
local reactions_line = vim.api.nvim_buf_line_count(tmpbuf) - 1
writers.write_block(tmpbuf, { "", "" }, reactions_line)
writers.write_reactions(tmpbuf, obj.reactionGroups, reactions_line)
Expand Down
4 changes: 3 additions & 1 deletion lua/octo/pickers/telescope/previewers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ local issue = defaulter(function(opts)
obj = result.data.repository.pullRequest
end

local state = utils.get_displayed_state(entry.kind == "issue", obj.state, obj.stateReason)

writers.write_title(bufnr, obj.title, 1)
writers.write_details(bufnr, obj)
writers.write_body(bufnr, obj)
writers.write_state(bufnr, obj.state:upper(), number)
writers.write_state(bufnr, state:upper(), number)
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)
Expand Down
2 changes: 2 additions & 0 deletions lua/octo/ui/colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ local function get_hl_links()

StateOpen = "OctoGreen",
StateClosed = "OctoRed",
StateCompleted = "OctoPurple",
StateNotPlanned = "OctoGrey",
StateMerged = "OctoPurple",
StatePending = "OctoYellow",
StateApproved = "OctoGreen",
Expand Down
5 changes: 3 additions & 2 deletions lua/octo/ui/writers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function M.write_state(bufnr, state, number)
-- title virtual text
local title_vt = {
{ tostring(number), "OctoIssueId" },
{ string.format(" [%s] ", state), utils.state_hl_map[state] },
{ string.format(" [%s] ", state:gsub("_", " ")), utils.state_hl_map[state] },
}

-- PR virtual text
Expand Down Expand Up @@ -1222,9 +1222,10 @@ function M.write_issue_summary(bufnr, issue, opts)
})

-- issue body
local state = utils.get_displayed_state(issue.__typename == "Issue", issue.state, issue.stateReason)
table.insert(chunks, {
{ " " },
{ "[" .. issue.state .. "] ", utils.state_hl_map[issue.state] },
{ "[" .. state:gsub("_", " ") .. "] ", utils.state_hl_map[state] },
{ issue.title .. " ", "OctoDetailsLabel" },
{ "#" .. issue.number .. " ", "OctoDetailsValue" },
})
Expand Down
15 changes: 15 additions & 0 deletions lua/octo/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ M.state_msg_map = {
M.state_hl_map = {
MERGED = "OctoStateMerged",
CLOSED = "OctoStateClosed",
COMPLETED = "OctoStateCompleted",
NOT_PLANNED = "OctoStateNotPlanned",
OPEN = "OctoStateOpen",
APPROVED = "OctoStateApproved",
CHANGES_REQUESTED = "OctoStateChangesRequested",
Expand Down Expand Up @@ -1525,4 +1527,17 @@ function M.convert_vim_mapping_to_fzf(vim_mapping)
return string.lower(fzf_mapping)
end

--- Logic to determine the state displayed for issue or PR
---@param isIssue boolean
---@param state string
---@param stateReason string | nil
---@return string
function M.get_displayed_state(isIssue, state, stateReason)
if isIssue and state == "CLOSED" then
return stateReason or state
end

return state
end

return M

0 comments on commit b43fac4

Please sign in to comment.