Skip to content

Commit

Permalink
fix(graphQL): resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
antimonyGu committed Dec 12, 2024
1 parent 88c26a9 commit 48a8de6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion ee/tabby-schema/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
28 changes: 14 additions & 14 deletions ee/tabby-schema/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,23 +541,23 @@ impl Query {
.await
}

async fn resolve_git_url(ctx: &Context, git_url: String) -> Result<bool> {
let user = check_user_and_auth_token(ctx).await?;
async fn resolve_git_url(ctx: &Context, git_url: String) -> Result<Option<Repository>> {
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<String> = 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<ContextInfo> {
Expand Down
4 changes: 2 additions & 2 deletions ee/tabby-schema/src/schema/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub enum RepositoryKind {
GitConfig,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Repository {
pub id: ID,

Expand Down Expand Up @@ -100,7 +100,7 @@ impl Repository {
}
}

#[derive(GraphQLObject, Debug)]
#[derive(GraphQLObject, Debug, Clone)]
pub struct GitReference {
pub name: String,
pub commit: String,
Expand Down
8 changes: 4 additions & 4 deletions ee/tabby-ui/components/chat/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion ee/tabby-ui/lib/tabby/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
`)

Expand Down

0 comments on commit 48a8de6

Please sign in to comment.