import { CheckIcon, ChevronDownIcon, GitBranchIcon, GitPullRequestIcon, Loader2Icon, LockIcon, PlusIcon, RefreshCwIcon, Settings2Icon, } from "lucide-react"; import { useEffect, useRef, useState, type ReactNode } from "react"; import { useAppHost } from "../lib/app-host"; import { toast } from "../lib/toast"; import { REPOSITORY_PANEL_CLASS } from "./repository-picker-layout"; import { ComposerMenuHeader, ComposerMenuRowsSkeleton, ComposerMenuSwitch, } from "../../ui/composer-menu"; import { MENU_BUTTON_CLASS, MENU_LABEL_CLASS, MENU_NOTE_CLASS } from "../../ui/menu-styles"; import { ManualRepositoryEditor, type ManualRepositoryAttachResult, } from "./manual-repository-editor"; import { RepositoryRefInput } from "./repository-ref-input"; import { Button } from "../../ui/button"; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "../../ui/collapsible"; import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from "../../ui/dropdown-menu"; import { Input } from "../../ui/input"; import { Label } from "../../ui/label"; import { MetaChip } from "../../ui/meta-chip"; import { SegmentedControl } from "../../ui/segmented-control"; import { userErrorText } from "../../ui/api-error"; import { ErrorText } from "../../ui/error-text"; import { repoCountLabel } from "../lib/format"; import { attachedManualRepositoryCount } from "../lib/manual-repositories"; import { gitHubRepositoryResource, isRepositoryResourceForGitHubRepo, sameRepositoryUri, type RepoDraft, type RepositoryGroup, } from "../lib/session-tools"; import { cn } from "../lib/utils"; import type { GitHubAppSetupMode, GitHubBindingStatus, GitHubInstallationBinding, GitHubRepository, PersonalGitHubConnectionStatusResponse, PersonalGitHubRepositoryCatalogItem, ResourceRef, } from "../types"; export function repositoryBindingPresentation( status: GitHubBindingStatus, installUrl: string | null, setupMode: GitHubAppSetupMode = "operator", ): { setupDescription: string; emptyDescription: string; connectUrl: string | null; connectLabel: string; healthy: boolean; canRefresh: boolean; } { if (status === "bound") { return { setupDescription: setupMode === "platform" ? "This workspace is connected to Opengeni's managed GitHub App." : "This workspace has a live GitHub App binding with an explicit repository allowlist.", emptyDescription: "The Opengeni app is installed, but no repositories are shared with this workspace yet.", connectUrl: installUrl, connectLabel: "Install on another account", healthy: true, canRefresh: true, }; } if (status === "unbound") { return { setupDescription: setupMode === "platform" ? "Install Opengeni on a GitHub account you own, or connect an existing installation." : "GitHub App server credentials are configured, but this workspace has no usable installation binding.", emptyDescription: setupMode === "platform" ? "Connect as the personal account owner or an organization owner. GitHub repository administrators and collaborators cannot connect an installation." : "GitHub App server credentials exist, but this workspace has no active installation binding. Connect as the personal owner or an organization owner; repository administrators and collaborators cannot bind.", connectUrl: installUrl, connectLabel: setupMode === "platform" ? "Install" : "Connect workspace App", healthy: false, canRefresh: false, }; } return { setupDescription: setupMode === "platform" ? "GitHub is temporarily unavailable for this Opengeni deployment." : "Create a prefilled app, add the generated values to your .env, then restart the API and worker.", emptyDescription: setupMode === "platform" ? "GitHub integration is unavailable for this Opengeni deployment." : "GitHub App server credentials are not configured. App registration alone does not connect repositories.", connectUrl: null, connectLabel: "Connect GitHub", healthy: false, canRefresh: false, }; } export type RepositoryContextPickerProps = { setupMode: GitHubAppSetupMode; configured: boolean; status: GitHubBindingStatus; installUrl: string | null; linkUrl: string | null; installations: GitHubInstallationBinding[]; repositories: GitHubRepository[]; personalGitHubStatus?: PersonalGitHubConnectionStatusResponse | null | undefined; personalGitHubRepositories?: PersonalGitHubRepositoryCatalogItem[] | undefined; selectedPersonalGitHubRepoIds?: Set | undefined; selectedPersonalGitHubRepoRefs?: Record | undefined; personalGitHubBusy?: boolean | undefined; onConnectPersonalGitHub?: (() => void) | undefined; onTogglePersonalGitHubRepo?: ((repo: PersonalGitHubRepositoryCatalogItem) => void) | undefined; onPersonalGitHubRefChange?: ((repositoryId: string, ref: string) => void) | undefined; groups: RepositoryGroup[]; selectedRepoIds: Set; selectedRepoRefs: Record; manualRepos: RepoDraft[]; manualOpen: boolean; org: string; pending: boolean; repoBusy: boolean; /** * The workspace's GitHub status or repository list failed to load and no * earlier list is shown. The menu says so instead of offering setup. */ githubLoadFailed?: boolean | undefined; /** * A later refresh failed while the earlier list is still shown. The menu * keeps the list and says it couldn't update it, with "Try again". */ githubUpdateFailed?: boolean | undefined; githubAppBusy: boolean; /** * Reloads both catalogs now (a manager's reload also syncs from GitHub). The * list refreshes itself on open and after GitHub flows; this backs the * "Try again" shown after a failed load. */ onRefresh: () => Promise; /** Passive open refresh. Caller owns provider-sync permissions and throttling. */ onOpenRefresh?: (() => Promise) | undefined; /** * The person is leaving to change GitHub access (on GitHub or the GitHub * settings page). The caller refreshes both catalogs, unthrottled, once they * are back. */ onLeaveForGitHub?: (() => void) | undefined; /** False when the current principal cannot read either repository catalog. */ refreshAllowed?: boolean | undefined; onToggleRepo: (repo: GitHubRepository) => void; onRefChange: (repoId: number, ref: string) => void; onManualOpenChange: (open: boolean) => void; onManualAdd: () => void; onManualUpdate: (id: number, patch: Partial) => void; onManualRemove: (id: number) => void; onManualAttach?: ((repository: RepoDraft) => Promise) | undefined; onLoadGitHubBranches?: | ((repository: GitHubRepository) => Promise) | undefined; onLoadPersonalGitHubBranches?: | (( repository: PersonalGitHubRepositoryCatalogItem, ) => Promise) | undefined; onOrgChange: (value: string) => void; onStartGitHubApp: () => void; /** * Starts workspace App setup. The link is minted on click: `installUrl` only * gates whether this principal may connect, because a page-load link expires. */ onConnectWorkspaceApp: () => void; /** Repositories already mounted on an additive surface cannot be removed or retargeted. */ lockedRepoIds?: ReadonlySet | undefined; /** Opens the chooser for which personal repositories Opengeni may use. */ personalGitHubManageUrl?: string | undefined; /** * The workspace's GitHub settings, where people manage both ways of * connecting (their own GitHub and the Opengeni app): repositories, * installations and unlinking. The picker links here once anything is connected. */ githubSettingsUrl?: string | undefined; /** Personal repositories already mounted on an additive surface cannot be removed or retargeted. */ lockedPersonalGitHubRepoIds?: ReadonlySet | undefined; /** Manual rows already mounted on an additive surface are rendered read-only. */ lockedManualRepoIds?: ReadonlySet | undefined; /** Mounted personal sources may outlive their currently authorized catalog entry. */ unavailableMountedRepositories?: ReadonlyArray<{ uri: string; ref: string }> | undefined; /** * Switching a mounted repository off asks to remove it from the chat. Without * it, mounted repositories stay locked. */ onRemoveMountedRepository?: ((target: MountedRepositoryTarget) => void) | undefined; /** Inline validation for pending manual repository additions. */ validationError?: string | null | undefined; /** New-chat route used to explain immutable mounted follow-up resources. */ newChatUrl?: string | undefined; /** Optional back control when embedded in the mobile “+” drill-in. */ leading?: ReactNode | undefined; /** Extra classes on the bar trigger (e.g. `max-sm:hidden` when opened from +). */ triggerClassName?: string | undefined; }; /** A mounted repository row the person switched off. */ export type MountedRepositoryTarget = | { kind: "app"; repository: GitHubRepository } | { kind: "personal"; repository: PersonalGitHubRepositoryCatalogItem } | { kind: "uri"; uri: string }; /** Shared picker body — desktop dropdown and mobile “+” drill-in. */ export function RepositoryContextMenuBody(props: RepositoryContextPickerProps) { const [search, setSearch] = useState(""); const [refreshError, setRefreshError] = useState(null); const [refreshBusy, setRefreshBusy] = useState(false); const refreshedOnOpen = useRef(false); const openRefresh = useRef(props.onOpenRefresh); openRefresh.current = props.onOpenRefresh; useEffect(() => { let active = true; void Promise.resolve() .then(() => { if (!active || refreshedOnOpen.current || !openRefresh.current) return; refreshedOnOpen.current = true; return openRefresh.current(); }) .catch((error: unknown) => { if (active) setRefreshError(userErrorText(error)); }); return () => { active = false; }; }, []); const matchesSearch = (name: string) => name.toLowerCase().includes(search.trim().toLowerCase()); const personalRepositories = (props.personalGitHubRepositories ?? []).filter( (repository) => repository.selectedAccess !== null, ); const manualCount = attachedManualRepositoryCount(props.manualRepos); const hasRepos = props.repositories.length > 0; const bindingPresentation = repositoryBindingPresentation( props.status, props.installUrl, props.setupMode, ); const loadFailed = props.githubLoadFailed === true && !hasRepos && !props.repoBusy; const updateFailed = props.githubUpdateFailed === true && !props.repoBusy && !refreshBusy; const canRefresh = props.refreshAllowed !== false && (bindingPresentation.canRefresh || loadFailed || props.personalGitHubStatus?.enabled === true); async function refreshList() { if (!canRefresh || props.repoBusy || refreshBusy) return; setRefreshBusy(true); setRefreshError(null); try { await props.onRefresh(); } catch (error) { setRefreshError(userErrorText(error)); } finally { setRefreshBusy(false); } } const personalEnabled = props.personalGitHubStatus?.enabled === true; const personalActive = personalEnabled && props.personalGitHubStatus?.connection?.status === "active"; const personalLogin = personalActive ? githubLoginLabel(props.personalGitHubStatus?.connection?.metadata.githubLogin) : null; const allRowGroups = repositoryPickerRowGroups(props.groups, personalRepositories); const rowGroups = allRowGroups.flatMap((group) => { const rows = group.rows.filter((row) => matchesSearch(row.fullName)); return rows.length > 0 ? [{ ...group, rows }] : []; }); const appBound = props.status === "bound"; // Nothing to pick yet: the ways to get repositories are the main content. const onboarding = allRowGroups.length === 0 && !props.repoBusy && !loadFailed; // A hosted workspace without the app gets one plain prompt, not the binding note. const connectPrompt = onboarding && props.setupMode === "platform" && props.status === "unbound"; // Account management (choosing repositories, installing on more accounts, // unlinking) lives on the GitHub settings page; the picker links there once // anything is connected. const manageVisible = Boolean(props.githubSettingsUrl) && (personalActive || appBound || props.installations.length > 0 || loadFailed); const onboardingEntries: ReactNode[] = []; if (onboarding && personalEnabled) { onboardingEntries.push(
Your GitHub
{personalActive ? `${personalLogin} · ${repoCountLabel(personalRepositories.length)}` : "Work appears under your name."}
{personalActive ? ( props.personalGitHubManageUrl ? ( ) : null ) : ( )}
, ); } const operatorSetup = props.setupMode === "operator" && !props.configured; // An operator without the app yet keeps Create app even once other repositories are listed. if ( (onboarding && !appBound && (props.setupMode === "operator" || props.status === "unbound")) || (operatorSetup && !loadFailed) ) { const connectable = Boolean(bindingPresentation.connectUrl); onboardingEntries.push(
Opengeni app
{props.setupMode === "operator" ? bindingPresentation.setupDescription : connectable ? "Work appears as the Opengeni bot, shared with the workspace." : "A workspace admin can install it."}
{connectable && !operatorSetup ? ( ) : null}
{operatorSetup ? (
props.onOrgChange(event.target.value)} placeholder="Optional org login" disabled={props.githubAppBusy} className="mt-1 h-8 text-xs" />
) : null}
, ); } return (
event.stopPropagation()} className="flex min-h-0 flex-1 flex-col">
{props.repositories.length + (props.personalGitHubRepositories?.length ?? 0) > 5 ? ( setSearch(event.target.value)} className="h-8 text-xs" /> ) : null} {search.trim() && !props.repositories.some((repo) => matchesSearch(repo.fullName)) && !personalRepositories.some((repo) => matchesSearch(repo.fullName)) ? (

No repositories match your search.

) : null} {rowGroups.length > 0 ? (
{rowGroups.map((group) => (
{group.label}
{group.rows.map((row) => ( ))}
))}
) : null} {personalActive && props.personalGitHubBusy && personalRepositories.length === 0 ? (
Loading your repositories
) : null} {hasRepos ? null : loadFailed ? (

Couldn't load GitHub

{canRefresh ? ( void refreshList()} disabled={refreshBusy} /> ) : ( "Your repositories show here once it loads." )}

) : props.repoBusy ? ( // First load only: rows that hold the menu's size. A refresh with // repositories already listed updates them in place, quietly. allRowGroups.length > 0 ? null : ( ) ) : allRowGroups.length === 0 && !(personalActive && props.personalGitHubBusy) ? ( connectPrompt ? (

Connect GitHub to pick repositories.

) : (

No repositories connected

{bindingPresentation.emptyDescription}

) ) : null} {onboardingEntries.length > 0 ? (
{onboardingEntries}
) : null} {props.unavailableMountedRepositories?.map((repo) => (
{repo.uri}
{repo.ref} ·{" "} {personalActive ? "No longer shared" : personalEnabled && props.personalGitHubStatus?.connection && !props.personalGitHubBusy ? "Reconnect your GitHub" : "Unavailable"}
{props.onRemoveMountedRepository ? null : ( props.onRemoveMountedRepository?.({ kind: "uri", uri: repo.uri }) } />
))} {props.manualRepos .filter((repo) => props.lockedManualRepoIds?.has(repo.id)) .map((repo) => (
{repo.url}
{repo.ref}
{props.onRemoveMountedRepository ? null : ( props.onRemoveMountedRepository?.({ kind: "uri", uri: repo.url }) } />
))} {props.manualRepos.length === 0 ? ( ) : (
{props.manualRepos.every((repo) => props.lockedManualRepoIds?.has(repo.id)) ? (

Public repositories only. Private ones come from your GitHub or the Opengeni app.

) : ( props.manualRepos .filter((repo) => !props.lockedManualRepoIds?.has(repo.id)) .map((repo) => ( props.onManualUpdate(repo.id, patch)} onRemove={() => props.onManualRemove(repo.id)} onAttach={ props.onManualAttach ?? (async () => { throw new Error("Repository attachment is unavailable."); }) } /> )) )} {props.validationError ? (

{props.validationError}

) : null}
)} {/* The list refreshes itself on open and after GitHub flows; only a failure offers a retry. */} {(refreshError || updateFailed) && !loadFailed ? (

Couldn't update the list. {refreshError ? ( <> {" "} {refreshError} ) : null} {canRefresh ? ( <> {" "} void refreshList()} disabled={refreshBusy} /> ) : null}

) : null} {manageVisible && props.githubSettingsUrl ? (
Manage GitHub access
) : null} {props.newChatUrl && (props.lockedRepoIds?.size ?? 0) + (props.lockedPersonalGitHubRepoIds?.size ?? 0) + (props.lockedManualRepoIds?.size ?? 0) > 0 ? (

To change the branch of a repository already in this chat,{" "} start a new chat .

) : null} {props.validationError && (!props.manualOpen || props.manualRepos.length === 0) ? (

{props.validationError}

) : null}
); } /** One repository the picker can select, through the workspace App, your GitHub, or both. */ export type RepositoryPickerRow = { key: string; fullName: string; name: string; private: boolean; app: GitHubRepository | null; personal: PersonalGitHubRepositoryCatalogItem | null; }; export type RepositoryPickerRowGroup = { key: string; label: string; rows: RepositoryPickerRow[]; }; function repositoryOwner(fullName: string): string { return fullName.split("/")[0] ?? fullName; } /** * Merges App and personal catalogs into one row per repository, grouped by * owner. App installations keep their order; a repository reachable both ways * is one row with both authorities. */ export function repositoryPickerRowGroups( groups: readonly RepositoryGroup[], personalRepositories: readonly PersonalGitHubRepositoryCatalogItem[], ): RepositoryPickerRowGroup[] { const ordered: RepositoryPickerRowGroup[] = []; const byOwner = new Map(); const byRepository = new Map(); const groupFor = (label: string) => { const key = label.toLowerCase(); let group = byOwner.get(key); if (!group) { group = { key, label, rows: [] }; byOwner.set(key, group); ordered.push(group); } return group; }; for (const group of groups) { for (const repo of group.repositories) { const key = repo.fullName.toLowerCase(); if (byRepository.has(key)) continue; const row: RepositoryPickerRow = { key, fullName: repo.fullName, name: repo.name, private: repo.private, app: repo, personal: null, }; byRepository.set(key, row); groupFor(repositoryOwner(repo.fullName)).rows.push(row); } } for (const repo of personalRepositories) { if (repo.selectedAccess === null) continue; const key = repo.fullName.toLowerCase(); const existing = byRepository.get(key); if (existing) { existing.personal ??= repo; continue; } const row: RepositoryPickerRow = { key, fullName: repo.fullName, name: repo.fullName.slice(repositoryOwner(repo.fullName).length + 1) || repo.fullName, private: repo.private, app: null, personal: repo, }; byRepository.set(key, row); groupFor(repositoryOwner(repo.fullName)).rows.push(row); } return ordered; } /** * Which identity a new selection acts as: you when your GitHub can write to * the repository (or is the only way to reach it), otherwise the workspace App. */ export function defaultRepositoryIdentity(row: RepositoryPickerRow): "personal" | "app" { if (!row.personal) return "app"; if (!row.app) return "personal"; return row.personal.selectedAccess === "write" ? "personal" : "app"; } /** Inline retry after a failed load or background update. */ function RetryLink(props: { onClick: () => void; disabled: boolean }) { return ( ); } /** * A link to another app page. Goes through the host's navigation, so an * embedded session UI opens it beside the host page instead of resolving it * against the host's origin; plain anchor when no navigation is configured. */ function AppPageLink(props: { href: string; className?: string | undefined; onClick?: (() => void) | undefined; children: ReactNode; }) { const HostLink = useAppHost().navigation?.Link; if (!HostLink) { return ( {props.children} ); } return ( {props.children} ); } function githubLoginLabel(login: unknown): string { return typeof login === "string" && login.length > 0 ? `@${login}` : "Connected"; } function RepositoryPickerRowView(props: { row: RepositoryPickerRow; picker: RepositoryContextPickerProps; }) { const { row, picker } = props; const { app, personal } = row; const canUsePersonal = Boolean(personal && picker.onTogglePersonalGitHubRepo); const appLocked = app !== null && picker.lockedRepoIds?.has(app.id) === true; const personalLocked = personal !== null && picker.lockedPersonalGitHubRepoIds?.has(personal.repositoryId) === true; const appSelected = app !== null && picker.selectedRepoIds.has(app.id); const personalSelected = personal !== null && picker.selectedPersonalGitHubRepoIds?.has(personal.repositoryId) === true; const locked = appLocked || personalLocked; const checked = locked || appSelected || personalSelected; const actingAs: "personal" | "app" = personalLocked || personalSelected ? "personal" : appLocked || appSelected ? "app" : !app ? "personal" : canUsePersonal ? defaultRepositoryIdentity(row) : "app"; const ref = actingAs === "personal" && personal ? (picker.selectedPersonalGitHubRepoRefs?.[personal.repositoryId] ?? personal.defaultBranch) : app ? (picker.selectedRepoRefs[app.id] ?? app.defaultBranch) : (personal?.defaultBranch ?? ""); const defaultRef = actingAs === "personal" && personal ? personal.defaultBranch : (app?.defaultBranch ?? ""); const personalBusy = picker.personalGitHubBusy === true; function select(identity: "personal" | "app") { if (identity === "personal" && personal) picker.onTogglePersonalGitHubRepo?.(personal); else if (app) picker.onToggleRepo(app); } function toggle() { if (locked) { if (personalLocked && personal) { picker.onRemoveMountedRepository?.({ kind: "personal", repository: personal }); } else if (app) { picker.onRemoveMountedRepository?.({ kind: "app", repository: app }); } return; } if (personalSelected && personal) picker.onTogglePersonalGitHubRepo?.(personal); else if (appSelected && app) picker.onToggleRepo(app); else select(actingAs); } // The new identity's selection replaces the other one; it keeps the ref. function switchIdentity(identity: "personal" | "app") { if (identity === actingAs || !app || !personal) return; if (identity === "personal") picker.onPersonalGitHubRefChange?.(personal.repositoryId, ref); else picker.onRefChange(app.id, ref); select(identity); } const rawLogin = picker.personalGitHubStatus?.connection?.metadata.githubLogin; const you = typeof rawLogin === "string" && rawLogin.length > 0 ? `You (@${rawLogin})` : "You"; const showIdentityChoice = checked && !locked && app !== null && canUsePersonal; // With your GitHub connected there are two identities, so a selected // repository always says which one it works as. Without it there is only // the app, and nothing to explain. const showIdentity = checked && !locked && picker.personalGitHubStatus?.enabled === true && picker.personalGitHubStatus.connection?.status === "active"; const readOnly = actingAs === "personal" && personal?.selectedAccess === "read"; // A selected row shows its branch in the field below; the subtitle would repeat it. const editing = checked && !locked; return (
{row.name} {row.private ? : null} {editing && !readOnly ? null : ( {editing ? "Read only" : readOnly ? `${ref} · Read only` : ref} )} {locked ? ( {picker.onRemoveMountedRepository ? null : ( ) : null}
{checked && !locked ? (
{ if (actingAs === "personal" && personal) { picker.onPersonalGitHubRefChange?.(personal.repositoryId, value); } else if (app) { picker.onRefChange(app.id, value); } }} disabled={picker.pending} loadBranches={ actingAs === "personal" && personal ? picker.onLoadPersonalGitHubBranches?.bind(null, personal) : app ? picker.onLoadGitHubBranches?.bind(null, app) : undefined } /> {showIdentityChoice ? (
Acts as
) : showIdentity ? (
Acts as {actingAs === "personal" ? you : "Opengeni app"}
) : null}
) : null}
); } export function RepositoryContextPicker(props: RepositoryContextPickerProps) { const selectedInstalledCount = props.selectedRepoIds.size; const selectedPersonalCount = props.selectedPersonalGitHubRepoIds?.size ?? 0; const manualCount = attachedManualRepositoryCount(props.manualRepos); const selectedCount = selectedInstalledCount + selectedPersonalCount + manualCount; const bindingPresentation = repositoryBindingPresentation( props.status, props.installUrl, props.setupMode, ); const personalGitHubActive = props.personalGitHubStatus?.connection?.status === "active"; const selectedInstalled = props.repositories.filter((repo) => props.selectedRepoIds.has(repo.id)); const selectedManual = props.manualRepos.filter( (repo) => repo.attached !== false && repo.url.trim().length > 0, ); const selectedNames = [ ...selectedInstalled.map((repo) => repo.fullName), ...selectedManual.map((repo) => repo.url.trim()), ...(props.personalGitHubRepositories ?? []) .filter((repo) => props.selectedPersonalGitHubRepoIds?.has(repo.repositoryId)) .map((repo) => repo.fullName), ]; const selectedLabel = selectedCount === 1 ? (selectedNames[0] ?? repoCountLabel(1)) : repoCountLabel(selectedCount); return ( ); } export function ScheduledTaskRepositoryPicker(props: { status: GitHubBindingStatus; repositories: GitHubRepository[]; groups: RepositoryGroup[]; resources: ResourceRef[]; busy: boolean; repoBusy: boolean; onRefresh: () => Promise; onResourcesChange: (resources: ResourceRef[]) => void; }) { const repositoryResources = props.resources.filter( (resource): resource is Extract => resource.kind === "repository", ); const fileResources = props.resources.filter((resource) => resource.kind === "file"); const preservedRepositoryResources = repositoryResources.filter( (resource) => !props.repositories.some((repo) => isRepositoryResourceForGitHubRepo(resource, repo)), ); function toggleRepo(repo: GitHubRepository) { const existing = props.resources.find( (resource) => resource.kind === "repository" && isRepositoryResourceForGitHubRepo(resource, repo), ); if (existing) { props.onResourcesChange(props.resources.filter((resource) => resource !== existing)); return; } try { const nextResource = gitHubRepositoryResource(repo, repo.defaultBranch); props.onResourcesChange([ ...props.resources.filter((resource) => !sameRepositoryUri(resource, nextResource.uri)), nextResource, ]); } catch (error) { toast.error("Couldn't select the repository", { description: userErrorText(error) }); } } function updateRef(repo: GitHubRepository, ref: string) { props.onResourcesChange( props.resources.map((resource) => { if (resource.kind !== "repository" || !isRepositoryResourceForGitHubRepo(resource, repo)) { return resource; } return { ...resource, ref }; }), ); } return (
Repositories
{repoCountLabel(repositoryResources.length)} attached to this task
{props.status !== "bound" ? (
{props.status === "disabled" ? "GitHub App server credentials are not configured." : "GitHub App credentials exist, but this workspace has no active installation binding."}
) : props.repoBusy ? (
Loading repositories
) : props.repositories.length === 0 ? (
The active binding currently shares no explicitly allowed repositories.
) : (
{props.groups.map((group) => (
{group.label}
{group.repositories.length} repos
{group.repositories.map((repo) => { const resource = repositoryResources.find((item) => isRepositoryResourceForGitHubRepo(item, repo), ); const checked = Boolean(resource); return (
{resource ? (
updateRef(repo, event.target.value)} onClick={(event) => event.stopPropagation()} disabled={props.busy} placeholder={repo.defaultBranch} aria-label={`${repo.fullName} branch or ref for the automation`} className="h-7 text-xs" />
) : null}
); })}
))}
)} {preservedRepositoryResources.length > 0 || fileResources.length > 0 ? (
Preserving {preservedRepositoryResources.length} manual repository resource {preservedRepositoryResources.length === 1 ? "" : "s"} {fileResources.length > 0 ? ` and ${fileResources.length} file resource${fileResources.length === 1 ? "" : "s"}` : ""} .
) : null}
); }