Skip to content

Commit 9779483

Browse files
Copilotalexr00
andauthored
Revert code changes; document OR syntax for multiple authors
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 850b80a commit 9779483

3 files changed

Lines changed: 2 additions & 77 deletions

File tree

package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"githubPullRequests.autoRepositoryDetection.markdownDescription": "Controls which repositories are automatically detected and opened by the extension.",
3131
"githubPullRequests.autoRepositoryDetection.workspace": "Only detect repositories within the current workspace folders.",
3232
"githubPullRequests.autoRepositoryDetection.true": "Detect all repositories found by the Git extension, including those outside workspace folders.",
33-
"githubPullRequests.queries.markdownDescription": "Specifies what queries should be used in the GitHub Pull Requests tree. All queries are made against **the currently opened repos**. Each query object has a `label` that will be shown in the tree and a search `query` using [GitHub search syntax](https://help.github.com/en/articles/understanding-the-search-syntax). By default these queries define the categories \"Copilot on My Behalf\", \"Local Pull Request Branches\", \"Waiting For My Review\", \"Assigned To Me\" and \"Created By Me\". If you want to preserve these, make sure they are still in the array when you modify the setting. \n\n**Variables available:**\n - `${user}` - currently logged in user \n - `${owner}` - repository owner, ex. `microsoft` in `microsoft/vscode` \n - `${repository}` - repository name, ex. `vscode` in `microsoft/vscode` \n - `${today-Nd}` - date N days ago, ex. `${today-7d}` becomes `2025-01-04`\n\n**Example custom queries:**\n```json\n\"githubPullRequests.queries\": [\n {\n \"label\": \"Waiting For My Review\",\n \"query\": \"is:open review-requested:${user}\"\n },\n {\n \"label\": \"Mentioned Me\",\n \"query\": \"is:open mentions:${user}\"\n },\n {\n \"label\": \"Recent Activity\",\n \"query\": \"is:open updated:>${today-7d}\"\n }\n]\n```",
33+
"githubPullRequests.queries.markdownDescription": "Specifies what queries should be used in the GitHub Pull Requests tree. All queries are made against **the currently opened repos**. Each query object has a `label` that will be shown in the tree and a search `query` using [GitHub search syntax](https://help.github.com/en/articles/understanding-the-search-syntax). By default these queries define the categories \"Copilot on My Behalf\", \"Local Pull Request Branches\", \"Waiting For My Review\", \"Assigned To Me\" and \"Created By Me\". If you want to preserve these, make sure they are still in the array when you modify the setting. \n\n**Variables available:**\n - `${user}` - currently logged in user \n - `${owner}` - repository owner, ex. `microsoft` in `microsoft/vscode` \n - `${repository}` - repository name, ex. `vscode` in `microsoft/vscode` \n - `${today-Nd}` - date N days ago, ex. `${today-7d}` becomes `2025-01-04`\n\n**Matching multiple values:** Queries use GitHub's advanced search, where a space between qualifiers means `AND`. To match any one of several values (for example several authors), combine them with `OR`, ex. `author:name1 OR author:name2 OR author:name3`.\n\n**Example custom queries:**\n```json\n\"githubPullRequests.queries\": [\n {\n \"label\": \"Waiting For My Review\",\n \"query\": \"is:open review-requested:${user}\"\n },\n {\n \"label\": \"Mentioned Me\",\n \"query\": \"is:open mentions:${user}\"\n },\n {\n \"label\": \"Created By My Team\",\n \"query\": \"is:open author:name1 OR author:name2 OR author:name3\"\n },\n {\n \"label\": \"Recent Activity\",\n \"query\": \"is:open updated:>${today-7d}\"\n }\n]\n```",
3434
"githubPullRequests.queries.label.description": "The label to display for the query in the Pull Requests tree.",
3535
"githubPullRequests.queries.query.description": "The GitHub search query for finding pull requests. Use GitHub search syntax with variables like ${user}, ${owner}, ${repository}. Example: 'is:open author:${user}' finds your open pull requests.",
3636
"githubPullRequests.queries.copilotOnMyBehalf": "Copilot on My Behalf",

src/github/utils.ts

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,53 +1764,8 @@ export function insertNewCommitsSinceReview(
17641764
});
17651765
}
17661766

1767-
const AUTHOR_QUALIFIER_PATTERN = /(^|\s|\()(-?)author:("[^"]+"|\S+)/g;
1768-
1769-
/**
1770-
* GitHub's advanced search treats a space between qualifiers as an `AND` operator.
1771-
* Because a pull request only has a single author, repeating positive `author:`
1772-
* qualifiers (e.g. `author:a author:b`) would `AND` them together and never match.
1773-
* The legacy search API used to `OR` these together, so combine repeated positive
1774-
* `author:` qualifiers into a single `(author:a OR author:b)` group to preserve that
1775-
* behavior. Negated qualifiers (e.g. `-author:a`) keep their `AND` semantics.
1776-
*/
1777-
function combineAuthorQualifiers(query: string): string {
1778-
const positiveAuthors: string[] = [];
1779-
let match: RegExpExecArray | null;
1780-
AUTHOR_QUALIFIER_PATTERN.lastIndex = 0;
1781-
while ((match = AUTHOR_QUALIFIER_PATTERN.exec(query)) !== null) {
1782-
if (!match[2]) {
1783-
positiveAuthors.push(`author:${match[3]}`);
1784-
}
1785-
}
1786-
if (positiveAuthors.length < 2) {
1787-
return query;
1788-
}
1789-
1790-
const group = `(${positiveAuthors.join(' OR ')})`;
1791-
let inserted = false;
1792-
AUTHOR_QUALIFIER_PATTERN.lastIndex = 0;
1793-
return query
1794-
.replace(AUTHOR_QUALIFIER_PATTERN, (full, prefix, negation) => {
1795-
if (negation) {
1796-
return full;
1797-
}
1798-
if (!inserted) {
1799-
inserted = true;
1800-
return `${prefix}${group}`;
1801-
}
1802-
// Drop this duplicate author qualifier. When the prefix is a plain
1803-
// separating space we remove it entirely; otherwise (e.g. a leading
1804-
// `(`) we keep the prefix so surrounding syntax stays intact. Any
1805-
// resulting double spaces are collapsed below.
1806-
return prefix === ' ' ? '' : prefix;
1807-
})
1808-
.replace(/\s{2,}/g, ' ')
1809-
.trim();
1810-
}
1811-
18121767
export function getPRFetchQuery(user: string, query: string): string {
1813-
const filter = combineAuthorQualifiers(query.replace(/\$\{user\}/g, user));
1768+
const filter = query.replace(/\$\{user\}/g, user);
18141769
return `is:pull-request ${filter} type:pr`;
18151770
}
18161771

src/test/github/utils.test.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,6 @@ describe('utils', () => {
1919
const result = getPRFetchQuery(user, query)
2020
assert.strictEqual(result, 'is:pull-request reviewed-by:rmacfarlane -author:rmacfarlane type:pr');
2121
});
22-
23-
it('combines multiple author qualifiers with OR', () => {
24-
const query = 'repo:owner/repo is:open author:name1 author:name2 author:name3';
25-
const result = getPRFetchQuery('me', query);
26-
assert.strictEqual(result, 'is:pull-request repo:owner/repo is:open (author:name1 OR author:name2 OR author:name3) type:pr');
27-
});
28-
29-
it('leaves a single author qualifier unchanged', () => {
30-
const query = 'repo:owner/repo is:open author:name1';
31-
const result = getPRFetchQuery('me', query);
32-
assert.strictEqual(result, 'is:pull-request repo:owner/repo is:open author:name1 type:pr');
33-
});
34-
35-
it('does not combine negated author qualifiers', () => {
36-
const query = 'is:open -author:name1 -author:name2';
37-
const result = getPRFetchQuery('me', query);
38-
assert.strictEqual(result, 'is:pull-request is:open -author:name1 -author:name2 type:pr');
39-
});
40-
41-
it('only groups positive author qualifiers, keeping negations', () => {
42-
const query = 'author:name1 author:name2 -author:name3';
43-
const result = getPRFetchQuery('me', query);
44-
assert.strictEqual(result, 'is:pull-request (author:name1 OR author:name2) -author:name3 type:pr');
45-
});
46-
47-
it('combines author qualifiers after ${user} substitution', () => {
48-
const query = 'author:${user} author:teammate';
49-
const result = getPRFetchQuery('me', query);
50-
assert.strictEqual(result, 'is:pull-request (author:me OR author:teammate) type:pr');
51-
});
5222
});
5323

5424
describe('sanitizeIssueTitle', () => {

0 commit comments

Comments
 (0)