Skip to content

Commit d152d2c

Browse files
fix(client-runtime): a search query pasted from github.com lists pull requests again (#30150)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 768f17c commit d152d2c

2 files changed

Lines changed: 39 additions & 6 deletions

File tree

‎packages/client-runtime/src/pullRequestQuery.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe("reading qualifiers out of a typed query", () => {
3333
review: "changes-requested",
3434
checks: "failing",
3535
});
36+
expect(parsePullRequestQuery("-draft:true").filters).toEqual({ draft: "hide" });
3637
});
3738

3839
it("leaves an unknown value and a stray colon as text, and reads an unknown key as a label", () => {
@@ -53,6 +54,20 @@ describe("reading qualifiers out of a typed query", () => {
5354
]);
5455
});
5556

57+
// regression: #30131 a query pasted from github.com lists nothing
58+
it("ignores GitHub's own search qualifiers instead of reading them as labels", () => {
59+
expect(
60+
parsePullRequestQuery(
61+
"is:pr state:open archived:false repo:org/repo org:org user:alice sort:updated-desc -repo:org/fork -state:closed fix",
62+
),
63+
).toEqual({ text: "fix", filters: {} });
64+
});
65+
66+
it("sets no author when the query names more than one", () => {
67+
expect(parsePullRequestQuery("author:alice author:bob").filters).toEqual({});
68+
expect(parsePullRequestQuery("author:me author:@me").filters).toEqual({ author: "me" });
69+
});
70+
5671
it("cuts a typed query back to what the contract carries", () => {
5772
const many = Array.from({ length: 14 }, (_, index) => `l${index}`).join(",");
5873
const long = "x".repeat(240);

‎packages/client-runtime/src/pullRequestQuery.ts‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ function splitQualifierList(raw: string): string[] {
2929
.filter((part) => part.length > 0);
3030
}
3131

32+
/** `me` and `@me` both name the viewer; logins are case-insensitive. */
33+
function authorKey(login: string): string {
34+
return login.toLowerCase().replace(/^@me$/, "me");
35+
}
36+
3237
function boundedNames(names: ReadonlyArray<string>): string[] {
3338
return names
3439
.slice(0, MAX_QUALIFIER_VALUES)
@@ -43,7 +48,8 @@ export function parsePullRequestQuery(raw: string): {
4348
const text: string[] = [];
4449
const labels: string[][] = [];
4550
const excludedLabels: string[] = [];
46-
let author: string | undefined;
51+
// `null` once two different logins are named: GitHub ORs them, the contract carries one.
52+
let author: string | null | undefined;
4753
let draft: PullRequestListFilters["draft"];
4854
let review: PullRequestListFilters["review"];
4955
let checks: PullRequestListFilters["checks"];
@@ -59,13 +65,16 @@ export function parsePullRequestQuery(raw: string): {
5965
else labels.push(names);
6066
continue;
6167
}
62-
case "author":
68+
case "author": {
6369
if (negated) break;
64-
author = value.slice(0, MAX_QUALIFIER_LENGTH).trim();
70+
const login = value.slice(0, MAX_QUALIFIER_LENGTH).trim();
71+
if (author === undefined) author = login;
72+
else if (author === null || authorKey(author) !== authorKey(login)) author = null;
6573
continue;
74+
}
6675
case "draft":
67-
if (negated || (value.toLowerCase() !== "true" && value.toLowerCase() !== "false")) break;
68-
draft = value.toLowerCase() === "true" ? "only" : "hide";
76+
if (value.toLowerCase() !== "true" && value.toLowerCase() !== "false") break;
77+
draft = (value.toLowerCase() === "true") !== negated ? "only" : "hide";
6978
continue;
7079
case "review": {
7180
const decision = negated ? undefined : REVIEW_VALUES[value.toLowerCase()];
@@ -80,6 +89,15 @@ export function parsePullRequestQuery(raw: string): {
8089
checks = state;
8190
continue;
8291
}
92+
// GitHub's own search qualifiers, not labels: the list sets scope and order itself.
93+
case "is":
94+
case "archived":
95+
case "state":
96+
case "repo":
97+
case "org":
98+
case "user":
99+
case "sort":
100+
continue;
83101
case "":
84102
break;
85103
default:
@@ -104,7 +122,7 @@ export function parsePullRequestQuery(raw: string): {
104122
...(excludedLabels.length === 0
105123
? {}
106124
: { excludedLabels: excludedLabels.slice(0, MAX_QUALIFIER_VALUES) }),
107-
...(author === undefined ? {} : { author }),
125+
...(typeof author === "string" ? { author } : {}),
108126
...(draft === undefined ? {} : { draft }),
109127
...(review === undefined ? {} : { review }),
110128
...(checks === undefined ? {} : { checks }),

0 commit comments

Comments
 (0)