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(webserver): cleanup directory structure / naming for Repository / GitRepository / GithubRepository / GitlabRepository #1983

Merged
merged 8 commits into from
Apr 26, 2024
Merged
22 changes: 9 additions & 13 deletions ee/tabby-webserver/src/cron/db/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,35 @@
use octocrab::{models::Repository, GitHubError, Octocrab};
use tracing::warn;

use crate::schema::github_repository_provider::{
GithubRepositoryProvider, GithubRepositoryProviderService,
};
use crate::schema::repository::{GithubRepositoryProvider, GithubRepositoryService};

pub async fn refresh_all_repositories(
service: Arc<dyn GithubRepositoryProviderService>,
) -> Result<()> {
pub async fn refresh_all_repositories(service: Arc<dyn GithubRepositoryService>) -> Result<()> {

Check warning on line 11 in ee/tabby-webserver/src/cron/db/github.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/github.rs#L11

Added line #L11 was not covered by tests
for provider in service
.list_github_repository_providers(vec![], None, None, None, None)
.list_providers(vec![], None, None, None, None)

Check warning on line 13 in ee/tabby-webserver/src/cron/db/github.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/github.rs#L13

Added line #L13 was not covered by tests
.await?
{
let start = Utc::now();
refresh_repositories_for_provider(service.clone(), provider.id.clone()).await?;
service
.delete_outdated_github_provided_repositories(provider.id, start)
.delete_outdated_repositories(provider.id, start)

Check warning on line 19 in ee/tabby-webserver/src/cron/db/github.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/github.rs#L19

Added line #L19 was not covered by tests
.await?;
}
Ok(())
}

async fn refresh_repositories_for_provider(
service: Arc<dyn GithubRepositoryProviderService>,
service: Arc<dyn GithubRepositoryService>,

Check warning on line 26 in ee/tabby-webserver/src/cron/db/github.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/github.rs#L26

Added line #L26 was not covered by tests
provider_id: ID,
) -> Result<()> {
let provider = service.get_github_repository_provider(provider_id).await?;
let provider = service.get_provider(provider_id).await?;

Check warning on line 29 in ee/tabby-webserver/src/cron/db/github.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/github.rs#L29

Added line #L29 was not covered by tests
let repos = match fetch_all_repos(&provider).await {
Ok(repos) => repos,
Err(octocrab::Error::GitHub {
source: source @ GitHubError { .. },
..
}) if source.status_code.is_client_error() => {
service
.update_github_repository_provider_sync_status(provider.id.clone(), false)
.update_provider_status(provider.id.clone(), false)

Check warning on line 37 in ee/tabby-webserver/src/cron/db/github.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/github.rs#L37

Added line #L37 was not covered by tests
.await?;
warn!(
"GitHub credentials for provider {} are expired or invalid",
Expand All @@ -64,7 +60,7 @@
let url = url.strip_suffix(".git").unwrap_or(&url);

service
.upsert_github_provided_repository(
.upsert_repository(

Check warning on line 63 in ee/tabby-webserver/src/cron/db/github.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/github.rs#L63

Added line #L63 was not covered by tests
provider.id.clone(),
id,
repo.full_name.unwrap_or(repo.name),
Expand All @@ -73,7 +69,7 @@
.await?;
}
service
.update_github_repository_provider_sync_status(provider.id.clone(), true)
.update_provider_status(provider.id.clone(), true)

Check warning on line 72 in ee/tabby-webserver/src/cron/db/github.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/github.rs#L72

Added line #L72 was not covered by tests
.await?;

Ok(())
Expand Down
22 changes: 9 additions & 13 deletions ee/tabby-webserver/src/cron/db/gitlab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,32 @@
use serde::Deserialize;
use tracing::warn;

use crate::schema::gitlab_repository_provider::{
GitlabRepositoryProvider, GitlabRepositoryProviderService,
};
use crate::schema::repository::{GitlabRepositoryProvider, GitlabRepositoryService};

pub async fn refresh_all_repositories(
service: Arc<dyn GitlabRepositoryProviderService>,
) -> Result<()> {
pub async fn refresh_all_repositories(service: Arc<dyn GitlabRepositoryService>) -> Result<()> {

Check warning on line 15 in ee/tabby-webserver/src/cron/db/gitlab.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/gitlab.rs#L15

Added line #L15 was not covered by tests
for provider in service
.list_gitlab_repository_providers(vec![], None, None, None, None)
.list_providers(vec![], None, None, None, None)

Check warning on line 17 in ee/tabby-webserver/src/cron/db/gitlab.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/gitlab.rs#L17

Added line #L17 was not covered by tests
.await?
{
let start = Utc::now();
refresh_repositories_for_provider(service.clone(), provider.id.clone()).await?;
service
.delete_outdated_gitlab_provided_repositories(provider.id, start)
.delete_outdated_repositories(provider.id, start)

Check warning on line 23 in ee/tabby-webserver/src/cron/db/gitlab.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/gitlab.rs#L23

Added line #L23 was not covered by tests
.await?;
}
Ok(())
}

async fn refresh_repositories_for_provider(
service: Arc<dyn GitlabRepositoryProviderService>,
service: Arc<dyn GitlabRepositoryService>,

Check warning on line 30 in ee/tabby-webserver/src/cron/db/gitlab.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/gitlab.rs#L30

Added line #L30 was not covered by tests
provider_id: ID,
) -> Result<()> {
let provider = service.get_gitlab_repository_provider(provider_id).await?;
let provider = service.get_provider(provider_id).await?;

Check warning on line 33 in ee/tabby-webserver/src/cron/db/gitlab.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/gitlab.rs#L33

Added line #L33 was not covered by tests
let repos = match fetch_all_repos(&provider).await {
Ok(repos) => repos,
Err(e) if e.to_string().contains("401 Unauthorized") => {
service
.update_gitlab_repository_provider_sync_status(provider.id.clone(), false)
.update_provider_status(provider.id.clone(), false)

Check warning on line 38 in ee/tabby-webserver/src/cron/db/gitlab.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/gitlab.rs#L38

Added line #L38 was not covered by tests
.await?;
warn!(
"GitLab credentials for provider {} are expired or invalid",
Expand All @@ -58,7 +54,7 @@
let url = url.strip_suffix(".git").unwrap_or(&url);

service
.upsert_gitlab_provided_repository(
.upsert_repository(

Check warning on line 57 in ee/tabby-webserver/src/cron/db/gitlab.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/gitlab.rs#L57

Added line #L57 was not covered by tests
provider.id.clone(),
id,
repo.name_with_namespace,
Expand All @@ -67,7 +63,7 @@
.await?;
}
service
.update_gitlab_repository_provider_sync_status(provider.id.clone(), true)
.update_provider_status(provider.id.clone(), true)

Check warning on line 66 in ee/tabby-webserver/src/cron/db/gitlab.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/gitlab.rs#L66

Added line #L66 was not covered by tests
.await?;

Ok(())
Expand Down
9 changes: 5 additions & 4 deletions ee/tabby-webserver/src/cron/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
use tracing::{debug, error};

use crate::schema::{
auth::AuthenticationService, github_repository_provider::GithubRepositoryProviderService,
gitlab_repository_provider::GitlabRepositoryProviderService, job::JobService,
auth::AuthenticationService,
job::JobService,
repository::{GithubRepositoryService, GitlabRepositoryService},
};

const EVERY_TWO_HOURS: &str = "0 0 1/2 * * * *";
Expand Down Expand Up @@ -64,7 +65,7 @@
}

pub async fn update_integrated_github_repositories_job(
github_repository_provider: Arc<dyn GithubRepositoryProviderService>,
github_repository_provider: Arc<dyn GithubRepositoryService>,

Check warning on line 68 in ee/tabby-webserver/src/cron/db/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/mod.rs#L68

Added line #L68 was not covered by tests
) -> Result<Job> {
service_job(
"sync github repositories",
Expand All @@ -79,7 +80,7 @@
}

pub async fn update_integrated_gitlab_repositories_job(
gitlab_repository_provider: Arc<dyn GitlabRepositoryProviderService>,
gitlab_repository_provider: Arc<dyn GitlabRepositoryService>,

Check warning on line 83 in ee/tabby-webserver/src/cron/db/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/mod.rs#L83

Added line #L83 was not covered by tests
) -> Result<Job> {
service_job(
"sync gitlab repositories",
Expand Down
Loading
Loading