Sort pull requests by updated time and fix git mock shape
- Use Effect ordering for PR recency sorting in the server git manager - Update web git status test mocks to match the split `vcs` and `git` APIs
This commit is contained in:
1 parent
03909848ec
commit
d66295d2a3
2 files changed
+12
-19
No files matched your search
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
||||
import { realpathSync } from "node:fs";
|
||||
|
||||
import {
|
||||
Array as EffectArray,
|
||||
Cache,
|
||||
DateTime,
|
||||
Duration,
|
||||
@@ -10,6 +11,7 @@ import {
|
||||
FileSystem,
|
||||
Layer,
|
||||
Option,
|
||||
Order,
|
||||
Path,
|
||||
Ref,
|
||||
} from "effect";
|
||||
@@ -74,6 +76,11 @@ interface PullRequestInfo extends OpenPrInfo, PullRequestHeadRemoteInfo {
|
||||
updatedAt: Option.Option<DateTime.Utc>;
|
||||
}
|
||||
|
||||
const pullRequestUpdatedAtDescOrder: Order.Order<PullRequestInfo> = Order.mapInput(
|
||||
Order.flip(Option.makeOrder(DateTime.Order)),
|
||||
(pullRequest) => pullRequest.updatedAt,
|
||||
);
|
||||
|
||||
interface ResolvedPullRequest {
|
||||
number: number;
|
||||
title: string;
|
||||
@@ -273,20 +280,6 @@ function toPullRequestInfo(summary: ChangeRequest): PullRequestInfo {
|
||||
};
|
||||
}
|
||||
|
||||
function compareOptionalDateTimeDesc(
|
||||
left: Option.Option<DateTime.Utc>,
|
||||
right: Option.Option<DateTime.Utc>,
|
||||
): number {
|
||||
return Option.match(left, {
|
||||
onNone: () => (Option.isNone(right) ? 0 : 1),
|
||||
onSome: (leftValue) =>
|
||||
Option.match(right, {
|
||||
onNone: () => -1,
|
||||
onSome: (rightValue) => DateTime.Order(rightValue, leftValue),
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
function gitManagerError(operation: string, detail: string, cause?: unknown): GitManagerError {
|
||||
return new GitManagerError({
|
||||
operation,
|
||||
@@ -895,9 +888,7 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
}
|
||||
}
|
||||
|
||||
const parsed = Array.from(parsedByNumber.values()).toSorted((a, b) =>
|
||||
compareOptionalDateTimeDesc(a.updatedAt, b.updatedAt),
|
||||
);
|
||||
const parsed = EffectArray.sort(parsedByNumber.values(), pullRequestUpdatedAtDescOrder);
|
||||
|
||||
const latestOpenPr = parsed.find((pr) => pr.state === "open");
|
||||
if (latestOpenPr) {
|
||||
|
||||
@@ -89,7 +89,7 @@ function createRegisteredGitStatusClient(environmentId: EnvironmentId) {
|
||||
shell: {
|
||||
openInEditor: vi.fn(async () => undefined),
|
||||
},
|
||||
git: {
|
||||
vcs: {
|
||||
pull: vi.fn(async () => undefined),
|
||||
refreshStatus: vi.fn(async (input: { cwd: string }) => ({
|
||||
...BASE_STATUS,
|
||||
@@ -98,13 +98,15 @@ function createRegisteredGitStatusClient(environmentId: EnvironmentId) {
|
||||
onStatus: vi.fn((_: { cwd: string }, listener: (event: GitStatusResult) => void) =>
|
||||
registerListener(listeners, listener),
|
||||
),
|
||||
runStackedAction: vi.fn(async () => ({}) as any),
|
||||
listBranches: vi.fn(async () => []),
|
||||
createWorktree: vi.fn(async () => undefined),
|
||||
removeWorktree: vi.fn(async () => undefined),
|
||||
createBranch: vi.fn(async () => undefined),
|
||||
checkout: vi.fn(async () => undefined),
|
||||
init: vi.fn(async () => undefined),
|
||||
},
|
||||
git: {
|
||||
runStackedAction: vi.fn(async () => ({}) as any),
|
||||
resolvePullRequest: vi.fn(async () => undefined),
|
||||
preparePullRequestThread: vi.fn(async () => undefined),
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user