Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys committed Sep 23, 2024
1 parent 51e020e commit c104641
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
27 changes: 16 additions & 11 deletions ee/tabby-schema/src/schema/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,34 @@ impl ContextInfo {
pub fn helper(&self) -> ContextInfoHelper {
ContextInfoHelper::new(self)
}

pub fn allowed_code_repository(&self) -> AllowedCodeRepository {
let mut repositories = vec![];
repositories.reserve(self.sources.len());
for x in &self.sources {
if let ContextSourceValueEnum::Repository(x) = x {
repositories.push(CodeRepository::new(&x.git_url, &x.source_id));

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

View check run for this annotation

Codecov / codecov/patch

ee/tabby-schema/src/schema/context.rs#L107

Added line #L107 was not covered by tests
}
}

AllowedCodeRepository::new(repositories)
}
}

pub struct ContextInfoHelper {
sources: HashMap<String, String>,
pub allowed_code_repository: AllowedCodeRepository,
allowed_code_repository: AllowedCodeRepository,
}

impl ContextInfoHelper {
pub fn new(context_info: &ContextInfo) -> Self {
let mut repositories = vec![];
for x in &context_info.sources {
if let ContextSourceValueEnum::Repository(x) = x {
repositories.push(CodeRepository::new(&x.git_url, &x.source_id));
}
}

Self {
sources: context_info
.sources
.iter()
.map(|source| (source.source_id(), source.source_name()))
.collect(),
allowed_code_repository: AllowedCodeRepository::new(repositories),
allowed_code_repository: context_info.allowed_code_repository()
}
}

Expand All @@ -146,8 +151,8 @@ impl ContextInfoHelper {
self.sources.contains_key(source_id)
}

pub fn find_closet_git_url(&self, git_url: &str) -> Option<&str> {
self.allowed_code_repository.closest_match(git_url)
pub fn allowed_code_repository(&self) -> &AllowedCodeRepository {
&self.allowed_code_repository
}

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

View check run for this annotation

Codecov / codecov/patch

ee/tabby-schema/src/schema/context.rs#L154-L156

Added lines #L154 - L156 were not covered by tests
}

Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/service/answer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl AnswerService {
None

Check warning on line 197 in ee/tabby-webserver/src/service/answer.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/answer.rs#L197

Added line #L197 was not covered by tests
}
} else if let Some(git_url) = &input.git_url {
helper.find_closet_git_url(git_url)
helper.allowed_code_repository().closest_match(git_url)

Check warning on line 200 in ee/tabby-webserver/src/service/answer.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/answer.rs#L199-L200

Added lines #L199 - L200 were not covered by tests
} else {
None

Check warning on line 202 in ee/tabby-webserver/src/service/answer.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/answer.rs#L202

Added line #L202 was not covered by tests
}
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl WorkerService for ServerContext {

request
.extensions_mut()
.insert(context_info.helper().allowed_code_repository);
.insert(context_info.allowed_code_repository());

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

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/mod.rs#L235-L237

Added lines #L235 - L237 were not covered by tests
}

next.run(request).await
Expand Down

0 comments on commit c104641

Please sign in to comment.