Skip to content

Commit ba6227c

Browse files
Copilotalexr00
andauthored
Add autoRepositoryDetection setting to control repository scope (#8501)
* Initial plan * Initial plan for autoRepositoryDetection setting Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Add autoRepositoryDetection setting implementation Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Revert proposals --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 148c313 commit ba6227c

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,18 @@
180180
},
181181
"markdownDescription": "%githubPullRequests.remotes.markdownDescription%"
182182
},
183+
"githubPullRequests.autoRepositoryDetection": {
184+
"markdownDescription": "%githubPullRequests.autoRepositoryDetection.markdownDescription%",
185+
"default": "workspace",
186+
"enum": [
187+
"workspace",
188+
true
189+
],
190+
"markdownEnumDescriptions": [
191+
"%githubPullRequests.autoRepositoryDetection.workspace%",
192+
"%githubPullRequests.autoRepositoryDetection.true%"
193+
]
194+
},
183195
"githubPullRequests.includeRemotes": {
184196
"type": "string",
185197
"enum": [

package.nls.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
"githubPullRequests.codingAgent.autoCommitAndPush.description": "Allow automatic git operations (commit, push) to be performed when starting a coding agent session.",
2828
"githubPullRequests.codingAgent.promptForConfirmation.description": "Prompt for confirmation before initiating a coding agent session from the UI integration.",
2929
"githubPullRequests.remotes.markdownDescription": "List of remotes, by name, to fetch pull requests from.",
30+
"githubPullRequests.autoRepositoryDetection.markdownDescription": "Controls which repositories are automatically detected and opened by the extension.",
31+
"githubPullRequests.autoRepositoryDetection.workspace": "Only detect repositories within the current workspace folders.",
32+
"githubPullRequests.autoRepositoryDetection.true": "Detect all repositories found by the Git extension, including those outside workspace folders.",
3033
"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```",
3134
"githubPullRequests.queries.label.description": "The label to display for the query in the Pull Requests tree.",
3235
"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.",

src/common/settingKeys.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export type PullPRBranchVariants = 'never' | 'pull' | 'pullAndMergeBase' | 'pull
4343
export const UPSTREAM_REMOTE = 'upstreamRemote';
4444
export const DEFAULT_CREATE_OPTION = 'defaultCreateOption';
4545
export const CREATE_BASE_BRANCH = 'createDefaultBaseBranch';
46+
export const AUTO_REPO_DETECTION = 'autoRepositoryDetection';
47+
export type AutoRepoDetectionVariants = 'workspace' | true;
4648

4749
export const ISSUES_SETTINGS_NAMESPACE = 'githubIssues';
4850
export const ASSIGN_WHEN_WORKING = 'assignWhenWorking';

src/extension.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { isSubmodule } from './common/gitUtils';
1515
import Logger from './common/logger';
1616
import * as PersistentState from './common/persistentState';
1717
import { parseRepositoryRemotes } from './common/remote';
18-
import { BRANCH_PUBLISH, EXPERIMENTAL_CHAT, FILE_LIST_LAYOUT, GIT, IGNORE_SUBMODULES, OPEN_DIFF_ON_CLICK, PR_SETTINGS_NAMESPACE, SHOW_INLINE_OPEN_FILE_ACTION } from './common/settingKeys';
18+
import { AUTO_REPO_DETECTION, AutoRepoDetectionVariants, BRANCH_PUBLISH, EXPERIMENTAL_CHAT, FILE_LIST_LAYOUT, GIT, IGNORE_SUBMODULES, OPEN_DIFF_ON_CLICK, PR_SETTINGS_NAMESPACE, SHOW_INLINE_OPEN_FILE_ACTION } from './common/settingKeys';
1919
import { initBasedOnSettingChange } from './common/settingsUtils';
2020
import { TemporaryState } from './common/temporaryState';
2121
import { Schemes } from './common/uri';
@@ -237,13 +237,20 @@ async function init(
237237
reviewsManager.addReviewManager(newReviewManager);
238238
}
239239

240-
// Check if repo is in one of the workspace folders or vice versa
241-
Logger.debug(`Checking if repo ${repo.rootUri.fsPath} is in a workspace folder.`, ACTIVATION);
242-
Logger.debug(`Workspace folders: ${workspaceFolders?.map(folder => folder.uri.fsPath).join(', ')}`, ACTIVATION);
243-
if (workspaceFolders && !workspaceFolders.some(folder => isDescendant(folder.uri.fsPath, repo.rootUri.fsPath, true) || isDescendant(repo.rootUri.fsPath, folder.uri.fsPath, true))) {
244-
Logger.appendLine(`Repo ${repo.rootUri} is not in a workspace folder, ignoring.`, ACTIVATION);
245-
return;
240+
const detectionMode = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<AutoRepoDetectionVariants>(AUTO_REPO_DETECTION, 'workspace');
241+
const shouldFilterByWorkspace = detectionMode === 'workspace';
242+
243+
if (shouldFilterByWorkspace) {
244+
Logger.debug(`Checking if repo ${repo.rootUri.fsPath} is in a workspace folder.`, ACTIVATION);
245+
Logger.debug(`Workspace folders: ${workspaceFolders?.map(folder => folder.uri.fsPath).join(', ')}`, ACTIVATION);
246+
if (workspaceFolders && !workspaceFolders.some(folder => isDescendant(folder.uri.fsPath, repo.rootUri.fsPath, true) || isDescendant(repo.rootUri.fsPath, folder.uri.fsPath, true))) {
247+
Logger.appendLine(`Repo ${repo.rootUri} is not in a workspace folder, ignoring.`, ACTIVATION);
248+
return;
249+
}
250+
} else {
251+
Logger.debug(`Auto-detection is enabled for all Git repositories.`, ACTIVATION);
246252
}
253+
247254
addRepo();
248255
const disposable = repo.state.onDidChange(() => {
249256
Logger.appendLine(`Repo state for ${repo.rootUri} changed.`, ACTIVATION);

0 commit comments

Comments
 (0)