Skip to content

Commit d6f00fe

Browse files
authored
Coding Agent UI: Closed pull requests are not detected as closed (#8485)
* Coding Agent UI: Closed pull requests are not detected as closed Fixes #8482 * Copilot PR comments
1 parent 8ff1803 commit d6f00fe

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/github/folderRepositoryManager.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
convertRESTPullRequestToRawPullRequest,
2323
getOverrideBranch,
2424
getPRFetchQuery,
25+
getStateFromQuery,
2526
loginComparator,
2627
parseGraphQLPullRequest,
2728
teamComparator,
@@ -1353,12 +1354,19 @@ export class FolderRepositoryManager extends Disposable {
13531354
})))
13541355
.filter(item => item !== null) as PullRequestModel[];
13551356

1357+
// GitHub's search API can return stale results whose state doesn't match the query.
1358+
// Post-filter to ensure only PRs with the requested state are included.
1359+
const queryState = getStateFromQuery(categoryQuery);
1360+
const filteredPullRequests = queryState
1361+
? pullRequests.filter(pr => pr.state === queryState)
1362+
: pullRequests;
1363+
13561364
Logger.debug(`Fetch pull request category ${categoryQuery} - done`, this.id);
13571365

13581366
return {
1359-
items: pullRequests,
1367+
items: filteredPullRequests,
13601368
hasMorePages,
1361-
totalCount: data.total_count
1369+
totalCount: data.total_count - (pullRequests.length - filteredPullRequests.length)
13621370
};
13631371
} catch (e) {
13641372
Logger.error(`Fetching pull request with query failed: ${e}`, this.id);

src/github/utils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { GitHubRepository, ViewerPermission } from './githubRepository';
1313
import * as GraphQL from './graphql';
1414
import {
1515
AccountType,
16+
GithubItemStateEnum,
1617
IAccount,
1718
IActor,
1819
IGitHubRef,
@@ -1643,6 +1644,28 @@ export function getPRFetchQuery(user: string, query: string): string {
16431644
return `is:pull-request ${filter} type:pr`;
16441645
}
16451646

1647+
/**
1648+
* Parse a GitHub search query for a state qualifier (e.g. `is:open`, `is:closed`, `is:merged`).
1649+
* Returns the corresponding GithubItemStateEnum if found, or undefined if no state is specified.
1650+
* GitHub's search API can return stale results that don't match the requested state,
1651+
* so callers can use this to post-filter.
1652+
*/
1653+
export function getStateFromQuery(query: string): GithubItemStateEnum | undefined {
1654+
const match = query.match(/(?:^|\s)is:(?<state>open|closed|merged)(?:\s|$)/i);
1655+
if (!match?.groups?.state) {
1656+
return undefined;
1657+
}
1658+
switch (match.groups.state.toLowerCase()) {
1659+
case 'open':
1660+
return GithubItemStateEnum.Open;
1661+
case 'closed':
1662+
return GithubItemStateEnum.Closed;
1663+
case 'merged':
1664+
return GithubItemStateEnum.Merged;
1665+
}
1666+
return undefined;
1667+
}
1668+
16461669
export function isInCodespaces(): boolean {
16471670
return vscode.env.remoteName === 'codespaces' && vscode.env.uiKind === vscode.UIKind.Web;
16481671
}

0 commit comments

Comments
 (0)