@@ -12,32 +12,55 @@ const props = defineProps<{
1212 repo: string ;
1313}>();
1414
15- const data = await $fetch (" /api/repo/commits" , {
16- query: {
17- owner: props .owner ,
18- repo: props .repo ,
19- },
20- });
15+ type BranchesResponse = {
16+ branches: string [];
17+ };
18+
19+ const [data, branchesResponse] = await Promise .all ([
20+ $fetch (" /api/repo/commits" , {
21+ query: {
22+ owner: props .owner ,
23+ repo: props .repo ,
24+ },
25+ }),
26+ $fetch <BranchesResponse >(" /api/repo/branches" , {
27+ query: {
28+ owner: props .owner ,
29+ repo: props .repo ,
30+ },
31+ }).catch (() => null ),
32+ ]);
2133
2234if (! data ) {
2335 throw createError (" Could not load Commits" );
2436}
2537
2638const branch = shallowReactive (data );
39+ const selectedBranch = ref (branch .name );
40+ const availableBranches = ref <string []>(
41+ branchesResponse ?.branches ?.length ? branchesResponse .branches : [branch .name ],
42+ );
43+
44+ if (! availableBranches .value .includes (branch .name )) {
45+ availableBranches .value .unshift (branch .name );
46+ }
2747
2848const commitsWithRelease = computed (() =>
2949 branch .target .history .nodes
30- .filter ((commit ) =>
31- commit .statusCheckRollup ?.contexts .nodes .some (
32- (context ) => context .name === " Continuous Releases" ,
33- ),
34- )
35- .map ((commit ) => ({
36- ... commit ,
37- release: commit .statusCheckRollup .contexts .nodes .find (
50+ .flatMap ((commit ) => {
51+ const release = commit .statusCheckRollup ?.contexts .nodes .find (
3852 (context ) => context .name === " Continuous Releases" ,
39- )! ,
40- })),
53+ );
54+
55+ return release
56+ ? [
57+ {
58+ ... commit ,
59+ release ,
60+ },
61+ ]
62+ : [];
63+ }),
4164);
4265
4366const selectedCommit = shallowRef <
@@ -114,6 +137,39 @@ onBeforeUnmount(() => {
114137// Pagination
115138const fetching = ref (false );
116139const fetchMoreForceDisabled = ref (! commitsWithRelease .value .length );
140+ const switchingBranch = ref (false );
141+
142+ async function loadBranch(branchName : string ) {
143+ if (switchingBranch .value ) {
144+ return ;
145+ }
146+
147+ const previousBranch = branch .name ;
148+
149+ try {
150+ switchingBranch .value = true ;
151+ selectedCommit .value = null ;
152+
153+ const result = await $fetch (" /api/repo/commits" , {
154+ query: {
155+ owner: props .owner ,
156+ repo: props .repo ,
157+ branch: branchName ,
158+ },
159+ });
160+
161+ Object .assign (branch , result );
162+ fetchMoreForceDisabled .value = ! commitsWithRelease .value .length ;
163+ } catch (error ) {
164+ selectedBranch .value = previousBranch ;
165+ } finally {
166+ switchingBranch .value = false ;
167+ }
168+ }
169+
170+ async function onBranchChange() {
171+ await loadBranch (selectedBranch .value );
172+ }
117173
118174async function fetchMore() {
119175 if (! branch .target .history .pageInfo .hasNextPage ) {
@@ -133,6 +189,7 @@ async function fetchMore() {
133189 query: {
134190 owner: props .owner ,
135191 repo: props .repo ,
192+ branch: selectedBranch .value ,
136193 cursor ,
137194 },
138195 });
@@ -159,10 +216,23 @@ async function fetchMore() {
159216
160217<template >
161218 <div class =" flex flex-col gap-6" >
162- <div class =" text-center flex justify-center items-center gap-1 opacity-80" >
219+ <div class =" text-center flex justify-center items-center gap-2 opacity-80" >
163220 Continuous Releases from
164221 <UIcon name =" i-ph-git-branch" />
165- {{ branch.name }}
222+ <select
223+ v-model =" selectedBranch"
224+ class =" px-2 py-1 rounded-md bg-transparent border border-gray-300 dark:border-gray-700 text-sm"
225+ :disabled =" switchingBranch"
226+ @change =" onBranchChange"
227+ >
228+ <option
229+ v-for =" branchName of availableBranches"
230+ :key =" branchName"
231+ :value =" branchName"
232+ >
233+ {{ branchName }}
234+ </option >
235+ </select >
166236 </div >
167237
168238 <div class =" flex flex-col gap-2" >
0 commit comments