mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
add branch search param, with branch validation, fallback to default branch
This commit is contained in:
@@ -71,3 +71,19 @@ export async function getBranches(owner: string, name: string): Promise<string[]
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function validateBranch(
|
||||
owner: string,
|
||||
repo: string,
|
||||
branch: string
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://api.github.com/repos/${owner}/${repo}/branches/${encodeURIComponent(branch)}`
|
||||
);
|
||||
return response.ok;
|
||||
} catch (error) {
|
||||
console.error('Failed to validate branch from GitHub:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+20
-8
@@ -17,7 +17,7 @@
|
||||
import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store';
|
||||
import { iconPath } from '$lib/stores/app';
|
||||
import type { PageData } from './$types';
|
||||
import { getDefaultBranch, getBranches } from '$lib/helpers/github';
|
||||
import { getDefaultBranch, getBranches, validateBranch } from '$lib/helpers/github';
|
||||
import { writable } from 'svelte/store';
|
||||
import Link from '$lib/elements/link.svelte';
|
||||
|
||||
@@ -85,18 +85,30 @@
|
||||
if (data.repository?.owner && data.repository?.name) {
|
||||
loadingBranches = true;
|
||||
try {
|
||||
const [branchList, defaultBranch] = await Promise.all([
|
||||
// Check for branch param from URL
|
||||
const branchParam = page.url.searchParams.get('branch');
|
||||
|
||||
const [branchList, defaultBranch, isBranchValid] = await Promise.all([
|
||||
getBranches(data.repository.owner, data.repository.name),
|
||||
getDefaultBranch(data.repository.owner, data.repository.name)
|
||||
getDefaultBranch(data.repository.owner, data.repository.name),
|
||||
branchParam
|
||||
? validateBranch(data.repository.owner, data.repository.name, branchParam)
|
||||
: Promise.resolve(false)
|
||||
]);
|
||||
|
||||
if (branchList && branchList.length > 0) {
|
||||
branches = branchList;
|
||||
// Pre-select default branch, or first branch if default not found
|
||||
selectedBranch =
|
||||
defaultBranch && branchList.includes(defaultBranch)
|
||||
? defaultBranch
|
||||
: branchList[0];
|
||||
|
||||
if (branchParam && isBranchValid) {
|
||||
// Use the provided branch if it's valid
|
||||
selectedBranch = branchParam;
|
||||
} else {
|
||||
// Fall back to default branch, or first branch if default not found
|
||||
selectedBranch =
|
||||
defaultBranch && branchList.includes(defaultBranch)
|
||||
? defaultBranch
|
||||
: branchList[0];
|
||||
}
|
||||
} else {
|
||||
// Branch list is empty or null
|
||||
addNotification({
|
||||
|
||||
+20
-8
@@ -19,7 +19,7 @@
|
||||
import { iconPath } from '$lib/stores/app';
|
||||
import type { PageData } from './$types';
|
||||
import { writable } from 'svelte/store';
|
||||
import { getDefaultBranch, getBranches } from '$lib/helpers/github';
|
||||
import { getDefaultBranch, getBranches, validateBranch } from '$lib/helpers/github';
|
||||
import Link from '$lib/elements/link.svelte';
|
||||
|
||||
let {
|
||||
@@ -125,18 +125,30 @@
|
||||
if (data.repository?.owner && data.repository?.name) {
|
||||
loadingBranches = true;
|
||||
try {
|
||||
const [branchList, defaultBranch] = await Promise.all([
|
||||
// Check for branch param from URL
|
||||
const branchParam = page.url.searchParams.get('branch');
|
||||
|
||||
const [branchList, defaultBranch, isBranchValid] = await Promise.all([
|
||||
getBranches(data.repository.owner, data.repository.name),
|
||||
getDefaultBranch(data.repository.owner, data.repository.name)
|
||||
getDefaultBranch(data.repository.owner, data.repository.name),
|
||||
branchParam
|
||||
? validateBranch(data.repository.owner, data.repository.name, branchParam)
|
||||
: Promise.resolve(false)
|
||||
]);
|
||||
|
||||
if (branchList && branchList.length > 0) {
|
||||
branches = branchList;
|
||||
// Pre-select default branch, or first branch if default not found
|
||||
selectedBranch =
|
||||
defaultBranch && branchList.includes(defaultBranch)
|
||||
? defaultBranch
|
||||
: branchList[0];
|
||||
|
||||
if (branchParam && isBranchValid) {
|
||||
// Use the provided branch if it's valid
|
||||
selectedBranch = branchParam;
|
||||
} else {
|
||||
// Fall back to default branch, or first branch if default not found
|
||||
selectedBranch =
|
||||
defaultBranch && branchList.includes(defaultBranch)
|
||||
? defaultBranch
|
||||
: branchList[0];
|
||||
}
|
||||
} else {
|
||||
// Branch list is empty or null
|
||||
addNotification({
|
||||
|
||||
@@ -113,6 +113,7 @@
|
||||
const install = currentUrl.searchParams.get('install');
|
||||
const build = currentUrl.searchParams.get('build');
|
||||
const rootDir = currentUrl.searchParams.get('rootDir');
|
||||
const branch = currentUrl.searchParams.get('branch');
|
||||
|
||||
if (entrypoint) url.searchParams.set('entrypoint', entrypoint);
|
||||
if (install) url.searchParams.set('install', install);
|
||||
@@ -122,6 +123,7 @@
|
||||
'rootDir',
|
||||
rootDir || data.deploymentData.repository.rootDirectory
|
||||
);
|
||||
if (branch) url.searchParams.set('branch', branch);
|
||||
|
||||
if (data.envKeys.length > 0) {
|
||||
url.searchParams.set('env', data.envKeys.join(','));
|
||||
|
||||
@@ -120,11 +120,13 @@
|
||||
const install = currentUrl.searchParams.get('install');
|
||||
const build = currentUrl.searchParams.get('build');
|
||||
const output = currentUrl.searchParams.get('output');
|
||||
const branch = currentUrl.searchParams.get('branch');
|
||||
|
||||
if (preset) url.searchParams.set('preset', preset);
|
||||
if (install) url.searchParams.set('install', install);
|
||||
if (build) url.searchParams.set('build', build);
|
||||
if (output) url.searchParams.set('output', output);
|
||||
if (branch) url.searchParams.set('branch', branch);
|
||||
}
|
||||
|
||||
if (data.envKeys.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user