From 48a8de656bc347f334fb8f28f9725e1775e0eae8 Mon Sep 17 00:00:00 2001 From: zzgu Date: Wed, 11 Dec 2024 17:09:40 -0800 Subject: [PATCH] fix(graphQL): resolve comments --- ee/tabby-schema/graphql/schema.graphql | 2 +- ee/tabby-schema/src/schema/mod.rs | 28 ++++++++++---------- ee/tabby-schema/src/schema/repository/mod.rs | 4 +-- ee/tabby-ui/components/chat/chat.tsx | 8 +++--- ee/tabby-ui/lib/tabby/query.ts | 14 +++++++++- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/ee/tabby-schema/graphql/schema.graphql b/ee/tabby-schema/graphql/schema.graphql index ffbfbf437d5e..e54c94d17977 100644 --- a/ee/tabby-schema/graphql/schema.graphql +++ b/ee/tabby-schema/graphql/schema.graphql @@ -715,7 +715,7 @@ type Query { userEvents(after: String, before: String, first: Int, last: Int, users: [ID!], start: DateTime!, end: DateTime!): UserEventConnection! diskUsageStats: DiskUsageStats! repositoryList: [Repository!]! - resolveGitUrl(gitUrl: String!): Boolean! + resolveGitUrl(gitUrl: String!): Repository contextInfo: ContextInfo! integrations(ids: [ID!], kind: IntegrationKind, after: String, before: String, first: Int, last: Int): IntegrationConnection! integratedRepositories(ids: [ID!], kind: IntegrationKind, active: Boolean, after: String, before: String, first: Int, last: Int): ProvidedRepositoryConnection! diff --git a/ee/tabby-schema/src/schema/mod.rs b/ee/tabby-schema/src/schema/mod.rs index 0dac0f78413a..5f6296dc7102 100644 --- a/ee/tabby-schema/src/schema/mod.rs +++ b/ee/tabby-schema/src/schema/mod.rs @@ -541,23 +541,23 @@ impl Query { .await } - async fn resolve_git_url(ctx: &Context, git_url: String) -> Result { - let user = check_user_and_auth_token(ctx).await?; + async fn resolve_git_url(ctx: &Context, git_url: String) -> Result> { + let user = check_user_and_auth_token(ctx, true).await?; - let repositorys = ctx - .locator + let context_info = ctx.locator.context().read(Some(&user.policy)).await?; + let target_source_id: Option = context_info.helper().allowed_code_repository().closest_match(&git_url).map(String::from); + let repos = ctx.locator .repository() .repository_list(Some(&user.policy)) - .await - .unwrap_or_default(); - - for repo in repositorys { - if repo.git_url == git_url { - return Ok(true); - } - } - - return Ok(false); + .await?; + + // Iterate through repositories and find matching source_id + let matching_repo = repos.iter().find(|repo| { + // Match repo source_id with your target + Some(&repo.source_id) == target_source_id.as_ref() + }); + + Ok(matching_repo.map(|repo| repo.clone())) } async fn context_info(ctx: &Context) -> Result { diff --git a/ee/tabby-schema/src/schema/repository/mod.rs b/ee/tabby-schema/src/schema/repository/mod.rs index bfc91ef4c8e8..8d3ba6a52f3f 100644 --- a/ee/tabby-schema/src/schema/repository/mod.rs +++ b/ee/tabby-schema/src/schema/repository/mod.rs @@ -40,7 +40,7 @@ pub enum RepositoryKind { GitConfig, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Repository { pub id: ID, @@ -100,7 +100,7 @@ impl Repository { } } -#[derive(GraphQLObject, Debug)] +#[derive(GraphQLObject, Debug, Clone)] pub struct GitReference { pub name: String, pub commit: String, diff --git a/ee/tabby-ui/components/chat/chat.tsx b/ee/tabby-ui/components/chat/chat.tsx index e23db41bd0cc..7ae1969555af 100644 --- a/ee/tabby-ui/components/chat/chat.tsx +++ b/ee/tabby-ui/components/chat/chat.tsx @@ -38,8 +38,8 @@ import { EmptyScreen } from './empty-screen' import { QuestionAnswerList } from './question-answer' import { createRequest } from '@urql/core' import { client } from '@/lib/tabby/gql' -import { IsAvaileableWorkspaceQuery } from '@/lib/gql/generates/graphql' -import { isAvaileableWorkspaceQuery, repositoryListQuery } from '@/lib/tabby/query' +import { ResolveGitUrlQuery } from '@/lib/gql/generates/graphql' +import { resolveGitUrlQuery, repositoryListQuery } from '@/lib/tabby/query' type ChatContextValue = { threadId: string | undefined @@ -107,12 +107,12 @@ interface ChatProps extends React.ComponentProps<'div'> { } async function isAvaileableWorkspace(gitUrl: string): Promise< - IsAvaileableWorkspaceQuery['isAvaileableWorkspace'] + ResolveGitUrlQuery['resolveGitUrl'] > { // debugger const query = client.createRequestOperation( 'query', - createRequest(isAvaileableWorkspaceQuery, { gitUrl }) + createRequest(resolveGitUrlQuery, { gitUrl }) ) return client diff --git a/ee/tabby-ui/lib/tabby/query.ts b/ee/tabby-ui/lib/tabby/query.ts index 04f69f0fb9f5..93ae9adc9483 100644 --- a/ee/tabby-ui/lib/tabby/query.ts +++ b/ee/tabby-ui/lib/tabby/query.ts @@ -282,7 +282,19 @@ export const repositoryListQuery = graphql(/* GraphQL */ ` export const resolveGitUrlQuery = graphql(/* GraphQL */ ` query ResolveGitUrl($gitUrl: String!) { - resolveGitUrl(gitUrl: $gitUrl) + resolveGitUrl(gitUrl: $gitUrl) { + id + sourceId + sourceKind + sourceName + name + kind + gitUrl + refs { + name + commit + } + } } `)