Skip to content

Commit

Permalink
refactor(repository): update repository ID generation and remove unus… (
Browse files Browse the repository at this point in the history
#3167)

* refactor(repository): update repository ID generation and remove unused GQL resolver

* Update ee/tabby-ui/lib/tabby/gql.ts

* update

* update: gql query

* [autofix.ci] apply automated fixes

---------

Co-authored-by: liangfung <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 19, 2024
1 parent 7ae86f1 commit 58befa5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ee/tabby-schema/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ input UpsertUserGroupMembershipInput {
}

interface ContextSource implements ContextSourceId {
id: ID!
sourceId: String!
sourceKind: ContextSourceKind!
"Display name of the source, used to provide a human-readable name for user selection, such as in a dropdown menu."
Expand Down Expand Up @@ -865,6 +866,7 @@ type UserSecured implements User {
}

type WebContextSource implements ContextSourceId & ContextSource {
id: ID!
sourceKind: ContextSourceKind!
sourceId: String!
sourceName: String!
Expand Down
10 changes: 9 additions & 1 deletion ee/tabby-schema/src/schema/context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::collections::HashMap;

use async_trait::async_trait;
use juniper::{graphql_interface, graphql_object, GraphQLEnum, GraphQLInterface, GraphQLObject};
use juniper::{
graphql_interface, graphql_object, GraphQLEnum, GraphQLInterface, GraphQLObject, ID,
};
use regex::{Captures, Regex};

use super::{
Expand Down Expand Up @@ -31,6 +33,8 @@ pub trait ContextSourceId {
#[derive(GraphQLInterface)]
#[graphql(context = Context, impl = [ContextSourceIdValue], for = [CustomWebDocument, PresetWebDocument, Repository, WebContextSource])]
pub struct ContextSource {
pub id: ID,

// start implements ContextSource
pub source_id: String,
// end implements ContextSource
Expand Down Expand Up @@ -66,6 +70,10 @@ const PUBLIC_WEB_INTERNAL_SOURCE_ID: &str = "internal-public-web";

#[graphql_object(context = Context, impl = [ContextSourceIdValue, ContextSourceValue])]
impl WebContextSource {
fn id(&self) -> ID {
ID::new(PUBLIC_WEB_INTERNAL_SOURCE_ID.to_owned())
}

fn source_kind(&self) -> ContextSourceKind {
ContextSourceKind::Web
}
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-schema/src/schema/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl From<GitRepository> for Repository {
fn from(value: GitRepository) -> Self {
Self {
source_id: value.source_id(),
id: value.id,
id: ID::new(value.source_id()),
name: value.name,
kind: RepositoryKind::Git,
dir: RepositoryConfig::resolve_dir(&value.git_url),
Expand Down
1 change: 0 additions & 1 deletion ee/tabby-ui/lib/tabby/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ const client = new Client({
GrepFile: () => null,
GrepTextOrBase64: () => null,
GrepSubMatch: () => null,
Repository: (data: any) => (data ? `${data.kind}_${data.id}` : null),
GitReference: () => null,
MessageAttachment: () => null,
MessageAttachmentCode: () => null,
Expand Down
1 change: 1 addition & 0 deletions ee/tabby-ui/lib/tabby/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export const contextInfoQuery = graphql(/* GraphQL */ `
query ContextInfo {
contextInfo {
sources {
id
sourceKind
sourceId
sourceName
Expand Down
7 changes: 4 additions & 3 deletions ee/tabby-webserver/src/service/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ fn list_refs(git_url: &str) -> Vec<tabby_git::GitReference> {
fn to_repository(kind: RepositoryKind, repo: ProvidedRepository) -> Repository {
Repository {
source_id: repo.source_id(),
id: repo.id,
id: ID::new(repo.source_id()),
name: repo.display_name,
kind,
dir: RepositoryConfig::resolve_dir(&repo.git_url),
Expand All @@ -254,9 +254,10 @@ fn to_repository(kind: RepositoryKind, repo: ProvidedRepository) -> Repository {
}

fn repository_config_to_repository(index: usize, config: &RepositoryConfig) -> Result<Repository> {
let source_id = config_index_to_id(index);
Ok(Repository {
id: ID::new(config_index_to_id(index)),
source_id: config_index_to_id(index),
id: ID::new(source_id.clone()),
source_id,
name: config.display_name(),
kind: RepositoryKind::GitConfig,
dir: config.dir(),
Expand Down

0 comments on commit 58befa5

Please sign in to comment.