The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 18:15 UTC
fix(pull-requests): list filters narrow on every host that can (#23922)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 23, 2026 at 16:11 UTC
7beaa01a32bb937453f1d1247d52d492f124236c
14 files changed
+372
-12
packages/contracts/src/pullRequest.test.ts
+23
-1
@@ -2,7 +2,12 @@ import { SourceControlProviderKind } from "./sourceControl.ts";
2
import * as Schema from "effect/Schema";
3
import { describe, expect, it } from "vite-plus/test";
4
5
-import { PullRequestDetail, PullRequestListResult, pullRequestHostOf } from "./pullRequest.ts";
5
+import {
6
+ PullRequestDetail,
7
+ PullRequestListResult,
8
+ pullRequestHostOf,
9
+ resolvePullRequestAuthorFilter,
10
+} from "./pullRequest.ts";
11
12
const decodeDetail = Schema.decodeUnknownSync(Schema.toCodecJson(PullRequestDetail));
13
@@ -144,3 +149,20 @@ describe("PullRequestCapabilities", () => {
149
expect(decoded.title).toBe(detail.title);
150
});
151
});
152
+
153
+describe("resolvePullRequestAuthorFilter", () => {
154
+ it("reads me as the signed-in account on the host", () => {
155
+ expect(resolvePullRequestAuthorFilter("me", "bilal")).toBe("bilal");
156
+ expect(resolvePullRequestAuthorFilter(" @Me ", "bilal")).toBe("bilal");
157
+ });
158
+
159
+ it("keeps me as a literal login when the host has no viewer", () => {
160
+ expect(resolvePullRequestAuthorFilter("me", null)).toBe("me");
161
+ expect(resolvePullRequestAuthorFilter("@me", " ")).toBe("@me");
162
+ });
163
+
164
+ it("passes any other login through trimmed", () => {
165
+ expect(resolvePullRequestAuthorFilter(" ana ", "bilal")).toBe("ana");
166
+ expect(resolvePullRequestAuthorFilter("meredith", "bilal")).toBe("meredith");
167
+ });
168
+});
packages/source-control-azure-devops/src/server/AzureDevOpsPullRequestCli.test.ts
+21
@@ -201,6 +201,27 @@ layer("AzureDevOpsPullRequestCli.layer", (it) => {
201
}),
202
);
203
204
+ it.effect("asks Azure for the author's pull requests by creator", () =>
205
+ Effect.gen(function* () {
206
+ mockedExecute.mockReturnValueOnce(Effect.succeed(output(pullRequests(1, 1))));
207
+ const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
208
+
209
+ yield* cli.listPullRequests({
210
+ cwd: "/w",
211
+ repository: "web",
212
+ state: "open",
213
+ involvement: "reviewing",
214
+ viewer: "bilal@acme.dev",
215
+ limit: 10,
216
+ author: "ana@acme.dev",
217
+ });
218
+
219
+ const args = argsOfCall(0);
220
+ assert.strictEqual(args[args.indexOf("--creator") + 1], "ana@acme.dev");
221
+ assert.strictEqual(args[args.indexOf("--reviewer") + 1], "bilal@acme.dev");
222
+ }),
223
+ );
224
+
225
it.effect("advances by malformed raw rows and keeps reading until the page is full", () =>
226
Effect.gen(function* () {
227
mockedExecute
packages/source-control-azure-devops/src/server/AzureDevOpsPullRequestCli.ts
+7
@@ -150,6 +150,8 @@ export class AzureDevOpsPullRequestCli extends Context.Service<
150
readonly involvement: PullRequestInvolvement;
151
readonly viewer: string;
152
readonly limit: number;
153
+ /** Matched by `--creator`, which takes the email a row shows as its login. */
154
+ readonly author?: string | undefined;
155
/**
156
* Where to carry on from. Azure has no date filter for a pull request listing, so the only
157
* part of a cursor it can use is how many rows have already been handed over.
@@ -403,6 +405,7 @@ export const make = Effect.gen(function* () {
405
readonly state: PullRequestListState;
406
readonly involvement: PullRequestInvolvement;
407
readonly viewer: string;
408
+ readonly author?: string | undefined;
409
readonly limit: number;
410
readonly skip: number;
411
readonly cursorAdvance: number;
@@ -429,6 +432,9 @@ export const make = Effect.gen(function* () {
432
input.repository,
433
...statusArgs(input.state),
434
...involvementArgs(input),
435
+ ...(input.author === undefined || input.involvement === "authored"
436
+ ? []
437
+ : ["--creator", input.author]),
438
"--include-links",
439
...(input.skip === 0 ? [] : ["--skip", String(input.skip)]),
440
"--top",
@@ -546,6 +552,7 @@ export const make = Effect.gen(function* () {
552
state: input.state,
553
involvement: input.involvement,
554
viewer: input.viewer,
555
+ author: input.author,
556
limit: input.limit,
557
skip: input.cursor?.delivered ?? 0,
558
cursorAdvance: 0,
packages/source-control-azure-devops/src/server/AzureDevOpsPullRequestProvider.ts
+5
-1
@@ -1,4 +1,4 @@
1
-import { SourceControlProviderKind } from "@t3tools/contracts";
1
+import { resolvePullRequestAuthorFilter, SourceControlProviderKind } from "@t3tools/contracts";
2
import * as Effect from "effect/Effect";
3
import * as Semaphore from "effect/Semaphore";
4
import type { PullRequestCapabilities, PullRequestViewerPermissions } from "@t3tools/contracts";
@@ -275,6 +275,10 @@ export const make = Effect.gen(function* () {
275
viewer: input.viewer,
276
limit: input.limit,
277
cursor: input.cursor,
278
+ author:
279
+ input.filters?.author === undefined
280
+ ? undefined
281
+ : resolvePullRequestAuthorFilter(input.filters.author, input.viewer),
282
})
283
.pipe(
284
Effect.mapError(fail("listChangeRequests")),
packages/source-control-bitbucket/src/server/BitbucketPullRequestApi.test.ts
+19
@@ -157,6 +157,25 @@ layer("BitbucketPullRequestApi.layer", (it) => {
157
}),
158
);
159
160
+ it.effect("narrows by author and draft state in the same query", () =>
161
+ Effect.gen(function* () {
162
+ mockedRequest.mockReturnValueOnce(Effect.succeed(response(page(0, 1))));
163
+ const api = yield* BitbucketPullRequestApi.BitbucketPullRequestApi;
164
+
165
+ yield* api.listPullRequests({
166
+ repository: "acme/web",
167
+ state: "open",
168
+ limit: 50,
169
+ author: 'ana"',
170
+ draft: false,
171
+ });
172
+
173
+ expect(filterOfCall(0)).toBe(
174
+ '(author.nickname = "ana\\"" OR author.display_name = "ana\\"") AND draft = false',
175
+ );
176
+ }),
177
+ );
178
+
179
it.effect("refuses a repository that is not workspace and slug", () =>
180
Effect.gen(function* () {
181
const api = yield* BitbucketPullRequestApi.BitbucketPullRequestApi;
packages/source-control-bitbucket/src/server/BitbucketPullRequestApi.ts
+10
@@ -147,6 +147,9 @@ export class BitbucketPullRequestApi extends Context.Service<
147
readonly limit: number;
148
readonly query?: string | undefined;
149
readonly cursor?: ProviderListCursor | undefined;
150
+ /** Matched against the login a row shows, which is the nickname or else the display name. */
151
+ readonly author?: string | undefined;
152
+ readonly draft?: boolean | undefined;
153
}) => Effect.Effect<BitbucketPullRequestBatch, BitbucketPullRequestApiError>;
154
155
readonly getPullRequest: (input: {
@@ -329,6 +332,11 @@ function searchFilter(query: string): string {
332
return `(title ~ "${literal}" OR description ~ "${literal}")`;
333
}
334
335
+function authorFilter(login: string): string {
336
+ const literal = filterLiteral(login);
337
+ return `(author.nickname = "${literal}" OR author.display_name = "${literal}")`;
338
+}
339
+
340
/**
341
* The backslash is escaped first, or escaping the quote would only produce a literal
342
* backslash followed by a live quote.
@@ -565,6 +573,8 @@ export const make = Effect.gen(function* () {
573
// Exclude already-sent IDs at the inclusive timestamp before applying the page limit.
574
const predicates = [
575
...(search.length === 0 ? [] : [searchFilter(search)]),
576
+ ...(input.author === undefined ? [] : [authorFilter(input.author)]),
577
+ ...(input.draft === undefined ? [] : [`draft = ${input.draft}`]),
578
...(input.cursor === undefined ? [] : [`updated_on <= ${input.cursor.updatedBefore}`]),
579
...(input.cursor?.seenAt ?? []).map((number) => `id != ${number}`),
580
];
packages/source-control-bitbucket/src/server/BitbucketPullRequestProvider.ts
+6
-1
@@ -1,4 +1,4 @@
1
-import { SourceControlProviderKind } from "@t3tools/contracts";
1
+import { resolvePullRequestAuthorFilter, SourceControlProviderKind } from "@t3tools/contracts";
2
import * as Effect from "effect/Effect";
3
import type { PullRequestCapabilities, PullRequestViewerPermissions } from "@t3tools/contracts";
4
@@ -158,6 +158,11 @@ export const make = Effect.gen(function* () {
158
limit: input.limit,
159
query: input.query,
160
cursor: input.cursor,
161
+ author:
162
+ input.filters?.author === undefined
163
+ ? undefined
164
+ : resolvePullRequestAuthorFilter(input.filters.author, input.viewer),
165
+ draft: input.filters?.draft === undefined ? undefined : input.filters.draft === "only",
166
})
167
.pipe(
168
Effect.mapError(fail("listChangeRequests")),
packages/source-control-forgejo/src/server/ForgejoPullRequestProvider.ts
+29
-6
@@ -1,4 +1,4 @@
1
-import { SourceControlProviderKind } from "@t3tools/contracts";
1
+import { resolvePullRequestAuthorFilter, SourceControlProviderKind } from "@t3tools/contracts";
2
import * as Effect from "effect/Effect";
3
import * as Schema from "effect/Schema";
4
import * as Result from "effect/Result";
@@ -254,13 +254,36 @@ export const make = Effect.gen(function* () {
254
const offset = input.cursor?.delivered ?? 0;
255
const items: ReturnType<typeof forgejoChangeRequest>[] = [];
256
const state = input.state === "merged" ? "closed" : input.state;
257
- const query = {
258
- ...input,
259
- path: `${repoPath(input)}/pulls?state=${state}&sort=recentupdate`,
260
- };
257
+ const params = new URLSearchParams({ state, sort: "recentupdate" });
258
+ const filters = input.filters;
259
+ // Several `labels` match a pull request holding any of them but list it once per label it
260
+ // holds, which would throw the row offset off, so one required label is all Forgejo is
261
+ // asked for. The service narrows the rest.
262
+ const single = filters?.labels?.find((group) => group.length === 1)?.[0];
263
+ if (single !== undefined) {
264
+ const labels = yield* page({ ...input, path: `${repoPath(input)}/labels` }, ForgejoLabel);
265
+ const label = labels.items.find(
266
+ (candidate) => candidate.name.toLowerCase() === single.trim().toLowerCase(),
267
+ );
268
+ if (label !== undefined) params.set("labels", String(label.id));
269
+ }
270
+ if (filters?.author !== undefined)
271
+ params.set("poster", resolvePullRequestAuthorFilter(filters.author, input.viewer));
272
+ const query = { ...input, path: `${repoPath(input)}/pulls?${params}` };
273
// Self-hosted servers may cap pages below 50. Establish their actual page size before
274
// translating the service's row offset into an API page number.
263
- const first = yield* readPage(query, Schema.NullOr(ForgejoPullRequest), 1);
275
+ const first = yield* readPage(query, Schema.NullOr(ForgejoPullRequest), 1).pipe(
276
+ Effect.catchTags({
277
+ // Forgejo answers a `poster` naming no account with a 400: nobody to list for.
278
+ PullRequestProviderError: (error) =>
279
+ params.has("poster") &&
280
+ isForgejoCliError(error.cause) &&
281
+ error.cause.httpStatus === 400
282
+ ? Effect.succeed(null)
283
+ : Effect.fail(error),
284
+ }),
285
+ );
286
+ if (first === null) return { items: [], truncated: false, continues: false };
287
const pageSize = first.rows.length || 50;
288
const firstIndex = Math.floor(offset / pageSize) + 1;
289
let consumed = 0;
packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts
+64
@@ -490,6 +490,70 @@ it.effect.each([
490
},
491
);
492
493
+it.effect("asks Forgejo for one required label by id and the author by login", () => {
494
+ const paths: Array<string> = [];
495
+ return Effect.gen(function* () {
496
+ const provider = yield* ForgejoPullRequestProvider.make;
497
+ yield* provider.listChangeRequests({
498
+ cwd: "/repo",
499
+ repository: "maria/project",
500
+ host: "forgejo.test",
501
+ state: "open",
502
+ involvement: "all",
503
+ viewer: "maria",
504
+ limit: 10,
505
+ filters: { labels: [["size:S", "size:M"], ["Bug"]], author: "@me" },
506
+ });
507
+ const listing = paths.find((path) => path.startsWith("repos/maria/project/pulls?"));
508
+ const params = new URLSearchParams(listing?.split("?")[1]);
509
+ assert.deepStrictEqual(params.getAll("labels"), ["7"]);
510
+ assert.strictEqual(params.get("poster"), "maria");
511
+ }).pipe(
512
+ Effect.provide(
513
+ Layer.mock(ForgejoCli.ForgejoCli)({
514
+ api: (input) => {
515
+ paths.push(input.path);
516
+ const response = input.path.startsWith("repos/maria/project/labels")
517
+ ? [{ id: 7, name: "bug" }]
518
+ : [];
519
+ return encodeJsonEffect(response).pipe(Effect.orDie, Effect.map(processOutput));
520
+ },
521
+ }),
522
+ ),
523
+ );
524
+});
525
+
526
+it.effect("lists nothing for an author Forgejo has no account for", () =>
527
+ Effect.gen(function* () {
528
+ const provider = yield* ForgejoPullRequestProvider.make;
529
+ const page = yield* provider.listChangeRequests({
530
+ cwd: "/repo",
531
+ repository: "maria/project",
532
+ host: "forgejo.test",
533
+ state: "open",
534
+ involvement: "all",
535
+ viewer: "maria",
536
+ limit: 10,
537
+ filters: { author: "nobody" },
538
+ });
539
+ assert.deepStrictEqual(page, { items: [], truncated: false, continues: false });
540
+ }).pipe(
541
+ Effect.provide(
542
+ Layer.mock(ForgejoCli.ForgejoCli)({
543
+ api: (input) =>
544
+ Effect.fail(
545
+ new ForgejoCli.ForgejoCliError({
546
+ command: "fj",
547
+ cwd: input.cwd,
548
+ httpStatus: 400,
549
+ detail: "Forgejo API request failed (HTTP 400): Poster not found",
550
+ }),
551
+ ),
552
+ }),
553
+ ),
554
+ ),
555
+);
556
+
557
it.effect("gives Forgejo identities the browser URL of the login that serves them", () =>
558
Effect.gen(function* () {
559
const provider = yield* ForgejoSourceControlProvider.make;
packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.test.ts
+47
@@ -418,6 +418,53 @@ describe("GitCafePullRequestProvider", () => {
418
}).pipe(Effect.provide(server.layer));
419
});
420
421
+ it.effect("narrows a listing on GitCafe by label ids, draft state and the author's actor", () => {
422
+ const server = fakeGitCafe({
423
+ "GET /repos/owner/repo/labels": { items: labels, next: null },
424
+ "GET /users/bob": { actorId: "act_bob", handle: "bob" },
425
+ "GET /repos/owner/repo/pulls": { items: [pull], next: null },
426
+ });
427
+ return Effect.gen(function* () {
428
+ const provider = yield* GitCafePullRequestProvider.make;
429
+ yield* provider.listChangeRequests({
430
+ ...target,
431
+ state: "open",
432
+ involvement: "all",
433
+ viewer: "alice",
434
+ limit: 10,
435
+ filters: {
436
+ draft: "hide",
437
+ labels: [["missing"], ["Bug", "docs"]],
438
+ excludedLabels: ["docs", "missing"],
439
+ author: "bob",
440
+ },
441
+ });
442
+ const listing = server.sent.at(-1)!;
443
+ assert.strictEqual(listing.path, "/repos/owner/repo/pulls");
444
+ assert.strictEqual(listing.query.get("labels"), '["label_bug","label_docs"]');
445
+ assert.strictEqual(listing.query.get("labelNots"), '["label_docs"]');
446
+ assert.strictEqual(listing.query.get("stateNots"), '["draft"]');
447
+ assert.strictEqual(listing.query.get("authors"), '["act_bob"]');
448
+ }).pipe(Effect.provide(server.layer));
449
+ });
450
+
451
+ it.effect("leaves an author GitCafe has no profile for to be narrowed by login", () => {
452
+ const server = fakeGitCafe({ "GET /repos/owner/repo/pulls": { items: [pull], next: null } });
453
+ return Effect.gen(function* () {
454
+ const provider = yield* GitCafePullRequestProvider.make;
455
+ const page = yield* provider.listChangeRequests({
456
+ ...target,
457
+ state: "open",
458
+ involvement: "all",
459
+ viewer: "alice",
460
+ limit: 10,
461
+ filters: { author: "synced-only" },
462
+ });
463
+ assert.strictEqual(page.items.length, 1);
464
+ assert.isNull(server.sent.at(-1)!.query.get("authors"));
465
+ }).pipe(Effect.provide(server.layer));
466
+ });
467
+
468
it.effect("lists nothing for a viewer the token does not belong to", () => {
469
const server = fakeGitCafe({
470
"GET /auth/principal": { actorId: "act_two", handle: "bob" },
packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.ts
+72
-2
@@ -5,8 +5,10 @@ import * as Schema from "effect/Schema";
5
import { randomUuidV4 } from "@t3tools/provider-core/server/randomUuid";
6
import {
7
NonNegativeInt,
8
+ resolvePullRequestAuthorFilter,
9
TrimmedNonEmptyString,
10
type PullRequestCapabilities,
11
+ type PullRequestListFilters,
12
type PullRequestStackHead,
13
} from "@t3tools/contracts";
14
import {
@@ -74,6 +76,7 @@ const Id = TrimmedNonEmptyString.check(Schema.isPattern(/^[A-Za-z0-9_-]+$/u));
76
const isId = Schema.is(Id);
77
const isApiError = Schema.is(GitCafeApi.GitCafeApiError);
78
const Principal = Schema.Struct({ actorId: TrimmedNonEmptyString, handle: TrimmedNonEmptyString });
79
+const User = Schema.Struct({ actorId: TrimmedNonEmptyString });
80
const Written = Schema.Struct({ id: Id });
81
const Versioned = Schema.Struct({ version: NonNegativeInt });
82
const CommentDetail = Schema.Struct({ id: Id, version: NonNegativeInt });
@@ -104,7 +107,7 @@ const Listed = Schema.Struct({
107
items: Schema.Array(Schema.Struct({ id: TrimmedNonEmptyString })),
108
next: Schema.NullOr(Schema.String),
109
});
107
-const encodeActorIds = Schema.encodeSync(Schema.fromJsonString(Schema.Array(Schema.String)));
110
+const encodeIds = Schema.encodeSync(Schema.fromJsonString(Schema.Array(Schema.String)));
111
const BranchCommit = Schema.Struct({ oid: TrimmedNonEmptyString });
112
const Snapshot = {
113
version: NonNegativeInt,
@@ -259,6 +262,68 @@ export const make = Effect.gen(function* () {
262
return { items, next };
263
});
264
265
+ /**
266
+ * GitCafe filters by ids, so label names and the author's handle are looked up first. A name it
267
+ * cannot resolve is left out, and the service narrows the rows by name instead.
268
+ */
269
+ const listFilterParams = Effect.fn("GitCafePullRequestProvider.listFilterParams")(function* (
270
+ input: ProviderRepositoryRef & {
271
+ readonly filters?: PullRequestListFilters | undefined;
272
+ readonly authorNarrowed: boolean;
273
+ readonly viewer: string;
274
+ },
275
+ base: string,
276
+ ) {
277
+ const filters = input.filters;
278
+ const params: Array<readonly [string, string]> = [];
279
+ if (filters === undefined) return params;
280
+ if (filters.draft !== undefined)
281
+ params.push([filters.draft === "only" ? "states" : "stateNots", encodeIds(["draft"])]);
282
+ const groups = filters.labels ?? [];
283
+ const excluded = filters.excludedLabels ?? [];
284
+ if (groups.length > 0 || excluded.length > 0) {
285
+ const labels = yield* readPages(
286
+ "listChangeRequests",
287
+ input,
288
+ `${base}/labels`,
289
+ Json.GitCafeLabels,
290
+ );
291
+ const ids = new Map(labels.items.map((label) => [label.name.toLowerCase(), label.id]));
292
+ const idsOf = (names: ReadonlyArray<string>) =>
293
+ names.flatMap((name) => {
294
+ const id = ids.get(name.trim().toLowerCase());
295
+ return id === undefined ? [] : [id];
296
+ });
297
+ // Several ids in `labels` match a pull request holding any one of them, which is exactly
298
+ // one group; the remaining groups are the service's to narrow.
299
+ const group = groups.find((names) => idsOf(names).length === names.length);
300
+ if (group !== undefined) params.push(["labels", encodeIds(idsOf(group))]);
301
+ const excludedIds = idsOf(excluded);
302
+ if (excludedIds.length > 0) params.push(["labelNots", encodeIds(excludedIds)]);
303
+ }
304
+ if (filters.author !== undefined && !input.authorNarrowed) {
305
+ const handle = resolvePullRequestAuthorFilter(filters.author, input.viewer);
306
+ // A GitHub-synced author with no GitCafe profile has no handle here; their rows are
307
+ // narrowed by login instead. A profile matches what GitHub sync authored for it too.
308
+ const user = yield* read(
309
+ "listChangeRequests",
310
+ input,
311
+ { path: `/users/${encodeURIComponent(handle)}` },
312
+ User,
313
+ ).pipe(
314
+ Effect.map(Option.some),
315
+ Effect.catchTags({
316
+ PullRequestProviderError: (error) =>
317
+ error.reason === "unauthenticated" || error.reason === "rate-limited"
318
+ ? Effect.fail(error)
319
+ : Effect.succeed(Option.none()),
320
+ }),
321
+ );
322
+ if (Option.isSome(user)) params.push(["authors", encodeIds([user.value.actorId])]);
323
+ }
324
+ return params;
325
+ });
326
+
327
const readComments = (operation: string, input: PullRef) =>
328
pullPath(operation, input).pipe(
329
Effect.flatMap((path) =>
@@ -570,6 +635,10 @@ export const make = Effect.gen(function* () {
635
actorId = principal.value.actorId;
636
}
637
}
638
+ const filterParams = yield* listFilterParams(
639
+ { ...input, authorNarrowed: actorId !== undefined && input.involvement === "authored" },
640
+ base,
641
+ );
642
const limit = Math.max(1, input.limit);
643
const items: Array<Json.GitCafePull> = [];
644
let next: string | null = null;
@@ -580,10 +649,11 @@ export const make = Effect.gen(function* () {
649
});
650
if (input.state !== "all") query.set("state", input.state);
651
if (input.query?.trim()) query.set("q", input.query.trim());
652
+ for (const [key, value] of filterParams) query.set(key, value);
653
if (actorId !== undefined)
654
query.set(
655
input.involvement === "reviewing" ? "reviewers" : "authors",
586
- encodeActorIds([actorId]),
656
+ encodeIds([actorId]),
657
);
658
if (next !== null) query.set("after", next);
659
const page: typeof Json.GitCafePulls.Type = yield* read(
packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts
+28
@@ -146,6 +146,34 @@ layer("GitLabPullRequestCli.layer", (it) => {
146
}),
147
);
148
149
+ it.effect("asks GitLab for the labels, author and draft state it can filter on", () =>
150
+ Effect.gen(function* () {
151
+ mockedExecute.mockReturnValueOnce(Effect.succeed(output(mergeRequests(1, 1))));
152
+ const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
153
+
154
+ yield* cli.listMergeRequests({
155
+ cwd: "/w",
156
+ repository: "acme/web",
157
+ state: "open",
158
+ involvement: "all",
159
+ viewer: "bilal",
160
+ limit: 10,
161
+ filters: {
162
+ labels: [["bug"], ["size:S", "size:XS"], ["a,b"], ["None"]],
163
+ excludedLabels: ["wontfix", "stale", "any"],
164
+ author: "@me",
165
+ draft: "only",
166
+ },
167
+ });
168
+
169
+ const params = new URLSearchParams((argsOfCall(0)[1] ?? "").split("?")[1]);
170
+ expect(params.get("labels")).toBe("bug");
171
+ expect(params.get("not[labels]")).toBe("wontfix,stale");
172
+ expect(params.get("author_username")).toBe("bilal");
173
+ expect(params.get("wip")).toBe("yes");
174
+ }),
175
+ );
176
+
177
it.effect("carries on from the number of rows already delivered", () =>
178
Effect.gen(function* () {
179
mockedExecute.mockReturnValueOnce(Effect.succeed(output(mergeRequests(3, 1))));
packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts
+40
-1
@@ -3,12 +3,13 @@ import * as Effect from "effect/Effect";
3
import * as Layer from "effect/Layer";
4
import * as Result from "effect/Result";
5
import * as Schema from "effect/Schema";
6
-import { VcsProcessExitError } from "@t3tools/contracts";
6
+import { resolvePullRequestAuthorFilter, VcsProcessExitError } from "@t3tools/contracts";
7
import type {
8
PullRequestAction,
9
PullRequestComment,
10
PullRequestCommit,
11
PullRequestInvolvement,
12
+ PullRequestListFilters,
13
PullRequestListState,
14
PullRequestMergeCapabilities,
15
PullRequestMergeMethod,
@@ -223,6 +224,7 @@ export class GitLabPullRequestCli extends Context.Service<
224
readonly limit: number;
225
readonly query?: string | undefined;
226
readonly cursor?: ProviderListCursor | undefined;
227
+ readonly filters?: PullRequestListFilters | undefined;
228
}) => Effect.Effect<GitLabMergeRequestListBatch, GitLabPullRequestCliError>;
229
230
readonly getMergeRequestDetail: (input: {
@@ -419,6 +421,41 @@ function involvementParams(input: {
421
}
422
}
423
424
+/**
425
+ * GitLab's `labels` asks for every label it names, so only groups of one go to it; a group of
426
+ * alternatives is left for the service to narrow. A comma would split a name in two, and `None`
427
+ * and `Any` mean "unlabeled" and "labeled" to GitLab rather than labels of those names.
428
+ */
429
+function filterParams(input: {
430
+ readonly filters?: PullRequestListFilters | undefined;
431
+ readonly involvement: PullRequestInvolvement;
432
+ readonly viewer: string;
433
+}): ReadonlyArray<readonly [string, string]> {
434
+ const filters = input.filters;
435
+ if (filters === undefined) return [];
436
+ const listable = (names: ReadonlyArray<string>) =>
437
+ names.filter((name) => !name.includes(",") && !/^(?:none|any)$/iu.test(name.trim()));
438
+ const required = listable(
439
+ (filters.labels ?? []).flatMap((group) => (group.length === 1 ? group : [])),
440
+ );
441
+ const excluded = listable(filters.excludedLabels ?? []);
442
+ return [
443
+ ...(required.length === 0 ? [] : [["labels", required.join(",")] as const]),
444
+ ...(excluded.length === 0 ? [] : [["not[labels]", excluded.join(",")] as const]),
445
+ ...(filters.author === undefined || input.involvement === "authored"
446
+ ? []
447
+ : [
448
+ [
449
+ "author_username",
450
+ resolvePullRequestAuthorFilter(filters.author, input.viewer),
451
+ ] as const,
452
+ ]),
453
+ ...(filters.draft === undefined
454
+ ? []
455
+ : [["wip", filters.draft === "only" ? "yes" : "no"] as const]),
456
+ ];
457
+}
458
+
459
function diffCursorPage(cursor: string): number | null {
460
return /^[1-9][0-9]{0,6}$/.test(cursor) ? Number(cursor) : null;
461
}
@@ -514,6 +551,7 @@ export const make = Effect.gen(function* () {
551
readonly limit: number;
552
readonly query?: string | undefined;
553
readonly cursor?: ProviderListCursor | undefined;
554
+ readonly filters?: PullRequestListFilters | undefined;
555
readonly page: number;
556
readonly collected: ReadonlyArray<GitLabMergeRequestListItem>;
557
readonly cursorAdvance: number;
@@ -535,6 +573,7 @@ export const make = Effect.gen(function* () {
573
["state", stateParam(input.state)],
574
...involvementParams(input),
575
...searchParams(input.query),
576
+ ...filterParams(input),
577
["order_by", "updated_at"],
578
["sort", "desc"],
579
["per_page", String(perPage)],
packages/source-control-gitlab/src/server/GitLabPullRequestProvider.ts
+1
@@ -130,6 +130,7 @@ export const make = Effect.gen(function* () {
130
limit: input.limit,
131
query: input.query,
132
cursor: input.cursor,
133
+ filters: input.filters,
134
})
135
.pipe(
136
Effect.mapError(fail("listChangeRequests")),