From a61935fdfb02a43a5e684db65d5b5acac7ec04b7 Mon Sep 17 00:00:00 2001 From: AmirSa12 Date: Tue, 24 Feb 2026 12:47:40 +0330 Subject: [PATCH 01/24] init --- packages/app/app/components/Commits.vue | 106 +++++++++++++++---- packages/app/server/api/repo/branches.get.ts | 65 ++++++++++++ packages/app/server/api/repo/commits.get.ts | 10 +- 3 files changed, 159 insertions(+), 22 deletions(-) create mode 100644 packages/app/server/api/repo/branches.get.ts diff --git a/packages/app/app/components/Commits.vue b/packages/app/app/components/Commits.vue index f31a6241..b01b0b3b 100644 --- a/packages/app/app/components/Commits.vue +++ b/packages/app/app/components/Commits.vue @@ -12,32 +12,55 @@ const props = defineProps<{ repo: string; }>(); -const data = await $fetch("/api/repo/commits", { - query: { - owner: props.owner, - repo: props.repo, - }, -}); +type BranchesResponse = { + branches: string[]; +}; + +const [data, branchesResponse] = await Promise.all([ + $fetch("/api/repo/commits", { + query: { + owner: props.owner, + repo: props.repo, + }, + }), + $fetch("/api/repo/branches", { + query: { + owner: props.owner, + repo: props.repo, + }, + }).catch(() => null), +]); if (!data) { throw createError("Could not load Commits"); } const branch = shallowReactive(data); +const selectedBranch = ref(branch.name); +const availableBranches = ref( + branchesResponse?.branches?.length ? branchesResponse.branches : [branch.name], +); + +if (!availableBranches.value.includes(branch.name)) { + availableBranches.value.unshift(branch.name); +} const commitsWithRelease = computed(() => branch.target.history.nodes - .filter((commit) => - commit.statusCheckRollup?.contexts.nodes.some( - (context) => context.name === "Continuous Releases", - ), - ) - .map((commit) => ({ - ...commit, - release: commit.statusCheckRollup.contexts.nodes.find( + .flatMap((commit) => { + const release = commit.statusCheckRollup?.contexts.nodes.find( (context) => context.name === "Continuous Releases", - )!, - })), + ); + + return release + ? [ + { + ...commit, + release, + }, + ] + : []; + }), ); const selectedCommit = shallowRef< @@ -114,6 +137,39 @@ onBeforeUnmount(() => { // Pagination const fetching = ref(false); const fetchMoreForceDisabled = ref(!commitsWithRelease.value.length); +const switchingBranch = ref(false); + +async function loadBranch(branchName: string) { + if (switchingBranch.value) { + return; + } + + const previousBranch = branch.name; + + try { + switchingBranch.value = true; + selectedCommit.value = null; + + const result = await $fetch("/api/repo/commits", { + query: { + owner: props.owner, + repo: props.repo, + branch: branchName, + }, + }); + + Object.assign(branch, result); + fetchMoreForceDisabled.value = !commitsWithRelease.value.length; + } catch (error) { + selectedBranch.value = previousBranch; + } finally { + switchingBranch.value = false; + } +} + +async function onBranchChange() { + await loadBranch(selectedBranch.value); +} async function fetchMore() { if (!branch.target.history.pageInfo.hasNextPage) { @@ -133,6 +189,7 @@ async function fetchMore() { query: { owner: props.owner, repo: props.repo, + branch: selectedBranch.value, cursor, }, }); @@ -159,10 +216,23 @@ async function fetchMore() {