From 9aa2b49f15d757da0b109fd936b4de12c969e898 Mon Sep 17 00:00:00 2001 From: Will Dean <57733339+wd60622@users.noreply.github.com> Date: Mon, 16 Dec 2024 10:17:18 +0100 Subject: [PATCH] distinguish completed from not planned (#716) * bring in stateReason for issue * add some colors for each state add some colors for each state * display for previewer and buffer * same logic for the popup summary * same logic for "Octo issue close" * same logic for fzf picker * refactor to put logic in one location --- lua/octo/commands.lua | 13 ++++++++----- lua/octo/gh/graphql.lua | 3 +++ lua/octo/model/octo-buffer.lua | 3 ++- lua/octo/pickers/fzf-lua/previewers.lua | 10 ++++++++-- lua/octo/pickers/telescope/previewers.lua | 4 +++- lua/octo/ui/colors.lua | 2 ++ lua/octo/ui/writers.lua | 5 +++-- lua/octo/utils.lua | 15 +++++++++++++++ 8 files changed, 44 insertions(+), 11 deletions(-) diff --git a/lua/octo/commands.lua b/lua/octo/commands.lua index d516718f..4741cc60 100644 --- a/lua/octo/commands.lua +++ b/lua/octo/commands.lua @@ -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, } diff --git a/lua/octo/gh/graphql.lua b/lua/octo/gh/graphql.lua index 377225f4..06f418a8 100644 --- a/lua/octo/gh/graphql.lua +++ b/lua/octo/gh/graphql.lua @@ -957,6 +957,7 @@ M.update_issue_state_mutation = [[ id number state + stateReason title body createdAt @@ -1896,6 +1897,7 @@ query($endCursor: String) { id number state + stateReason title body createdAt @@ -2076,6 +2078,7 @@ query { __typename createdAt state + stateReason number title body diff --git a/lua/octo/model/octo-buffer.lua b/lua/octo/model/octo-buffer.lua index c8c3f246..189f1d5e 100644 --- a/lua/octo/model/octo-buffer.lua +++ b/lua/octo/model/octo-buffer.lua @@ -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) diff --git a/lua/octo/pickers/fzf-lua/previewers.lua b/lua/octo/pickers/fzf-lua/previewers.lua index c30d2636..790f7a8a 100644 --- a/lua/octo/pickers/fzf-lua/previewers.lua +++ b/lua/octo/pickers/fzf-lua/previewers.lua @@ -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) @@ -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) diff --git a/lua/octo/pickers/telescope/previewers.lua b/lua/octo/pickers/telescope/previewers.lua index 1da79a8d..1bc0a1c2 100644 --- a/lua/octo/pickers/telescope/previewers.lua +++ b/lua/octo/pickers/telescope/previewers.lua @@ -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) diff --git a/lua/octo/ui/colors.lua b/lua/octo/ui/colors.lua index 20b557ad..3196caf4 100644 --- a/lua/octo/ui/colors.lua +++ b/lua/octo/ui/colors.lua @@ -115,6 +115,8 @@ local function get_hl_links() StateOpen = "OctoGreen", StateClosed = "OctoRed", + StateCompleted = "OctoPurple", + StateNotPlanned = "OctoGrey", StateMerged = "OctoPurple", StatePending = "OctoYellow", StateApproved = "OctoGreen", diff --git a/lua/octo/ui/writers.lua b/lua/octo/ui/writers.lua index 844a3d3b..a78d964c 100644 --- a/lua/octo/ui/writers.lua +++ b/lua/octo/ui/writers.lua @@ -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 @@ -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" }, }) diff --git a/lua/octo/utils.lua b/lua/octo/utils.lua index 19b0bf10..778b52d9 100644 --- a/lua/octo/utils.lua +++ b/lua/octo/utils.lua @@ -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", @@ -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