Repository navigation
fix(github): search repositories by name #8340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d7a485d
91ad373
2a4c55e
6cf30bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,7 @@ import { | |||||||||||||||||||||||||||||||||||
| getCloneDestinationPath, | ||||||||||||||||||||||||||||||||||||
| getCloneDirectoryName, | ||||||||||||||||||||||||||||||||||||
| getDefaultCloneUrl, | ||||||||||||||||||||||||||||||||||||
| isGitHubRepositoryShorthand, | ||||||||||||||||||||||||||||||||||||
| normalizePastedCloneUrl, | ||||||||||||||||||||||||||||||||||||
| resolveAddProjectPath, | ||||||||||||||||||||||||||||||||||||
| sortAddProjectProviderSources, | ||||||||||||||||||||||||||||||||||||
|
|
@@ -31,7 +32,12 @@ import { | |||||||||||||||||||||||||||||||||||
| inferProjectTitleFromPath, | ||||||||||||||||||||||||||||||||||||
| isWindowsPlatform, | ||||||||||||||||||||||||||||||||||||
| } from "@t3tools/client-runtime/state/projects"; | ||||||||||||||||||||||||||||||||||||
| import { CommandId, type EnvironmentId, ProjectId } from "@t3tools/contracts"; | ||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||
| CommandId, | ||||||||||||||||||||||||||||||||||||
| type EnvironmentId, | ||||||||||||||||||||||||||||||||||||
| ProjectId, | ||||||||||||||||||||||||||||||||||||
| type SourceControlRepositoryInfo, | ||||||||||||||||||||||||||||||||||||
| } from "@t3tools/contracts"; | ||||||||||||||||||||||||||||||||||||
| import { CommonActions, StackActions, useNavigation } from "@react-navigation/native"; | ||||||||||||||||||||||||||||||||||||
| import { SymbolView } from "../../components/AppSymbol"; | ||||||||||||||||||||||||||||||||||||
| import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react"; | ||||||||||||||||||||||||||||||||||||
|
|
@@ -55,6 +61,7 @@ import { useThemeColor } from "../../lib/useThemeColor"; | |||||||||||||||||||||||||||||||||||
| import { uuidv4 } from "../../lib/uuid"; | ||||||||||||||||||||||||||||||||||||
| import { useAtomCommand } from "../../state/use-atom-command"; | ||||||||||||||||||||||||||||||||||||
| import { useAtomQueryRunner } from "../../state/use-atom-query-runner"; | ||||||||||||||||||||||||||||||||||||
| import { useDebouncedValue } from "../../state/queries"; | ||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||
| useRemoteConnectionStatus, | ||||||||||||||||||||||||||||||||||||
| useRemoteEnvironmentRuntime, | ||||||||||||||||||||||||||||||||||||
|
|
@@ -72,6 +79,8 @@ interface EnvironmentOption { | |||||||||||||||||||||||||||||||||||
| readonly connectionErrorTraceId: string | null; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const REPOSITORY_SEARCH_DEBOUNCE_MS = 100; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const environmentOptionOrder = Order.mapInput( | ||||||||||||||||||||||||||||||||||||
| Order.Struct({ | ||||||||||||||||||||||||||||||||||||
| label: Order.String, | ||||||||||||||||||||||||||||||||||||
|
|
@@ -652,11 +661,55 @@ export function AddProjectRepositoryScreen(props: { | |||||||||||||||||||||||||||||||||||
| reportFailure: false, | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
| const navigation = useNavigation(); | ||||||||||||||||||||||||||||||||||||
| const iconColor = useThemeColor("--color-icon"); | ||||||||||||||||||||||||||||||||||||
| const environment = useEnvironmentFromParam(props.environmentId); | ||||||||||||||||||||||||||||||||||||
| const source = sourceFromParam(props.source); | ||||||||||||||||||||||||||||||||||||
| const [repositoryInput, setRepositoryInput] = useState(""); | ||||||||||||||||||||||||||||||||||||
| const [isSubmitting, setIsSubmitting] = useState(false); | ||||||||||||||||||||||||||||||||||||
| const [error, setError] = useState<string | null>(null); | ||||||||||||||||||||||||||||||||||||
| const normalizedRepositoryInput = repositoryInput.trim(); | ||||||||||||||||||||||||||||||||||||
| const debouncedRepositoryInput = useDebouncedValue( | ||||||||||||||||||||||||||||||||||||
| normalizedRepositoryInput, | ||||||||||||||||||||||||||||||||||||
| REPOSITORY_SEARCH_DEBOUNCE_MS, | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
| const githubRepositorySearchEnvironmentId = | ||||||||||||||||||||||||||||||||||||
| source === "github" ? (environment?.environmentId ?? null) : null; | ||||||||||||||||||||||||||||||||||||
| const settledRepositoryInput = | ||||||||||||||||||||||||||||||||||||
| normalizedRepositoryInput.length > 0 && normalizedRepositoryInput === debouncedRepositoryInput | ||||||||||||||||||||||||||||||||||||
| ? debouncedRepositoryInput | ||||||||||||||||||||||||||||||||||||
| : null; | ||||||||||||||||||||||||||||||||||||
| const repositorySearch = useEnvironmentQuery( | ||||||||||||||||||||||||||||||||||||
| githubRepositorySearchEnvironmentId !== null && settledRepositoryInput !== null | ||||||||||||||||||||||||||||||||||||
| ? sourceControlEnvironment.repositorySearch({ | ||||||||||||||||||||||||||||||||||||
| environmentId: githubRepositorySearchEnvironmentId, | ||||||||||||||||||||||||||||||||||||
| input: { | ||||||||||||||||||||||||||||||||||||
| provider: "github", | ||||||||||||||||||||||||||||||||||||
| query: settledRepositoryInput, | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||
| : null, | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
| const repositories = repositorySearch.data; | ||||||||||||||||||||||||||||||||||||
| const isRepositorySearchPending = | ||||||||||||||||||||||||||||||||||||
| normalizedRepositoryInput.length > 0 && | ||||||||||||||||||||||||||||||||||||
| (normalizedRepositoryInput !== debouncedRepositoryInput || repositorySearch.isPending); | ||||||||||||||||||||||||||||||||||||
| const visibleError = error ?? repositorySearch.error; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const selectRepository = useCallback( | ||||||||||||||||||||||||||||||||||||
| (repository: SourceControlRepositoryInfo) => { | ||||||||||||||||||||||||||||||||||||
| if (!environment) return; | ||||||||||||||||||||||||||||||||||||
| navigation.dispatch( | ||||||||||||||||||||||||||||||||||||
| StackActions.push("AddProjectDestination", { | ||||||||||||||||||||||||||||||||||||
| environmentId: environment.environmentId, | ||||||||||||||||||||||||||||||||||||
| source, | ||||||||||||||||||||||||||||||||||||
| remoteUrl: getDefaultCloneUrl(repository), | ||||||||||||||||||||||||||||||||||||
| repositoryTitle: repository.nameWithOwner, | ||||||||||||||||||||||||||||||||||||
| repositoryName: getCloneDirectoryName(repository.nameWithOwner), | ||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| [environment, navigation, source], | ||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const lookupRepository = useCallback(async () => { | ||||||||||||||||||||||||||||||||||||
| if (!environment || repositoryInput.trim().length === 0 || isSubmitting) return; | ||||||||||||||||||||||||||||||||||||
|
|
@@ -678,6 +731,11 @@ export function AddProjectRepositoryScreen(props: { | |||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (provider === "github" && !isGitHubRepositoryShorthand(repositoryInput)) { | ||||||||||||||||||||||||||||||||||||
| setIsSubmitting(false); | ||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const result = await lookupRepositoryQuery({ | ||||||||||||||||||||||||||||||||||||
| environmentId: environment.environmentId, | ||||||||||||||||||||||||||||||||||||
| input: { | ||||||||||||||||||||||||||||||||||||
|
|
@@ -704,29 +762,64 @@ export function AddProjectRepositoryScreen(props: { | |||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||
| <AddProjectShell> | ||||||||||||||||||||||||||||||||||||
| {error ? <ErrorBanner message={error} /> : null} | ||||||||||||||||||||||||||||||||||||
| {visibleError ? <ErrorBanner message={visibleError} /> : null} | ||||||||||||||||||||||||||||||||||||
| {environment ? ( | ||||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||||
| <TextInput | ||||||||||||||||||||||||||||||||||||
| className="h-12 min-h-12 rounded-[24px] px-4 py-0 text-base leading-snug" | ||||||||||||||||||||||||||||||||||||
| value={repositoryInput} | ||||||||||||||||||||||||||||||||||||
| onChangeText={setRepositoryInput} | ||||||||||||||||||||||||||||||||||||
| onChangeText={(value) => { | ||||||||||||||||||||||||||||||||||||
| if (value.trim() !== normalizedRepositoryInput) { | ||||||||||||||||||||||||||||||||||||
| setError(null); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| setRepositoryInput(value); | ||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||
| autoCapitalize="none" | ||||||||||||||||||||||||||||||||||||
| autoCorrect={false} | ||||||||||||||||||||||||||||||||||||
| placeholder={ | ||||||||||||||||||||||||||||||||||||
| source === "url" | ||||||||||||||||||||||||||||||||||||
| ? "https://github.com/org/repo.git" | ||||||||||||||||||||||||||||||||||||
| : addProjectRemoteSourcePathHint(source) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| returnKeyType="next" | ||||||||||||||||||||||||||||||||||||
| returnKeyType={source === "github" ? "done" : "next"} | ||||||||||||||||||||||||||||||||||||
| onSubmitEditing={() => void lookupRepository()} | ||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||
| <PrimaryActionButton | ||||||||||||||||||||||||||||||||||||
| label={source === "url" ? "Continue" : "Lookup repository"} | ||||||||||||||||||||||||||||||||||||
| disabled={isSubmitting || repositoryInput.trim().length === 0} | ||||||||||||||||||||||||||||||||||||
| onPress={() => void lookupRepository()} | ||||||||||||||||||||||||||||||||||||
| loading={isSubmitting} | ||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||
| {source === "github" ? null : ( | ||||||||||||||||||||||||||||||||||||
| <PrimaryActionButton | ||||||||||||||||||||||||||||||||||||
| label={source === "url" ? "Continue" : "Lookup repository"} | ||||||||||||||||||||||||||||||||||||
| disabled={isSubmitting || repositoryInput.trim().length === 0} | ||||||||||||||||||||||||||||||||||||
| onPress={() => void lookupRepository()} | ||||||||||||||||||||||||||||||||||||
| loading={isSubmitting} | ||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||
| {source === "github" && isRepositorySearchPending ? ( | ||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GitHub lookup shows no loading stateMedium Severity The GitHub spinner now follows Additional Locations (1)Reviewed by Cursor Bugbot for commit 91ad373. Configure here. |
||||||||||||||||||||||||||||||||||||
| <View className="items-center py-3"> | ||||||||||||||||||||||||||||||||||||
| <ActivityIndicator /> | ||||||||||||||||||||||||||||||||||||
| </View> | ||||||||||||||||||||||||||||||||||||
| ) : null} | ||||||||||||||||||||||||||||||||||||
| {repositories ? ( | ||||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||||
| <SectionTitle>Repositories</SectionTitle> | ||||||||||||||||||||||||||||||||||||
| <ListSection> | ||||||||||||||||||||||||||||||||||||
| {repositories.length === 0 ? ( | ||||||||||||||||||||||||||||||||||||
| <View className="items-center px-4 py-5"> | ||||||||||||||||||||||||||||||||||||
| <Text className="text-sm text-foreground-muted">No repositories found.</Text> | ||||||||||||||||||||||||||||||||||||
| </View> | ||||||||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||||||||
| repositories.map((repository, index) => ( | ||||||||||||||||||||||||||||||||||||
| <ListRow | ||||||||||||||||||||||||||||||||||||
| key={repository.nameWithOwner} | ||||||||||||||||||||||||||||||||||||
| title={repository.nameWithOwner} | ||||||||||||||||||||||||||||||||||||
| subtitle={repository.url} | ||||||||||||||||||||||||||||||||||||
| icon={<SourceControlIcon kind="github" size={18} color={String(iconColor)} />} | ||||||||||||||||||||||||||||||||||||
| isFirst={index === 0} | ||||||||||||||||||||||||||||||||||||
| onPress={() => selectRepository(repository)} | ||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+810
to
+817
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Repository rows remain tappable while
Suggested change
🤖 Copy this AI Prompt to have your agent fix this: |
||||||||||||||||||||||||||||||||||||
| )) | ||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||
| </ListSection> | ||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||
| ) : null} | ||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||||||||
| <EmptyEnvironmentState /> | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,25 @@ const processOutput = (stdout: string): VcsProcess.VcsProcessOutput => ({ | |
| stderrTruncated: false, | ||
| }); | ||
|
|
||
| const repositorySearchResult = (nameWithOwner: string) => ({ | ||
| nameWithOwner, | ||
| url: `https://github.com/${nameWithOwner}`, | ||
| sshUrl: `[email protected]:${nameWithOwner}.git`, | ||
| }); | ||
|
|
||
| const repositorySearchOutput = (input: { | ||
| readonly owner: ReadonlyArray<string>; | ||
| readonly global?: ReadonlyArray<string>; | ||
| }): VcsProcess.VcsProcessOutput => | ||
| processOutput( | ||
| JSON.stringify({ | ||
| data: { | ||
| owner: { nodes: input.owner.map(repositorySearchResult) }, | ||
| global: { nodes: (input.global ?? []).map(repositorySearchResult) }, | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| const mockRun = vi.fn<VcsProcess.VcsProcess["Service"]["run"]>(); | ||
|
|
||
| const layer = GitHubCli.layer.pipe( | ||
|
|
@@ -292,6 +311,105 @@ describe("GitHubCli.layer", () => { | |
| }).pipe(Effect.provide(layer)), | ||
| ); | ||
|
|
||
| it.effect("searches repositories with the authenticated owner's matches first", () => | ||
| Effect.gen(function* () { | ||
| mockRun.mockReturnValueOnce( | ||
| Effect.succeed( | ||
| repositorySearchOutput({ | ||
| owner: ["current-user/skills"], | ||
| global: ["mattpocock/skills", "current-user/skills", "someone-else/skills"], | ||
| }), | ||
| ), | ||
| ); | ||
|
|
||
| const gh = yield* GitHubCli.GitHubCli; | ||
| const result = yield* gh.searchRepositories({ | ||
| cwd: "/repo", | ||
| query: "skills", | ||
| }); | ||
|
|
||
| assert.deepStrictEqual( | ||
| result.map((repository) => repository.nameWithOwner), | ||
| ["current-user/skills", "mattpocock/skills", "someone-else/skills"], | ||
| ); | ||
| assert.equal(result[0]?.sshUrl, "[email protected]:current-user/skills.git"); | ||
| expect(mockRun).toHaveBeenCalledTimes(1); | ||
| expect(mockRun).toHaveBeenCalledWith({ | ||
| operation: "GitHubCli.execute", | ||
| command: "gh", | ||
| args: expect.arrayContaining([ | ||
| "api", | ||
| "graphql", | ||
| "ownerQuery=skills in:name user:@me fork:true", | ||
| "globalQuery=skills in:name fork:false", | ||
| ]), | ||
| cwd: "/repo", | ||
| timeoutMs: 30_000, | ||
| }); | ||
| }).pipe(Effect.provide(layer)), | ||
| ); | ||
|
|
||
| it.effect("returns an exact owner and repository path before other owner matches", () => | ||
| Effect.gen(function* () { | ||
| mockRun.mockReturnValueOnce( | ||
| Effect.succeed( | ||
| repositorySearchOutput({ | ||
| owner: ["octocat/codething-tools", "octocat/codething-mvp"], | ||
| }), | ||
| ), | ||
| ); | ||
|
|
||
| const gh = yield* GitHubCli.GitHubCli; | ||
| const result = yield* gh.searchRepositories({ | ||
| cwd: "/repo", | ||
| query: " octocat/codething-mvp ", | ||
| }); | ||
|
|
||
| assert.deepStrictEqual(result, [ | ||
| { | ||
| nameWithOwner: "octocat/codething-mvp", | ||
| url: "https://github.com/octocat/codething-mvp", | ||
| sshUrl: "[email protected]:octocat/codething-mvp.git", | ||
| }, | ||
| { | ||
| nameWithOwner: "octocat/codething-tools", | ||
| url: "https://github.com/octocat/codething-tools", | ||
| sshUrl: "[email protected]:octocat/codething-tools.git", | ||
| }, | ||
| ]); | ||
| expect(mockRun).toHaveBeenCalledTimes(1); | ||
| }).pipe(Effect.provide(layer)), | ||
| ); | ||
|
|
||
| it.effect("searches within an owner for a partial repository path", () => | ||
| Effect.gen(function* () { | ||
| mockRun.mockReturnValueOnce( | ||
| Effect.succeed(repositorySearchOutput({ owner: ["octocat/codething-mvp"] })), | ||
| ); | ||
|
|
||
| const gh = yield* GitHubCli.GitHubCli; | ||
| const result = yield* gh.searchRepositories({ cwd: "/repo", query: "octocat/code" }); | ||
|
|
||
| assert.deepStrictEqual( | ||
| result.map((repository) => repository.nameWithOwner), | ||
| ["octocat/codething-mvp"], | ||
| ); | ||
| expect(mockRun).toHaveBeenCalledTimes(1); | ||
| }).pipe(Effect.provide(layer)), | ||
| ); | ||
|
|
||
| it.effect("returns no repository search results when there are no matches", () => | ||
| Effect.gen(function* () { | ||
| mockRun.mockReturnValueOnce(Effect.succeed(repositorySearchOutput({ owner: [] }))); | ||
|
|
||
| const gh = yield* GitHubCli.GitHubCli; | ||
| const result = yield* gh.searchRepositories({ cwd: "/repo", query: "does-not-exist" }); | ||
|
|
||
| assert.deepStrictEqual(result, []); | ||
| expect(mockRun).toHaveBeenCalledTimes(1); | ||
| }).pipe(Effect.provide(layer)), | ||
| ); | ||
|
|
||
| it.effect("creates repositories and parses clone URLs from create output", () => | ||
| Effect.gen(function* () { | ||
| mockRun.mockReturnValueOnce( | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.