Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ The forge dialog is a composer, not a push button:
- **Comment**, **Approve** or **Request changes** — and an approval needs nothing attached, since a verdict stands on its own. Approve and Request changes are disabled on your own pull request, which the forge refuses anyway
- everything goes as **one review**: one notification for the author, a summary that has somewhere to live, and no half-posted review if something fails

A comment on a line the pull request does not touch is caught before anything is sent, because the whole review is a single request and one unpostable line would reject all of it. Findings already sent are marked *already on the pull request* and left unselected.
A comment on a line the pull request does not touch is caught before anything is sent, because the whole review is a single request and one unpostable line would reject all of it. Findings already sent are marked *already on the pull request* and left unselected. A finding that has been sent once is not sent again, however it has been reworded since, because the forge cannot update the comment already there — but a new finding on a line that already carries someone's comment does go out, since the line says nothing about which finding is on it.

Existing inline comments can be pulled into the viewer from the same dialog.

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@diffity/api",
"version": "0.10.35",
"version": "0.10.36",
"private": true,
"type": "module",
"main": "./dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@naturalcycles/diffity",
"version": "0.10.35",
"version": "0.10.36",
"description": "Agent-agnostic, GitHub-style diff viewer and code review tool with a live agent loop",
"type": "module",
"bin": {
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/inbox/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { spawn, execFile } from 'node:child_process';
import { promisify } from 'node:util';
import type { LiveRequest } from '@diffity/api';
import { createReview, fetchPrContext, type PrContext, type PrSnapshot } from '@diffity/github';
import { createReview, fetchPrContext, getViewerLogin, type PrContext, type PrSnapshot } from '@diffity/github';
import { createWriteStream, mkdirSync, readFileSync, rmSync, writeFileSync, type WriteStream } from 'node:fs';
import { dirname, join } from 'node:path';
import { logsDir, type ExportOpts, type MarkPostedOpts, type PrepareDeps, type RunAgentOpts, type ServerHandle } from './prepare.js';
Expand Down Expand Up @@ -59,7 +59,9 @@ export function realPrepareDeps(nodePath: string, entry: string, dataDirFor: (wo
prContext: (snapshot, worktree) => writePrContext(snapshot, dataDirFor(worktree), log),
// In this process, with the reviewer's own credentials: posting the alert findings is the
// daemon's own act, after the agent has finished, and never something the agent can reach.
postReview: opts => createReview(opts.owner, opts.repo, opts.prNumber, opts.headSha, opts.submission),
postReview: async opts => createReview(opts.owner, opts.repo, opts.prNumber, opts.headSha, opts.submission, {
viewerLogin: await getViewerLogin(),
}),
markPosted: opts => markPosted(nodePath, entry, opts, dataDirFor(opts.worktree)),
exportBundle: opts => exportBundle(nodePath, entry, opts, dataDirFor(opts.worktree)),
log,
Expand Down
14 changes: 12 additions & 2 deletions packages/cli/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import {
prCommits as githubPrCommits,
prBaseRef as githubPrBaseRef,
getCompareDiff as githubCompareDiff,
getViewerLogin,
type CreateReviewOptions,
type GitHubRemote,
} from '@diffity/github';
Expand All @@ -83,7 +84,7 @@ import { computeDiffFingerprint } from './fingerprint.js';
import { parseDiffStatFiles } from './diff-stat.js';
import { parseDiffStatSummary } from './diff-stat.js';
import { anyReviewInProgress, getReviewRun } from './review-run.js';
import { createThread, addReply, getThreadsForSession, markThreadsSubmitted, setThreadForgeComment, updateThreadStatus } from './threads.js';
import { createThread, addReply, getThreadsForSession, markThreadsSubmitted, setThreadForgeComment, threadsOnTheForge, updateThreadStatus } from './threads.js';
import { existingThreadFor } from './github-pull.js';
import { threadsResolvedRemotely } from './github-resolution.js';
import { noteViewerSeen, markViewerGone, viewerSnapshot, viewerIsPresent, viewerHasGone, awakeMs, VIEWER_POLL_MS } from './viewers.js';
Expand Down Expand Up @@ -831,7 +832,16 @@ export function startServer(options: ServerOptions): Promise<ServerResult> {
details.prNumber,
details.headSha,
submission,
target,
{
...target,
// Which findings are already on the pull request is a question about these
// findings, not about the lines they sit on — a line collects comments over
// rounds, and the ones on it may be nothing to do with what is being sent now.
postedThreadIds: threadsOnTheForge(
submission.comments.map(comment => comment.threadId).filter((id): id is string => !!id),
),
viewerLogin: await getViewerLogin(),
},
);
// Only the reader's own submit counts as the pull request being handled; an agent
// posting through this route is not the reviewer having reviewed it. The mark is
Expand Down
20 changes: 20 additions & 0 deletions packages/cli/src/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,26 @@ export function markThreadsSubmitted(
}
}

/**
* Of these findings, the ones that are on the forge already — sent from here, or pulled from
* there and so known by the comment they exist as. What sits on a line cannot say which finding
* put it there, so this record is what tells a resend from a new remark in the same place.
*/
export function threadsOnTheForge(ids: string[]): Set<string> {
if (ids.length === 0) {
return new Set();
}

const rows = queryAll<{ id: string }>(
`SELECT id FROM comment_threads
WHERE (submitted_at IS NOT NULL OR github_comment_id IS NOT NULL)
AND id IN (${ids.map(() => '?').join(', ')})`,
...ids,
);

return new Set(rows.map(row => row.id));
}

/** Records which forge comment a thread exists as, once that is learned. */
export function setThreadForgeComment(threadId: string, githubCommentId: number): void {
getDb()
Expand Down
Loading
Loading