From bb4accfdad836eb7f74516d5c11b6abb60343fa3 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Sat, 21 Mar 2026 17:52:36 +0100 Subject: [PATCH] fix(detail): show correct count of unresolved discussion threads Currently in GitLab any comments that are not resolvable threads, system activity or similar events both, counted towards unresolved count in the details sidebar section as well as shown with an unresolved marker in the detail overview even though they aren't actionable. Resolve this by globally populating a `resolvable` property, which is assigned during fetching discussions. If an active thread's notes are unresolved, reflect that in the parent discussions dictionary. --- lua/codereview/mr/detail.lua | 2 +- lua/codereview/providers/github.lua | 1 + lua/codereview/providers/gitlab.lua | 14 ++++++- tests/codereview/mr/detail_spec.lua | 65 +++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 3 deletions(-) diff --git a/lua/codereview/mr/detail.lua b/lua/codereview/mr/detail.lua index 3d49a0a..2c94e20 100644 --- a/lua/codereview/mr/detail.lua +++ b/lua/codereview/mr/detail.lua @@ -180,7 +180,7 @@ local function render_thread(result, disc, width, reply_key, resolve_key, is_las -- Status dot + label: "● Unresolved" or "○ Resolved" local status_dot = "" local status_label = "" - if first_note.resolvable ~= nil or disc.resolved ~= nil then + if disc.resolvable then status_dot = resolved and "○" or "●" status_label = resolved and " Resolved" or " Unresolved" end diff --git a/lua/codereview/providers/github.lua b/lua/codereview/providers/github.lua index 4333592..103dc26 100644 --- a/lua/codereview/providers/github.lua +++ b/lua/codereview/providers/github.lua @@ -141,6 +141,7 @@ function M.normalize_graphql_threads(thread_nodes) table.insert(discussions, { id = tostring(comments[1].databaseId), node_id = thread.id, + resolvable = true, resolved = thread.isResolved or false, notes = notes, }) diff --git a/lua/codereview/providers/gitlab.lua b/lua/codereview/providers/gitlab.lua index e3df728..81c7782 100644 --- a/lua/codereview/providers/gitlab.lua +++ b/lua/codereview/providers/gitlab.lua @@ -113,10 +113,20 @@ end --- Map a GitLab discussion raw object to a normalized discussion. function M.normalize_discussion(raw) local notes = {} + local resolvable = raw.resolvable or false + local resolved = raw.resolved or true for _, n in ipairs(raw.notes or {}) do - table.insert(notes, normalize_note(n)) + local note = normalize_note(n) + table.insert(notes, note) + + if note.resolvable then + resolvable = true + if not note.resolved then + resolved = false + end + end end - return { id = raw.id, resolved = raw.resolved or false, notes = notes } + return { id = raw.id, resolved = resolved, resolvable = resolvable, notes = notes } end --- Normalize a GitLab file diff entry. diff --git a/tests/codereview/mr/detail_spec.lua b/tests/codereview/mr/detail_spec.lua index 49294ae..c0881e2 100644 --- a/tests/codereview/mr/detail_spec.lua +++ b/tests/codereview/mr/detail_spec.lua @@ -267,6 +267,7 @@ describe("mr.detail", function() local discussions = { { id = "abc", + resolvable = true, resolved = false, notes = { { @@ -283,10 +284,69 @@ describe("mr.detail", function() } local result = detail.build_activity_lines(discussions) local joined = table.concat(result.lines, "\n") + print(joined) assert.truthy(joined:find("Unresolved")) assert.truthy(joined:find("●")) end) + it("count resolved/unresolved status for resolvables", function() + local discussions = { + { + id = "abc", + resolvable = true, + resolved = false, + notes = { + { + id = 1, + body = "Bug here", + author = "alice", + created_at = "2026-02-20T10:00:00Z", + system = false, + resolvable = true, + resolved = false, + }, + }, + }, + { + id = "def", + resolvable = true, + resolved = true, + notes = { + { + id = 1, + body = "Bug here resolved", + author = "alice", + created_at = "2026-02-20T10:00:00Z", + system = false, + resolvable = true, + resolved = true, + }, + }, + }, + { + id = "ghi", + resolvable = false, + resolved = true, + notes = { + { + id = 1, + body = "not resolvable here", + author = "alice", + created_at = "2026-02-20T10:00:00Z", + system = false, + resolvable = false, + resolved = true, + }, + }, + }, + } + local result = detail.build_activity_lines(discussions) + local joined = table.concat(result.lines, "\n") + assert.truthy(joined:find("1 unresolved")) + assert.truthy(joined:find("○ Resolved")) + assert.truthy(joined:find("● Unresolved")) + end) + it("maps thread rows to discussions in row_map", function() local disc = { id = "abc", @@ -423,6 +483,8 @@ describe("mr.detail", function() local discussions = { { id = "s1", + resolvable = false, + resolved = false, notes = { { id = 1, @@ -450,6 +512,7 @@ describe("mr.detail", function() local discussions = { { id = "d1", + resolvable = true, resolved = false, notes = { { @@ -478,6 +541,7 @@ describe("mr.detail", function() local discussions = { { id = "d1", + resolvable = true, resolved = false, notes = { { @@ -507,6 +571,7 @@ describe("mr.detail", function() local discussions = { { id = "d1", + resolvable = true, resolved = false, notes = { {