Skip to content

Commit f769d39

Browse files
committed
feat: add pagination to checkout to command
1 parent 9734dd5 commit f769d39

File tree

4 files changed

+47
-25
lines changed

4 files changed

+47
-25
lines changed

extensions/github1s/src/adapters/github1s/data-source.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ export class GitHub1sDataSource extends DataSource {
127127
const { owner, repo } = parseRepoFullName(repoFullName);
128128
const requestParams = { owner, repo, ref };
129129
const { data } = await fetcher.request('GET /repos/{owner}/{repo}/git/matching-refs/{ref}', requestParams);
130-
return data.map((item) => ({ name: item.ref.slice(ref === 'heads' ? 11 : 10), commitSha: item.object.sha }));
130+
return data.map((item) => ({
131+
name: item.ref.slice(ref === 'heads' ? 11 : 10),
132+
commitSha: item.object.sha,
133+
description: `${ref === 'heads' ? 'Branch' : 'Tag'} at ${item.object.sha.slice(0, 8)}`,
134+
}));
131135
}
132136
);
133137

extensions/github1s/src/adapters/sourcegraph/ref.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ export const getAllRefs = async (repository: string): Promise<{ branches: Branch
4343
const branches = (repositoryData.branches?.nodes || []).map?.((branch) => ({
4444
name: branch.displayName,
4545
commitSha: branch.target?.commit?.oid,
46+
description: `Branch at ${branch.target?.commit?.oid?.slice(0, 8)}`,
4647
}));
4748
const tags = (repositoryData.tags?.nodes || []).map?.((tag) => ({
4849
name: tag?.displayName,
4950
commitSha: tag?.target?.commit?.oid,
51+
description: `Tag at ${tag?.target?.commit?.oid?.slice(0, 8)}`,
5052
}));
5153
return { branches, tags };
5254
};

extensions/github1s/src/adapters/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ export interface SymbolicLink {
4242

4343
export interface Branch {
4444
name: string;
45-
commitSha: string;
45+
commitSha?: string;
46+
description?: string;
4647
}
4748

4849
export interface Tag {
4950
name: string;
50-
commitSha: string;
51+
commitSha?: string;
52+
description?: string;
5153
}
5254

5355
export type CommitsQueryOptions = { from?: string; author?: string; path?: string } & CommonQueryOptions;

extensions/github1s/src/commands/ref.ts

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,52 @@ import router from '@/router';
88
import { adapterManager } from '@/adapters';
99
import { Repository } from '@/repository';
1010

11+
const loadMorePickerItem: vscode.QuickPickItem = {
12+
label: '$(more) Load More',
13+
alwaysShow: true,
14+
};
15+
16+
const checkoutToItem: vscode.QuickPickItem = {
17+
label: '$(debug-disconnect) Checkout detached',
18+
alwaysShow: true,
19+
};
20+
1121
// check out to branch/tag/commit
1222
const commandCheckoutTo = async () => {
1323
const routerParser = await router.resolveParser();
1424
const routeState = await router.getState();
15-
16-
const scheme = adapterManager.getCurrentScheme();
17-
const repository = Repository.getInstance(scheme, routeState.repo);
18-
const [branchRefs, tagRefs] = await Promise.all([repository.getBranchList(), repository.getTagList()]);
19-
const branchPickerItems: vscode.QuickPickItem[] = branchRefs.map((branchRef) => ({
20-
label: branchRef.name,
21-
description: (branchRef.commitSha || '').slice(0, 8),
22-
}));
23-
const tagPickerItems: vscode.QuickPickItem[] = tagRefs.map((tagRef) => ({
24-
label: tagRef.name,
25-
description: `Tag at ${(tagRef.commitSha || '').slice(0, 8)}`,
26-
}));
27-
2825
const quickPick = vscode.window.createQuickPick();
29-
quickPick.placeholder = routeState.ref;
30-
quickPick.items = [...branchPickerItems, ...tagPickerItems];
3126

27+
const loadMoreRefPickerItems = async () => {
28+
quickPick.busy = true;
29+
const scheme = adapterManager.getCurrentScheme();
30+
const repository = Repository.getInstance(scheme, routeState.repo);
31+
await Promise.all([repository.loadMoreBranches(), repository.loadMoreTags()]);
32+
const [branchRefs, tagRefs] = await Promise.all([repository.getBranchList(), repository.getTagList()]);
33+
const refPickerItems = [...branchRefs, ...tagRefs].map((ref) => ({
34+
label: ref.name,
35+
description: ref.description,
36+
}));
37+
const hasMore = (await Promise.all([repository.hasMoreBranches(), repository.hasMoreTags()])).some(Boolean);
38+
quickPick.items = [...refPickerItems, hasMore ? loadMorePickerItem : null!, checkoutToItem].filter(Boolean);
39+
quickPick.busy = false;
40+
};
41+
42+
quickPick.placeholder = 'Input a ref to checkout';
43+
quickPick.items = [checkoutToItem];
44+
loadMoreRefPickerItems();
3245
quickPick.show();
33-
const choice = await new Promise<vscode.QuickPickItem | undefined>((resolve) =>
34-
quickPick.onDidAccept(() => resolve(quickPick.activeItems[0]))
35-
);
36-
quickPick.hide();
3746

38-
const selectedRef = choice?.label || quickPick.value;
39-
if (selectedRef) {
47+
quickPick.onDidAccept(async () => {
48+
const choice = quickPick.activeItems[0];
49+
if (choice === loadMorePickerItem) {
50+
return loadMoreRefPickerItems();
51+
}
52+
const selectedRef = choice === checkoutToItem ? quickPick.value : choice?.label;
4053
const targetRef = selectedRef.toUpperCase() !== 'HEAD' ? selectedRef : undefined;
4154
router.push(await routerParser.buildTreePath(routeState.repo, targetRef));
42-
}
55+
quickPick.hide();
56+
});
4357
};
4458

4559
export const registerRefCommands = (context: vscode.ExtensionContext) => {

0 commit comments

Comments
 (0)