Skip to content

Commit 1b359ea

Browse files
committed
Coding Agent UI: Closed pull requests are not detected as closed
Fixes #8482
1 parent b2d0c58 commit 1b359ea

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/github/folderRepositoryManager.ts

Lines changed: 9 additions & 1 deletion
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,10 +1354,17 @@ 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,
13611369
totalCount: data.total_count
13621370
};

src/github/utils.ts

Lines changed: 24 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,29 @@ 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+
default:
1666+
return undefined;
1667+
}
1668+
}
1669+
16461670
export function isInCodespaces(): boolean {
16471671
return vscode.env.remoteName === 'codespaces' && vscode.env.uiKind === vscode.UIKind.Web;
16481672
}

0 commit comments

Comments
 (0)