Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys committed Apr 26, 2024
1 parent 57b7a03 commit d941827
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/repositories/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async fn resolve_path(
Path(repo): Path<ResolveParams>,
) -> Result<Response, StatusCode> {
let relpath = repo.os_path();
let Some(root) = rs.find_repository(&repo.kind, &repo.id).await else {
let Some(root) = rs.find_repository(&repo).await else {
return Err(StatusCode::NOT_FOUND);
};
let full_path = root.join(relpath);
Expand Down
8 changes: 6 additions & 2 deletions ee/tabby-webserver/src/repositories/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,12 @@ impl ResolveState {
Ok(resp.map(boxed))
}

pub async fn find_repository(&self, kind: &RepositoryKind, id: &ID) -> Option<PathBuf> {
let repository = self.service.get(kind, id).await.ok()?;
pub async fn find_repository(&self, params: &ResolveParams) -> Option<PathBuf> {
let repository = self
.service
.resolve_repository(&params.kind, &params.id)
.await
.ok()?;
Some(repository.dir)

Check warning on line 134 in ee/tabby-webserver/src/repositories/resolve.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/repositories/resolve.rs#L128-L134

Added lines #L128 - L134 were not covered by tests
}
}
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/schema/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub trait RepositoryProvider {
#[async_trait]
pub trait RepositoryService: Send + Sync + RepositoryAccess {
async fn repository_list(&self) -> Result<Vec<Repository>>;
async fn get(&self, kind: &RepositoryKind, id: &ID) -> Result<Repository>;
async fn resolve_repository(&self, kind: &RepositoryKind, id: &ID) -> Result<Repository>;
async fn search_files(
&self,
kind: &RepositoryKind,
Expand Down
4 changes: 2 additions & 2 deletions ee/tabby-webserver/src/service/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl RepositoryService for RepositoryServiceImpl {
Ok(all)
}

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

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/repository.rs#L87-L88

Added lines #L87 - L88 were not covered by tests

async fn get(&self, kind: &RepositoryKind, id: &ID) -> Result<Repository> {
async fn resolve_repository(&self, kind: &RepositoryKind, id: &ID) -> Result<Repository> {
match kind {
RepositoryKind::Git => self.git().get_repository(id).await,
RepositoryKind::Github => self.github().get_repository(id).await,
Expand All @@ -105,7 +105,7 @@ impl RepositoryService for RepositoryServiceImpl {
if pattern.trim().is_empty() {
return Ok(vec![]);
}
let dir = self.get(kind, id).await?.dir;
let dir = self.resolve_repository(kind, id).await?.dir;

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

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/repository.rs#L98-L108

Added lines #L98 - L108 were not covered by tests

let pattern = pattern.to_owned();
let matching = tokio::task::spawn_blocking(move || async move {
Expand Down

0 comments on commit d941827

Please sign in to comment.