Skip to content
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

refactor(repository): update repository ID generation and remove unus… #3167

Merged
merged 5 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 7 additions & 1 deletion ee/tabby-schema/src/schema/context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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 +31,8 @@
#[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 +68,10 @@

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

Check warning on line 73 in ee/tabby-schema/src/schema/context.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-schema/src/schema/context.rs#L71-L73

Added lines #L71 - L73 were not covered by tests

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 @@
fn from(value: GitRepository) -> Self {
Self {
source_id: value.source_id(),
id: value.id,
id: ID::new(value.source_id()),

Check warning on line 113 in ee/tabby-schema/src/schema/repository/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-schema/src/schema/repository/mod.rs#L113

Added line #L113 was not covered by tests
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 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 repository_config_to_repository(index: usize, config: &RepositoryConfig) -> Result<Repository> {
let source_id = config_index_to_id(index);

Check warning on line 257 in ee/tabby-webserver/src/service/repository/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/repository/mod.rs#L257

Added line #L257 was not covered by tests
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: source_id,

Check warning on line 260 in ee/tabby-webserver/src/service/repository/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/repository/mod.rs#L259-L260

Added lines #L259 - L260 were not covered by tests
name: config.display_name(),
kind: RepositoryKind::GitConfig,
dir: config.dir(),
Expand Down
Loading