Start review from code-comment on revision diff

Co-authored-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
Brandon Oxendine
2026-04-30 16:49:41 +02:00
committed by Rūdolfs Ošiņš
co-authored by Rūdolfs Ošiņš
parent e0aafa7de2
commit ec49ecbd36
7 changed files with 132 additions and 21 deletions
+18 -1
View File
@@ -2,6 +2,7 @@
import type { PatchStatus } from "@app/views/repo/router";
import type { Patch } from "@bindings/cob/patch/Patch";
import { draftReviewStorage } from "@app/lib/draftReviewStorage";
import { cachedDiffStats } from "@app/lib/invoke";
import { push } from "@app/lib/router";
import {
@@ -26,6 +27,10 @@
}
const { focussed, patch, rid, status }: Props = $props();
const hasDraftReview = $derived(
patch.revisionIds.some(id => draftReviewStorage.hasForRevision(id)),
);
</script>
<style>
@@ -103,6 +108,18 @@
</div>
<div class="global-flex" style:margin-left="auto">
{#if hasDraftReview}
<div
class="txt-body-m-regular"
style:white-space="nowrap"
style:border="1px solid var(--color-border-subtle)"
style:border-radius="var(--border-radius-sm)"
style:padding="0.125rem 0.5rem"
style:color="var(--color-text-primary)">
Review in progress
</div>
{/if}
{#await cachedDiffStats(rid, patch.base, patch.head) then stats}
<DiffStatBadge {stats} />
{/await}
@@ -120,7 +137,7 @@
style:padding="0 0.5rem"
style:color="var(--color-text-tertiary)">
<Icon name="revision" />
{patch.revisionCount}
{patch.revisionIds.length}
</div>
</div>
</div>
-2
View File
@@ -148,7 +148,6 @@
if ("draft" in review) {
draftReviewStorage.addComment(review.id, {
body,
embeds,
location: location!,
});
} else {
@@ -178,7 +177,6 @@
if ("draft" in review) {
draftReviewStorage.updateComment(review.id, commentId, {
body,
embeds,
});
} else {
await invoke("edit_patch", {
+84 -2
View File
@@ -1,14 +1,17 @@
<script lang="ts">
import type { CodeComments } from "@app/components/Diff.svelte";
import type { Author } from "@bindings/cob/Author";
import type { Revision } from "@bindings/cob/patch/Revision";
import type { CodeLocation } from "@bindings/cob/thread/CodeLocation";
import type { Embed } from "@bindings/cob/thread/Embed";
import type { Thread } from "@bindings/cob/thread/Thread";
import type { Config } from "@bindings/config/Config";
import { draftReviewStorage } from "@app/lib/draftReviewStorage";
import { nodeRunning } from "@app/lib/events";
import { invoke } from "@app/lib/invoke";
import * as roles from "@app/lib/roles";
import { publicKeyFromDid } from "@app/lib/utils";
import { didFromPublicKey, publicKeyFromDid } from "@app/lib/utils";
import { announce } from "@app/components/AnnounceSwitch.svelte";
import Changes from "@app/components/Changes.svelte";
@@ -35,6 +38,85 @@
hideDescription = false,
}: Props = $props();
const currentUserAuthor: Author = $derived({
did: didFromPublicKey(config.publicKey),
alias: config.alias ?? undefined,
});
const draftReview = $derived(
draftReviewStorage.getForRevision(revision.id, currentUserAuthor),
);
const hasPublishedReview = $derived(
revision.reviews?.some(r => r.author.did === currentUserAuthor.did) ??
false,
);
const codeCommentThreads: Thread<CodeLocation>[] = $derived(
draftReview
? (draftReview.comments
.filter(c => c.location && !c.replyTo)
.map(root => ({
root,
replies: draftReview.comments.filter(c => c.replyTo === root.id),
})) as Thread<CodeLocation>[])
: [],
);
async function createCodeComment(
body: string,
_embeds: Embed[],
_replyTo?: string,
location?: CodeLocation,
) {
if (!location) return;
try {
let draftId = draftReview?.id;
if (!draftId) {
draftId = draftReviewStorage.create(rid, revision.id);
}
draftReviewStorage.addComment(draftId, { body, location });
} catch (error) {
console.error("Creating code comment failed", error);
} finally {
await loadPatch();
}
}
async function editCodeComment(
commentId: string,
body: string,
_embeds: Embed[],
) {
if (!draftReview) return;
draftReviewStorage.updateComment(draftReview.id, commentId, {
body,
});
await loadPatch();
}
async function deleteCodeComment(commentId: string) {
if (!draftReview) return;
draftReviewStorage.deleteComment(draftReview.id, commentId);
await loadPatch();
}
const codeComments: CodeComments | undefined = $derived(
hasPublishedReview
? undefined
: {
config,
createComment: createCodeComment,
editComment: editCodeComment,
deleteComment: deleteCodeComment,
repoDelegates,
rid,
threads: codeCommentThreads,
canReply: true,
disableAttachments: "Publish your review to attach files",
},
);
const commentThreads = $derived(
((revision.discussion &&
revision.discussion
@@ -206,4 +288,4 @@
{repoDelegates}
{rid} />
<Changes {rid} {patchId} {revision} />
<Changes {rid} {patchId} {revision} {codeComments} />