Skip to content

Commit 3b5839a

Browse files
authored
Refresh PR tree when repos are discovered after initial load (#7989)
1 parent d37dac6 commit 3b5839a

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/test/view/prsTree.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,40 @@ describe('GitHub Pull Requests view', function () {
141141
);
142142
});
143143

144+
it('refreshes tree when GitHub repositories are discovered in existing folder manager', async function () {
145+
const repository = new MockRepository();
146+
repository.addRemote('origin', 'git@github.com:aaa/bbb');
147+
const folderManager = new FolderRepositoryManager(0, context, repository, telemetry, new GitApiImpl(reposManager), credentialStore, createPrHelper, mockThemeWatcher);
148+
sinon.stub(folderManager, 'getPullRequestDefaults').returns(Promise.resolve({ owner: 'aaa', repo: 'bbb', base: 'main' }));
149+
reposManager.insertFolderManager(folderManager);
150+
provider.initialize([], mockNotificationsManager as NotificationsManager);
151+
152+
// Initially no children because no GitHub repositories are loaded yet
153+
let rootNodes = await provider.getChildren();
154+
assert.strictEqual(rootNodes.length, 0);
155+
156+
// Listen to the prsTreeModel's onDidChangeData event which is what actually drives the tree refresh
157+
const onDidChangeDataSpy = sinon.spy();
158+
provider.prsTreeModel.onDidChangeData(onDidChangeDataSpy);
159+
160+
// Simulate GitHub repositories being discovered (as happens when remotes load after activation)
161+
sinon.stub(credentialStore, 'isAuthenticated').returns(true);
162+
await folderManager.updateRepositories();
163+
164+
// Verify that the tree model's data change event was triggered
165+
assert(onDidChangeDataSpy.calledWith(folderManager),
166+
'Tree model should fire data change event with the folder manager when GitHub repositories are discovered');
167+
168+
// Verify tree now has content
169+
rootNodes = await provider.getChildren();
170+
const treeItems = await Promise.all(rootNodes.map(node => node.getTreeItem()));
171+
assert.deepStrictEqual(
172+
treeItems.map(n => n.label),
173+
['Copilot on My Behalf', 'Local Pull Request Branches', 'Waiting For My Review', 'Created By Me', 'All Open'],
174+
'Tree should display categories after GitHub repositories are discovered',
175+
);
176+
});
177+
144178
describe('Local Pull Request Branches', function () {
145179
it('creates a node for each local pull request', async function () {
146180
const url = 'git@github.com:aaa/bbb';

src/view/prsTreeModel.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ export class PrsTreeModel extends Disposable {
118118
}
119119
}));
120120

121+
this._register(this._reposManager.onDidChangeAnyGitHubRepository((folderManager) => {
122+
this._onDidChangeData.fire(folderManager);
123+
}));
124+
121125
const expandedQueries = this._context.workspaceState.get(EXPANDED_QUERIES_STATE, undefined);
122126
if (expandedQueries) {
123127
this._expandedQueries = new Set(expandedQueries);

0 commit comments

Comments
 (0)