mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 06:10:44 +08:00
desktop: Count every commit of a revision in the revision picker
Fixes rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5/cob/xyz.radicle.issue/47d0ce74b984d8aa0a7c671e76f2af1a6b12d3fb
This commit is contained in:
@@ -9,12 +9,10 @@
|
||||
import type { Revision } from "@bindings/cob/patch/Revision";
|
||||
import type { Config } from "@bindings/config/Config";
|
||||
import type { Stats } from "@bindings/diff/Stats";
|
||||
import type { Commit } from "@bindings/repo/Commit";
|
||||
import type { RepoInfo } from "@bindings/repo/RepoInfo";
|
||||
|
||||
import UserAvatar from "@radicle-gui/ui/components/UserAvatar.svelte";
|
||||
import countBy from "lodash/countBy";
|
||||
import mapValues from "lodash/mapValues";
|
||||
import { SvelteSet } from "svelte/reactivity";
|
||||
|
||||
import { commentSourcesOf } from "@app/lib/commentSources";
|
||||
@@ -32,11 +30,7 @@
|
||||
import { patchContributions } from "@app/lib/patchContributions";
|
||||
import type { ReviewEntry } from "@app/lib/reviewSummary";
|
||||
import { revisionTitle } from "@app/lib/revisionDescription";
|
||||
import {
|
||||
newCommitsByRevision,
|
||||
orderRevisions,
|
||||
revisionNumbers,
|
||||
} from "@app/lib/revisionList";
|
||||
import { orderRevisions, revisionNumbers } from "@app/lib/revisionList";
|
||||
import { revisionListSettings } from "@app/lib/revisionListSettings";
|
||||
import * as roles from "@app/lib/roles";
|
||||
import * as router from "@app/lib/router";
|
||||
@@ -234,7 +228,7 @@
|
||||
let commentPosition = $state({ index: -1, total: 0 });
|
||||
|
||||
let commentSourcesExpanded = $state(false);
|
||||
let commitCountsByRevisionId: Record<string, number> = $state({});
|
||||
let commitCountsByRevisionId: Record<string, number | undefined> = $state({});
|
||||
let statsByRevisionId: Record<string, Stats> = $state({});
|
||||
let columnMenuOpen = $state(false);
|
||||
let columnMenuEl: HTMLElement | undefined = $state();
|
||||
@@ -366,22 +360,26 @@
|
||||
|
||||
$effect(() => {
|
||||
const ridLocal = repo.rid;
|
||||
const ordered = orderedRevisions;
|
||||
void Promise.all(
|
||||
ordered.map(async (rev): Promise<[string, Commit[]]> => {
|
||||
try {
|
||||
const commits = await cachedListCommits(ridLocal, rev.base, rev.head);
|
||||
return [rev.id, commits];
|
||||
} catch {
|
||||
return [rev.id, []];
|
||||
}
|
||||
}),
|
||||
orderedRevisions.map(
|
||||
async (rev): Promise<[string, number | undefined]> => [
|
||||
rev.id,
|
||||
// Every commit in the revision, as the Changes view counts them. A
|
||||
// list that failed to load has no count, which is not zero.
|
||||
await cachedListCommits(ridLocal, rev.base, rev.head).then(
|
||||
commits => commits.length,
|
||||
error => {
|
||||
console.error(
|
||||
`Failed to load commits for revision ${rev.id} (${rev.base}..${rev.head})`,
|
||||
error,
|
||||
);
|
||||
return undefined;
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
).then(entries => {
|
||||
const commits = Object.fromEntries(entries);
|
||||
commitCountsByRevisionId = mapValues(
|
||||
newCommitsByRevision(ordered, id => commits[id] ?? []),
|
||||
added => added.length,
|
||||
);
|
||||
commitCountsByRevisionId = Object.fromEntries(entries);
|
||||
});
|
||||
});
|
||||
// Per-revision diff stats for the dropdown: one request each, so they are
|
||||
|
||||
@@ -23,7 +23,7 @@ async function createPatch(peer: RadiclePeer) {
|
||||
[],
|
||||
{ cwd: repoFolder },
|
||||
);
|
||||
return { rid, patchId };
|
||||
return { rid, patchId, repoFolder };
|
||||
}
|
||||
|
||||
async function openChanges(page: Page, peer: RadiclePeer) {
|
||||
@@ -153,6 +153,27 @@ test("a comment-only review needs a summary", async ({ page, peer }) => {
|
||||
await expect(publish).toBeEnabled();
|
||||
});
|
||||
|
||||
test("the revision picker counts a revision's commits as the Changes view does", async ({
|
||||
page,
|
||||
peer,
|
||||
}) => {
|
||||
const { rid, patchId, repoFolder } = await createPatch(peer);
|
||||
// A second revision that keeps the first one's commit and adds another.
|
||||
await Fs.appendFile(Path.join(repoFolder, "notes.txt"), "six\n");
|
||||
await peer.git(["commit", "-am", "Add a sixth line"], { cwd: repoFolder });
|
||||
await peer.git(["push", "rad", `HEAD:refs/heads/patches/${patchId}`], {
|
||||
cwd: repoFolder,
|
||||
});
|
||||
await page.goto(`/repos/${rid}/patches/${patchId}?view=changes`);
|
||||
|
||||
await expect(page.getByText("2 commits on base")).toBeVisible();
|
||||
await page.getByRole("button", { name: /Revision 2 of 2/ }).click();
|
||||
// The second revision's row, which ends with its commit count.
|
||||
await expect(
|
||||
page.getByRole("button", { name: /Add a sixth line.* icon-commit 2$/ }),
|
||||
).toBeVisible();
|
||||
});
|
||||
|
||||
test("shows reviews from other peers", async ({ page }) => {
|
||||
await page.goto(`/repos/${cobRid}/patches`);
|
||||
await page.getByText("Taking another stab at the README").click();
|
||||
|
||||
Reference in New Issue
Block a user