-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add restore diagnostics command for previous code reviews #19
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| local diagnostics = require("coderabbit.diagnostics") | ||
| local review = require("coderabbit.review") | ||
| local storage = require("coderabbit.storage") | ||
| local h = require("tests.helpers") | ||
| local test, eq = h.test, h.eq | ||
|
|
||
| local test_dir = vim.fn.tempname() .. "/coderabbit_restore_test" | ||
| storage._set_base_dir(test_dir) | ||
|
|
||
| local function flush() | ||
| vim.wait(10, function() | ||
| return false | ||
| end) | ||
| end | ||
|
|
||
| local finding_tmpdirs = {} | ||
|
|
||
| local function cleanup() | ||
| for _, dir in ipairs(finding_tmpdirs) do | ||
| vim.fn.delete(dir, "rf") | ||
| end | ||
| finding_tmpdirs = {} | ||
| vim.fn.delete(test_dir, "rf") | ||
| diagnostics.clear() | ||
| end | ||
|
|
||
| local function make_findings(n) | ||
| local tmpdir = vim.fn.tempname() | ||
| vim.fn.mkdir(tmpdir, "p") | ||
| table.insert(finding_tmpdirs, tmpdir) | ||
| local findings = {} | ||
| for i = 1, n do | ||
| local filepath = tmpdir .. "/file" .. i .. ".ts" | ||
| vim.fn.writefile({ "// mock" }, filepath) | ||
| table.insert(findings, h.finding(filepath, i * 10, h.W, "finding " .. i)) | ||
| end | ||
| return findings | ||
| end | ||
|
|
||
| -- ────────────────────────────────────────────────────────── | ||
| -- Tests | ||
| -- ────────────────────────────────────────────────────────── | ||
|
|
||
| test("restore: warns when no saved reviews exist", function() | ||
| cleanup() | ||
| -- Should not error, just warn | ||
| review.restore(nil) | ||
| end) | ||
|
|
||
| test("restore: warns when review ID not found", function() | ||
| cleanup() | ||
| storage.save(make_findings(1), h.context()) | ||
| review.restore(999) | ||
| end) | ||
|
|
||
| test("restore: restores diagnostics from a specific review", function() | ||
| cleanup() | ||
| local findings = make_findings(2) | ||
| storage.save(findings, h.context()) | ||
|
|
||
| review.restore(1) | ||
| flush() | ||
|
|
||
| for _, finding in ipairs(findings) do | ||
| local bufnr = vim.fn.bufnr(finding.filepath) | ||
| local got = vim.diagnostic.get(bufnr, { namespace = diagnostics.ns }) | ||
| eq(#got, 1) | ||
| eq(got[1].message, finding.diagnostic.message) | ||
| end | ||
| end) | ||
|
|
||
| test("restore: defaults to most recent review when no ID given", function() | ||
| cleanup() | ||
| local old_findings = make_findings(1) | ||
| storage.save(old_findings, h.context("old-branch")) | ||
| local new_findings = make_findings(2) | ||
| storage.save(new_findings, h.context("new-branch")) | ||
|
|
||
| review.restore(nil) | ||
| flush() | ||
|
|
||
| -- Should have diagnostics from the second review (2 findings) | ||
| local total = 0 | ||
| for _, d in ipairs(vim.diagnostic.get()) do | ||
| if d.source == "coderabbit" then | ||
| total = total + 1 | ||
| end | ||
| end | ||
| eq(total, 2) | ||
| end) | ||
|
|
||
| test("restore: clears previous diagnostics before applying", function() | ||
| cleanup() | ||
| local first = make_findings(3) | ||
| storage.save(first, h.context()) | ||
| local second = make_findings(1) | ||
| storage.save(second, h.context()) | ||
|
|
||
| review.restore(1) -- 3 findings | ||
| flush() | ||
| review.restore(2) -- 1 finding — should replace, not accumulate | ||
| flush() | ||
|
|
||
| local total = 0 | ||
| for _, d in ipairs(vim.diagnostic.get()) do | ||
| if d.source == "coderabbit" then | ||
| total = total + 1 | ||
| end | ||
| end | ||
| eq(total, 1) | ||
| end) | ||
|
|
||
| cleanup() | ||
| h.summary() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.