Skip to content

Commit 127af23

Browse files
Copilotalexr00
andcommitted
Add auto-refresh configuration for pull requests queries
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent eaa6adc commit 127af23

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@
263263
}
264264
]
265265
},
266+
"githubPullRequests.queries.refreshInterval": {
267+
"type": "number",
268+
"default": 0,
269+
"minimum": 0,
270+
"markdownDescription": "%githubPullRequests.queries.refreshInterval.markdownDescription%"
271+
},
266272
"githubPullRequests.labelCreated": {
267273
"type": "array",
268274
"items": {

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"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```",
3030
"githubPullRequests.queries.label.description": "The label to display for the query in the Pull Requests tree.",
3131
"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.",
32+
"githubPullRequests.queries.refreshInterval.markdownDescription": "Automatically refresh pull requests queries at the specified interval. Set to `0` to disable auto-refresh. The minimum refresh interval is 5 minutes.",
3233
"githubPullRequests.queries.copilotOnMyBehalf": "Copilot on My Behalf",
3334
"githubPullRequests.queries.waitingForMyReview": "Waiting For My Review",
3435
"githubPullRequests.queries.assignedToMe": "Assigned To Me",

src/common/settingKeys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type NotificationVariants = 'off' | 'pullRequests';
2323
export const POST_CREATE = 'postCreate';
2424
export const POST_DONE = 'postDone';
2525
export const QUERIES = 'queries';
26+
export const QUERIES_REFRESH_INTERVAL = 'queries.refreshInterval';
2627
export const PULL_REQUEST_LABELS = 'labelCreated';
2728
export const FOCUSED_MODE = 'focusedMode';
2829
export const CREATE_DRAFT = 'createDraft';

src/view/prsTreeDataProvider.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { AuthProvider } from '../common/authentication';
1111
import { commands, contexts } from '../common/executeCommands';
1212
import { Disposable } from '../common/lifecycle';
1313
import Logger from '../common/logger';
14-
import { FILE_LIST_LAYOUT, PR_SETTINGS_NAMESPACE, QUERIES, REMOTES } from '../common/settingKeys';
14+
import { FILE_LIST_LAYOUT, PR_SETTINGS_NAMESPACE, QUERIES, QUERIES_REFRESH_INTERVAL, REMOTES } from '../common/settingKeys';
1515
import { ITelemetry } from '../common/telemetry';
1616
import { createPRNodeIdentifier } from '../common/uri';
1717
import { EXTENSION_ID } from '../constants';
@@ -47,6 +47,7 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
4747
private _initialized: boolean = false;
4848
private _notificationsProvider?: NotificationsManager;
4949
private _notificationClearTimeout: NodeJS.Timeout | undefined;
50+
private _autoRefreshTimer: NodeJS.Timeout | undefined;
5051

5152
get view(): vscode.TreeView<TreeNode> {
5253
return this._view;
@@ -94,6 +95,10 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
9495
clearTimeout(this._notificationClearTimeout);
9596
this._notificationClearTimeout = undefined;
9697
}
98+
if (this._autoRefreshTimer) {
99+
clearInterval(this._autoRefreshTimer);
100+
this._autoRefreshTimer = undefined;
101+
}
97102
}
98103
});
99104

@@ -150,6 +155,9 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
150155
if (e.affectsConfiguration(`${PR_SETTINGS_NAMESPACE}.${FILE_LIST_LAYOUT}`)) {
151156
this.refreshAll();
152157
}
158+
if (e.affectsConfiguration(`${PR_SETTINGS_NAMESPACE}.${QUERIES_REFRESH_INTERVAL}`)) {
159+
this.setupAutoRefresh();
160+
}
153161
}));
154162

155163
this._register(this._view.onDidChangeCheckboxState(e => TreeUtils.processCheckboxUpdates(e, [])));
@@ -160,6 +168,39 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
160168
this._register(this._view.onDidCollapseElement(collapsed => {
161169
this.prsTreeModel.updateExpandedQueries(collapsed.element, false);
162170
}));
171+
172+
// Initialize auto-refresh timer
173+
this.setupAutoRefresh();
174+
}
175+
176+
private setupAutoRefresh(): void {
177+
// Clear existing timer if any
178+
if (this._autoRefreshTimer) {
179+
clearInterval(this._autoRefreshTimer);
180+
this._autoRefreshTimer = undefined;
181+
}
182+
183+
// Get the refresh interval setting in minutes
184+
const config = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE);
185+
const intervalMinutes = config.get<number>(QUERIES_REFRESH_INTERVAL, 0);
186+
187+
// If interval is 0, auto-refresh is disabled
188+
if (intervalMinutes === 0) {
189+
return;
190+
}
191+
192+
// Enforce minimum of 5 minutes
193+
const actualIntervalMinutes = Math.max(intervalMinutes, 5);
194+
const intervalMs = actualIntervalMinutes * 60 * 1000;
195+
196+
// Set up the timer
197+
this._autoRefreshTimer = setInterval(() => {
198+
Logger.appendLine('Auto-refreshing pull requests queries', 'PullRequestsTreeDataProvider');
199+
this.prsTreeModel.forceClearCache();
200+
this.refreshAllQueryResults(true);
201+
}, intervalMs);
202+
203+
Logger.appendLine(`Auto-refresh enabled with interval of ${actualIntervalMinutes} minutes`, 'PullRequestsTreeDataProvider');
163204
}
164205

165206
private filterNotificationsToKnown(notifications: PullRequestModel[]): PullRequestModel[] {

0 commit comments

Comments
 (0)