From 1d53952c8efd4513e614692417889e723645afb9 Mon Sep 17 00:00:00 2001 From: boxbeam Date: Fri, 26 Apr 2024 13:47:27 -0400 Subject: [PATCH 1/8] feat(webserver, db): track github/gitlab provider status with synced_at --- .../migrations/0022_github-provider.up.sql | 4 +- ...down.sql => 0027_gitlab-provider.down.sql} | 0 ...der.up.sql => 0027_gitlab-provider.up.sql} | 3 +- ...ithub-repository-columns-on-oauth.down.sql | 0 ...-github-repository-columns-on-oauth.up.sql | 7 --- ee/tabby-db/schema.sqlite | Bin 176128 -> 176128 bytes ee/tabby-db/src/github_repository_provider.rs | 17 +++++++- ee/tabby-db/src/gitlab_repository_provider.rs | 17 +++++++- ee/tabby-webserver/src/cron/github.rs | 5 ++- ee/tabby-webserver/src/cron/gitlab.rs | 5 ++- .../src/schema/github_repository_provider.rs | 10 +++-- .../src/schema/gitlab_repository_provider.rs | 10 +++-- ee/tabby-webserver/src/schema/types.rs | 19 +++++++- ee/tabby-webserver/src/service/dao.rs | 11 ++++- .../src/service/github_repository_provider.rs | 41 ++++++++---------- .../src/service/gitlab_repository_provider.rs | 37 ++++++---------- 16 files changed, 112 insertions(+), 74 deletions(-) rename ee/tabby-db/migrations/{0028_gitlab-provider.down.sql => 0027_gitlab-provider.down.sql} (100%) rename ee/tabby-db/migrations/{0028_gitlab-provider.up.sql => 0027_gitlab-provider.up.sql} (94%) delete mode 100644 ee/tabby-db/migrations/0027_remove-github-repository-columns-on-oauth.down.sql delete mode 100644 ee/tabby-db/migrations/0027_remove-github-repository-columns-on-oauth.up.sql diff --git a/ee/tabby-db/migrations/0022_github-provider.up.sql b/ee/tabby-db/migrations/0022_github-provider.up.sql index 0634b42cb7ac..b72697de3795 100644 --- a/ee/tabby-db/migrations/0022_github-provider.up.sql +++ b/ee/tabby-db/migrations/0022_github-provider.up.sql @@ -1,8 +1,6 @@ CREATE TABLE github_repository_provider( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, display_name TEXT NOT NULL, - application_id TEXT NOT NULL, - secret TEXT NOT NULL, access_token TEXT, - CONSTRAINT `idx_application_id` UNIQUE (`application_id`) + synced_at TIMESTAMP ); diff --git a/ee/tabby-db/migrations/0028_gitlab-provider.down.sql b/ee/tabby-db/migrations/0027_gitlab-provider.down.sql similarity index 100% rename from ee/tabby-db/migrations/0028_gitlab-provider.down.sql rename to ee/tabby-db/migrations/0027_gitlab-provider.down.sql diff --git a/ee/tabby-db/migrations/0028_gitlab-provider.up.sql b/ee/tabby-db/migrations/0027_gitlab-provider.up.sql similarity index 94% rename from ee/tabby-db/migrations/0028_gitlab-provider.up.sql rename to ee/tabby-db/migrations/0027_gitlab-provider.up.sql index 4c1103d69d07..f0e387f91ca8 100644 --- a/ee/tabby-db/migrations/0028_gitlab-provider.up.sql +++ b/ee/tabby-db/migrations/0027_gitlab-provider.up.sql @@ -1,7 +1,8 @@ CREATE TABLE gitlab_repository_provider( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, display_name TEXT NOT NULL, - access_token TEXT + access_token TEXT, + synced_at TIMESTAMP ); CREATE TABLE gitlab_provided_repositories( diff --git a/ee/tabby-db/migrations/0027_remove-github-repository-columns-on-oauth.down.sql b/ee/tabby-db/migrations/0027_remove-github-repository-columns-on-oauth.down.sql deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/ee/tabby-db/migrations/0027_remove-github-repository-columns-on-oauth.up.sql b/ee/tabby-db/migrations/0027_remove-github-repository-columns-on-oauth.up.sql deleted file mode 100644 index 424f642b519d..000000000000 --- a/ee/tabby-db/migrations/0027_remove-github-repository-columns-on-oauth.up.sql +++ /dev/null @@ -1,7 +0,0 @@ -DROP TABLE github_repository_provider; - -CREATE TABLE github_repository_provider( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - display_name TEXT NOT NULL, - access_token TEXT -); diff --git a/ee/tabby-db/schema.sqlite b/ee/tabby-db/schema.sqlite index 325abece2c60ba6cf0326220d74ca06681fe9f69..666a0bcbe2d842b1162706bb3a60e5a4c4536cfd 100644 GIT binary patch delta 1412 zcmbV~ZA@Eb6vyv*ZrckN@U~gj(ii$h%b>t$J5uI04Al``B4e2wukC0{OJTIdFv3O@ zM+t0dbm@GEPw*4eFKkORtO+$vaPxyRTgHswj4>v28Z$DpY&sT~DfrYkZa?_Nn|sf_ z`JHqB=YP(&`ki)Xb)~(!(&;ifYIZob?{L&Sy>>2L{vCS)Z(6$%n(__>N-Kv( z`@c~)DkonZsoK-@-nMH0c3H*ZoAoQ*p_5;I-nxGo%avw+LjmtnI?&E}+^5uwDN)*4 zPwzu~MOiAwzh&_19bBcV7UQVO&bBNE@RZ72yCHr3!v2G|&OboWQ+Eb`6Ju~5-w2a-iy>{^n*3!_Qzc=~F-S+h`URP!Ha}?Uy_V+)*!9t_B-zkbc z-*@9ng;}OoC_Xgrz&drAxVlkoXJ1zWHQQYbY;Kw?Vhzr|_9O&9D>@5-*ap99iRAbX|{9#d+#$AeA3spUP1Q6 zy9KHIRlYd)O0J4q;y(Z{FNK5PJw5FsulwLCFSE+16vH$ZlMX*Lfh9fX2ZaO#yv}LJ zy&%%hb-@y_qi!qtv>VJ&l3wWsBY=hQhoKRyr0p>H;jgzPmhnb2QTD=aGVVhPESE^q zeZ6oDfr;FX!UZ87HF7Gq8%9F|{y-!|=6gXyR-;Hmter?fj4>3~RPaW692tsrhJqdb z0po!^4fQV^a5wDZ)5#bdx|FPwpRbe1(~>$^6KuB`9?dXZm+YSOS=l-EzLaO7z=LM; z&-^*ozX8pp-13(ZYTlZe(?BMos3y-Ak5>Hchx`;kPZA+UUAQ_?T>sxL%0`v8^hcdY z1yGKE=X9ARnQ}@wRaqH~4dahxwdtl1(gT#y>`n!@#N=dL3~ZsDiXpBbRbjN5EOyb* z6h`{Y6HoHONCzdPG>o=FDQOO)T@r?o+#r{`!SsJtZbL%cUd5@}>mlCI6AOlpk<(FB kL~5h7*~17LX2(sH#O*`7L7qP0LmmWt3he6!x?Oty0f|tMjsO4v delta 1449 zcmb7@drVtZ9LM`RZRu!%woY35egNgQLR;8?xeBON9NV%)rh6FYm>ER3`Pc$k_J^BpL?@ocsJ)5*nB3pV%_raU z{eI6qx%+Mi_uUWf!|i8wxy>}Cxx2yK z;cjO-yi* zTlM^=jD)K6sj`NPTYtH3Dmd^`&&jLt2WwG3mdK34f4b-4EixcYq5#;yNakMk2f;*qbG_Uv3gxH0IQT^XJfe|mXB zHP1Y@`>neVn!SN4%MWRL78DnBcgmNqG}n|?;59ib&zeAu1M|2sK_8hnNb%0H1$-uf zReG7?n)hDCYDHS4x>8}`w)S7geTtMw9HiI|BlwmgITFV!srP5E;}Rtc_fTwqCkY={ z8Y0yTVSG-5*Qrk4F7848Z6M~B5_TyNUs#* z`Yaw&tAq7f$4(Cyilm8D5*{NRB^^ajYWYzd7?K2r3a6g~o+MQSa~z(8`z6eYTg6dv zW3fMp)(dBZf^}!(mSWCFuY!Yae zGD7!VNDi<8KN6_J{SA;7dd7_!0MaRXBDyP;?oNbWDPcS)p2X1w(h2b(P550%$~;I7 zDWuthGD)HbX~~oa>3DHtd^7pR1BU;9>=>g!-fD*4R&TGxN~H7 pNqV=N|31)3Kjf2Q7m{KLk4Hpp@LH5GEqq_0@iwp<0)-O#{0Uf5s~`XX diff --git a/ee/tabby-db/src/github_repository_provider.rs b/ee/tabby-db/src/github_repository_provider.rs index f6c666783a0c..8c9f191f662d 100644 --- a/ee/tabby-db/src/github_repository_provider.rs +++ b/ee/tabby-db/src/github_repository_provider.rs @@ -9,6 +9,7 @@ pub struct GithubRepositoryProviderDAO { pub id: i64, pub display_name: String, pub access_token: Option, + pub synced_at: Option, } #[derive(FromRow)] @@ -36,7 +37,7 @@ impl DbConn { pub async fn get_github_provider(&self, id: i64) -> Result { let provider = query_as!( GithubRepositoryProviderDAO, - "SELECT id, display_name, access_token FROM github_repository_provider WHERE id = ?;", + r#"SELECT id, display_name, access_token, synced_at AS "synced_at: DateTimeUtc" FROM github_repository_provider WHERE id = ?;"#, id ) .fetch_one(&self.pool) @@ -95,6 +96,18 @@ impl DbConn { Ok(()) } + pub async fn update_github_provider_synced_at(&self, id: i64, success: bool) -> Result<()> { + let time = success.then_some(DateTimeUtc::now()); + query!( + "UPDATE github_repository_provider SET synced_at = ? WHERE id = ?", + time, + id + ) + .execute(&self.pool) + .await?; + Ok(()) + } + pub async fn list_github_repository_providers( &self, ids: Vec, @@ -113,7 +126,7 @@ impl DbConn { let providers = query_paged_as!( GithubRepositoryProviderDAO, "github_repository_provider", - ["id", "display_name", "access_token"], + ["id", "display_name", "access_token", "synced_at" as "synced_at: DateTimeUtc"], limit, skip_id, backwards, diff --git a/ee/tabby-db/src/gitlab_repository_provider.rs b/ee/tabby-db/src/gitlab_repository_provider.rs index 509498333185..f26d70e4f961 100644 --- a/ee/tabby-db/src/gitlab_repository_provider.rs +++ b/ee/tabby-db/src/gitlab_repository_provider.rs @@ -9,6 +9,7 @@ pub struct GitlabRepositoryProviderDAO { pub id: i64, pub display_name: String, pub access_token: Option, + pub synced_at: Option, } #[derive(FromRow)] @@ -36,7 +37,7 @@ impl DbConn { pub async fn get_gitlab_provider(&self, id: i64) -> Result { let provider = query_as!( GitlabRepositoryProviderDAO, - "SELECT id, display_name, access_token FROM gitlab_repository_provider WHERE id = ?;", + r#"SELECT id, display_name, access_token, synced_at AS "synced_at: DateTimeUtc" FROM gitlab_repository_provider WHERE id = ?;"#, id ) .fetch_one(&self.pool) @@ -95,6 +96,18 @@ impl DbConn { Ok(()) } + pub async fn update_gitlab_provider_synced_at(&self, id: i64, success: bool) -> Result<()> { + let time = success.then_some(DateTimeUtc::now()); + query!( + "UPDATE gitlab_repository_provider SET synced_at = ? WHERE id = ?", + time, + id + ) + .execute(&self.pool) + .await?; + Ok(()) + } + pub async fn list_gitlab_repository_providers( &self, ids: Vec, @@ -113,7 +126,7 @@ impl DbConn { let providers = query_paged_as!( GitlabRepositoryProviderDAO, "gitlab_repository_provider", - ["id", "display_name", "access_token"], + ["id", "display_name", "access_token", "synced_at" as "synced_at: DateTimeUtc"], limit, skip_id, backwards, diff --git a/ee/tabby-webserver/src/cron/github.rs b/ee/tabby-webserver/src/cron/github.rs index 4d49a3a1e3fa..bef73e9f4b3b 100644 --- a/ee/tabby-webserver/src/cron/github.rs +++ b/ee/tabby-webserver/src/cron/github.rs @@ -38,7 +38,7 @@ async fn refresh_repositories_for_provider( .. }) if source.status_code.is_client_error() => { service - .reset_github_repository_provider_access_token(provider.id.clone()) + .update_github_repository_provider_sync_status(provider.id.clone(), false) .await?; warn!( "GitHub credentials for provider {} are expired or invalid", @@ -66,6 +66,9 @@ async fn refresh_repositories_for_provider( .upsert_github_provided_repository(provider.id.clone(), id, repo.name, url) .await?; } + service + .update_github_repository_provider_sync_status(provider.id.clone(), true) + .await?; Ok(()) } diff --git a/ee/tabby-webserver/src/cron/gitlab.rs b/ee/tabby-webserver/src/cron/gitlab.rs index 1639c673d14b..6c7e27ec28fd 100644 --- a/ee/tabby-webserver/src/cron/gitlab.rs +++ b/ee/tabby-webserver/src/cron/gitlab.rs @@ -39,7 +39,7 @@ async fn refresh_repositories_for_provider( Ok(repos) => repos, Err(e) if e.to_string().contains("401 Unauthorized") => { service - .reset_gitlab_repository_provider_access_token(provider.id.clone()) + .update_gitlab_repository_provider_sync_status(provider.id.clone(), false) .await?; warn!( "GitLab credentials for provider {} are expired or invalid", @@ -64,6 +64,9 @@ async fn refresh_repositories_for_provider( ) .await?; } + service + .update_gitlab_repository_provider_sync_status(provider.id.clone(), true) + .await?; Ok(()) } diff --git a/ee/tabby-webserver/src/schema/github_repository_provider.rs b/ee/tabby-webserver/src/schema/github_repository_provider.rs index fdf4ebaf319e..3412729f2b6e 100644 --- a/ee/tabby-webserver/src/schema/github_repository_provider.rs +++ b/ee/tabby-webserver/src/schema/github_repository_provider.rs @@ -2,7 +2,7 @@ use async_trait::async_trait; use chrono::{DateTime, Utc}; use juniper::{GraphQLObject, ID}; -use super::{repository::RepositoryProvider, Context}; +use super::{repository::RepositoryProvider, types::RepositoryProviderStatus, Context}; use crate::{juniper::relay::NodeType, schema::Result}; #[derive(GraphQLObject, Debug, PartialEq)] @@ -11,7 +11,7 @@ pub struct GithubRepositoryProvider { pub id: ID, pub display_name: String, - pub connected: bool, + pub status: RepositoryProviderStatus, #[graphql(skip)] pub access_token: Option, @@ -75,7 +75,11 @@ pub trait GithubRepositoryProviderService: Send + Sync + RepositoryProvider { display_name: String, access_token: String, ) -> Result<()>; - async fn reset_github_repository_provider_access_token(&self, id: ID) -> Result<()>; + async fn update_github_repository_provider_sync_status( + &self, + id: ID, + success: bool, + ) -> Result<()>; async fn list_github_repository_providers( &self, diff --git a/ee/tabby-webserver/src/schema/gitlab_repository_provider.rs b/ee/tabby-webserver/src/schema/gitlab_repository_provider.rs index 71316f44aa6f..b446ddbe80ca 100644 --- a/ee/tabby-webserver/src/schema/gitlab_repository_provider.rs +++ b/ee/tabby-webserver/src/schema/gitlab_repository_provider.rs @@ -2,7 +2,7 @@ use async_trait::async_trait; use chrono::{DateTime, Utc}; use juniper::{GraphQLObject, ID}; -use super::{repository::RepositoryProvider, Context}; +use super::{repository::RepositoryProvider, types::RepositoryProviderStatus, Context}; use crate::{juniper::relay::NodeType, schema::Result}; #[derive(GraphQLObject, Debug, PartialEq)] @@ -11,7 +11,7 @@ pub struct GitlabRepositoryProvider { pub id: ID, pub display_name: String, - pub connected: bool, + pub status: RepositoryProviderStatus, #[graphql(skip)] pub access_token: Option, @@ -75,7 +75,11 @@ pub trait GitlabRepositoryProviderService: Send + Sync + RepositoryProvider { display_name: String, access_token: String, ) -> Result<()>; - async fn reset_gitlab_repository_provider_access_token(&self, id: ID) -> Result<()>; + async fn update_gitlab_repository_provider_sync_status( + &self, + id: ID, + success: bool, + ) -> Result<()>; async fn list_gitlab_repository_providers( &self, diff --git a/ee/tabby-webserver/src/schema/types.rs b/ee/tabby-webserver/src/schema/types.rs index 06ff4ceed7c7..49599e00f7ee 100644 --- a/ee/tabby-webserver/src/schema/types.rs +++ b/ee/tabby-webserver/src/schema/types.rs @@ -1,4 +1,4 @@ -use juniper::{GraphQLInputObject, ID}; +use juniper::{GraphQLEnum, GraphQLInputObject, ID}; use validator::Validate; #[derive(GraphQLInputObject, Validate)] @@ -23,3 +23,20 @@ pub struct UpdateRepositoryProviderInput { #[validate(length(code = "access_token", min = 10))] pub access_token: String, } + +#[derive(GraphQLEnum, Debug, PartialEq)] +pub enum RepositoryProviderStatus { + Ready, + Pending, + Error, +} + +impl RepositoryProviderStatus { + pub fn get_status(access_token_set: bool, synced_at_set: bool) -> Self { + match (access_token_set, synced_at_set) { + (true, true) => RepositoryProviderStatus::Ready, + (true, false) => RepositoryProviderStatus::Pending, + _ => RepositoryProviderStatus::Error, + } + } +} diff --git a/ee/tabby-webserver/src/service/dao.rs b/ee/tabby-webserver/src/service/dao.rs index 6d8b0dca8765..19ab7787d7ef 100644 --- a/ee/tabby-webserver/src/service/dao.rs +++ b/ee/tabby-webserver/src/service/dao.rs @@ -16,6 +16,7 @@ use crate::{ gitlab_repository_provider::{GitlabProvidedRepository, GitlabRepositoryProvider}, job, setting::{NetworkSetting, SecuritySetting}, + types::RepositoryProviderStatus, user_event::{EventKind, UserEvent}, CoreError, }, @@ -130,7 +131,10 @@ impl From for GithubRepositoryProvider { Self { display_name: value.display_name, id: value.id.as_id(), - connected: value.access_token.is_some(), + status: RepositoryProviderStatus::get_status( + value.access_token.is_some(), + value.synced_at.is_some(), + ), access_token: value.access_token, } } @@ -154,7 +158,10 @@ impl From for GitlabRepositoryProvider { Self { display_name: value.display_name, id: value.id.as_id(), - connected: value.access_token.is_some(), + status: RepositoryProviderStatus::get_status( + value.access_token.is_some(), + value.synced_at.is_some(), + ), access_token: value.access_token, } } diff --git a/ee/tabby-webserver/src/service/github_repository_provider.rs b/ee/tabby-webserver/src/service/github_repository_provider.rs index fb78553415fb..7dbf57ed4f32 100644 --- a/ee/tabby-webserver/src/service/github_repository_provider.rs +++ b/ee/tabby-webserver/src/service/github_repository_provider.rs @@ -50,13 +50,6 @@ impl GithubRepositoryProviderService for GithubRepositoryProviderServiceImpl { Ok(()) } - async fn reset_github_repository_provider_access_token(&self, id: ID) -> Result<()> { - self.db - .reset_github_provider_access_token(id.as_rowid()?) - .await?; - Ok(()) - } - async fn list_github_repository_providers( &self, ids: Vec, @@ -183,6 +176,21 @@ impl GithubRepositoryProviderService for GithubRepositoryProviderServiceImpl { .await?; Ok(()) } + + async fn update_github_repository_provider_sync_status( + &self, + id: ID, + success: bool, + ) -> Result<()> { + let id = id.as_rowid()?; + if !success { + self.db.reset_github_provider_access_token(id).await?; + } + self.db + .update_github_provider_synced_at(id, success) + .await?; + Ok(()) + } } #[async_trait] @@ -217,7 +225,7 @@ mod tests { use chrono::Duration; use super::*; - use crate::service::AsID; + use crate::{schema::types::RepositoryProviderStatus, service::AsID}; #[tokio::test] async fn test_github_provided_repositories() { @@ -318,7 +326,7 @@ mod tests { id: id.clone(), display_name: "id".into(), access_token: Some("secret".into()), - connected: true, + status: RepositoryProviderStatus::Pending, } ); @@ -330,21 +338,6 @@ mod tests { assert_eq!(providers.len(), 1); assert_eq!(providers[0].access_token, Some("secret".into())); - // Test resetgithub provider tokens - service - .reset_github_repository_provider_access_token(id.clone()) - .await - .unwrap(); - - assert_eq!( - service - .get_github_repository_provider(id.clone()) - .await - .unwrap() - .access_token, - None - ); - // Test deleting github provider service .delete_github_repository_provider(id.clone()) diff --git a/ee/tabby-webserver/src/service/gitlab_repository_provider.rs b/ee/tabby-webserver/src/service/gitlab_repository_provider.rs index 5c4d328d75cd..4e75a187ce34 100644 --- a/ee/tabby-webserver/src/service/gitlab_repository_provider.rs +++ b/ee/tabby-webserver/src/service/gitlab_repository_provider.rs @@ -50,13 +50,6 @@ impl GitlabRepositoryProviderService for GitlabRepositoryProviderServiceImpl { Ok(()) } - async fn reset_gitlab_repository_provider_access_token(&self, id: ID) -> Result<()> { - self.db - .reset_gitlab_provider_access_token(id.as_rowid()?) - .await?; - Ok(()) - } - async fn list_gitlab_repository_providers( &self, ids: Vec, @@ -186,6 +179,17 @@ impl GitlabRepositoryProviderService for GitlabRepositoryProviderServiceImpl { .await?; Ok(()) } + + async fn update_gitlab_repository_provider_sync_status( + &self, + id: ID, + success: bool, + ) -> Result<()> { + self.db + .update_gitlab_provider_synced_at(id.as_rowid()?, success) + .await?; + Ok(()) + } } fn deduplicate_gitlab_repositories(repositories: &mut Vec) { @@ -220,7 +224,7 @@ mod tests { use chrono::Duration; use super::*; - use crate::service::AsID; + use crate::{schema::types::RepositoryProviderStatus, service::AsID}; #[tokio::test] async fn test_gitlab_provided_repositories() { @@ -321,7 +325,7 @@ mod tests { id: id.clone(), display_name: "id".into(), access_token: Some("secret".into()), - connected: true, + status: RepositoryProviderStatus::Pending } ); @@ -333,21 +337,6 @@ mod tests { assert_eq!(providers.len(), 1); assert_eq!(providers[0].access_token, Some("secret".into())); - // Test resetgitlab provider tokens - service - .reset_gitlab_repository_provider_access_token(id.clone()) - .await - .unwrap(); - - assert_eq!( - service - .get_gitlab_repository_provider(id.clone()) - .await - .unwrap() - .access_token, - None - ); - // Test deleting gitlab provider service .delete_gitlab_repository_provider(id.clone()) From 70085da7599c3b7d3acf908f88e66a2e6885dbd4 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 26 Apr 2024 17:57:59 +0000 Subject: [PATCH 2/8] [autofix.ci] apply automated fixes --- ee/tabby-db/schema/schema.sql | 14 ++++++++------ ee/tabby-db/schema/schema.svg | 8 ++++++++ ee/tabby-webserver/graphql/schema.graphql | 10 ++++++++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/ee/tabby-db/schema/schema.sql b/ee/tabby-db/schema/schema.sql index e855a24eb36d..7877f0cfe181 100644 --- a/ee/tabby-db/schema/schema.sql +++ b/ee/tabby-db/schema/schema.sql @@ -98,6 +98,12 @@ CREATE INDEX user_completions_completion_id_idx ON user_completions( ); CREATE INDEX idx_job_created_at ON job_runs(job, created_at); CREATE INDEX idx_repository_name ON repositories(name); +CREATE TABLE github_repository_provider( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + display_name TEXT NOT NULL, + access_token TEXT, + synced_at TIMESTAMP +); CREATE INDEX idx_user_completion_user_id_created_at_language ON user_completions( user_id, created_at, @@ -144,15 +150,11 @@ CREATE TABLE password_reset( created_at TIMESTAMP NOT NULL DEFAULT(DATETIME('now')), FOREIGN KEY(user_id) REFERENCES users(id) ); -CREATE TABLE github_repository_provider( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - display_name TEXT NOT NULL, - access_token TEXT -); CREATE TABLE gitlab_repository_provider( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, display_name TEXT NOT NULL, - access_token TEXT + access_token TEXT, + synced_at TIMESTAMP ); CREATE TABLE gitlab_provided_repositories( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, diff --git a/ee/tabby-db/schema/schema.svg b/ee/tabby-db/schema/schema.svg index 096664001962..adb349a8a540 100644 --- a/ee/tabby-db/schema/schema.svg +++ b/ee/tabby-db/schema/schema.svg @@ -128,6 +128,10 @@   access_token + +  + +synced_at @@ -186,6 +190,10 @@   access_token + +  + +synced_at diff --git a/ee/tabby-webserver/graphql/schema.graphql b/ee/tabby-webserver/graphql/schema.graphql index 0f940e9425bd..f386e0cece92 100644 --- a/ee/tabby-webserver/graphql/schema.graphql +++ b/ee/tabby-webserver/graphql/schema.graphql @@ -13,7 +13,7 @@ input UpdateRepositoryProviderInput { type GitlabRepositoryProvider { id: ID! displayName: String! - connected: Boolean! + status: RepositoryProviderStatus! } enum Language { @@ -119,6 +119,12 @@ type UserConnection { pageInfo: PageInfo! } +enum RepositoryProviderStatus { + READY + PENDING + ERROR +} + type DiskUsageStats { events: DiskUsage! indexedRepositories: DiskUsage! @@ -142,7 +148,7 @@ type ServerInfo { type GithubRepositoryProvider { id: ID! displayName: String! - connected: Boolean! + status: RepositoryProviderStatus! } input PasswordChangeInput { From 9b058129ecc592c08027d9375f299e96e07911b1 Mon Sep 17 00:00:00 2001 From: boxbeam Date: Fri, 26 Apr 2024 15:12:03 -0400 Subject: [PATCH 3/8] Fix migrations --- .../migrations/0022_github-provider.up.sql | 4 +++- ...ithub-repository-columns-on-oauth.down.sql | 0 ...-github-repository-columns-on-oauth.up.sql | 8 ++++++++ ...down.sql => 0028_gitlab-provider.down.sql} | 0 ...der.up.sql => 0028_gitlab-provider.up.sql} | 0 ee/tabby-db/schema.sqlite | Bin 176128 -> 176128 bytes 6 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 ee/tabby-db/migrations/0027_remove-github-repository-columns-on-oauth.down.sql create mode 100644 ee/tabby-db/migrations/0027_remove-github-repository-columns-on-oauth.up.sql rename ee/tabby-db/migrations/{0027_gitlab-provider.down.sql => 0028_gitlab-provider.down.sql} (100%) rename ee/tabby-db/migrations/{0027_gitlab-provider.up.sql => 0028_gitlab-provider.up.sql} (100%) diff --git a/ee/tabby-db/migrations/0022_github-provider.up.sql b/ee/tabby-db/migrations/0022_github-provider.up.sql index b72697de3795..0634b42cb7ac 100644 --- a/ee/tabby-db/migrations/0022_github-provider.up.sql +++ b/ee/tabby-db/migrations/0022_github-provider.up.sql @@ -1,6 +1,8 @@ CREATE TABLE github_repository_provider( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, display_name TEXT NOT NULL, + application_id TEXT NOT NULL, + secret TEXT NOT NULL, access_token TEXT, - synced_at TIMESTAMP + CONSTRAINT `idx_application_id` UNIQUE (`application_id`) ); diff --git a/ee/tabby-db/migrations/0027_remove-github-repository-columns-on-oauth.down.sql b/ee/tabby-db/migrations/0027_remove-github-repository-columns-on-oauth.down.sql new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/ee/tabby-db/migrations/0027_remove-github-repository-columns-on-oauth.up.sql b/ee/tabby-db/migrations/0027_remove-github-repository-columns-on-oauth.up.sql new file mode 100644 index 000000000000..d8116958d01d --- /dev/null +++ b/ee/tabby-db/migrations/0027_remove-github-repository-columns-on-oauth.up.sql @@ -0,0 +1,8 @@ +DROP TABLE github_repository_provider; + +CREATE TABLE github_repository_provider( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + display_name TEXT NOT NULL, + access_token TEXT, + synced_at TIMESTAMP +); diff --git a/ee/tabby-db/migrations/0027_gitlab-provider.down.sql b/ee/tabby-db/migrations/0028_gitlab-provider.down.sql similarity index 100% rename from ee/tabby-db/migrations/0027_gitlab-provider.down.sql rename to ee/tabby-db/migrations/0028_gitlab-provider.down.sql diff --git a/ee/tabby-db/migrations/0027_gitlab-provider.up.sql b/ee/tabby-db/migrations/0028_gitlab-provider.up.sql similarity index 100% rename from ee/tabby-db/migrations/0027_gitlab-provider.up.sql rename to ee/tabby-db/migrations/0028_gitlab-provider.up.sql diff --git a/ee/tabby-db/schema.sqlite b/ee/tabby-db/schema.sqlite index 666a0bcbe2d842b1162706bb3a60e5a4c4536cfd..e9dce0a00e756915273eafa406f8c83c877073fb 100644 GIT binary patch delta 1360 zcmb7@e@t6d6vun+d+lpqXd(v=65wuFIm zf4IUDvuF%M?y@_KQ+~uOqSK5n)PTYLNTzenUu zGZuBm0t5YB)k5_Kr?A0Uy)obQNUfw(RTn<<_VNT*J8nZBdA+Uu^(_tF57)HSjmvjC z&Xye_SB==S^s%RP>C+?YX1t$2KeywU!JbCMAW*)e@8howZLB<+5x;~%(QXk3Y51=jd$fb(rt!Q?ADw3bZ*Ats>EJU zp257SBAwS_5~$vlGQ8hZmSzcw`P}c|UrnWHmSdJ`Uww$Tnlo&V#CHB+#M9=&blzo& z`OXbur6uE~+9K876miH>lg^uvSjYBJe94m0qj-UeFYLt|`HWtGcd4fjcB&YtmoA>h zM<3h!k{4*%u(*UD@EMV^Jjp=wBKGHH3>=VHYs)I0%X6j;+)lA`-(kBo)2!L*LO;&n z_+x0=D$Ox^5HDLx(xqyf#BO-;W?N>qof7jMzlz6fnHCpq0_z=fvZ+6V^I<06jW}Pz zlW*p5dlij%KG9w^ermKqt#?Q%sVI=bEQKkd7jANsBf80vhS_I<)|IMZK}PGSZ()IZ ziBo8&G%MGkjWLtb5VFp8!Xn_GfFoO)Y2pJJ5(M0ye5H~ z*jbH_rBX)!doQPnbPSmWsDvN4CzTsL^(t&Em8&%QC{ksCC`Y6hZ52yqDtZrk(Hbjk&V_) zq2I_A5$ylxyhJ*0JvAh_$VWYB2C7I~1T~Uy81%`L5!8&(4k0yd8#&*B+_Y{e;v};X eXdsP2q{lj%Ch900p;PyiJQfA7eX>C(z5f8dH;Q-w delta 1211 zcmbV~ZA@EL7{~8(?(Mzww&k|bwe*F)K+B*oxK-C0DoYzl=7)`$C3C=9Z41;{C?sl7 zGbe+v7#C-%XW0>BCSzY<`(R2Fu5KAJzbtOqmI%@KVUgfVSe7iJ+u}k7p1Sqc&nEYr zll-3N{QuAMoO@(hJhCk28lfrQbX{uqF$`li8|ZG=Qj(1>xn0F6&;2Ut6fZm|oY z*1)r^fe`N5BC}n4m#}2^sVr;`pzuXJX!fY+q*-QT{rB;A=0=sR7umhrxY-g?*?>i6 zJC{=U3yZJyvBixGd-tu(-bLAuZV&%01^=8o+4f=Xul3H3&oozOP9!J1<7@s87QSb_ zyI|?fRjb+@r!4l%LA+2^E^(EzmoEme-P)w)by#Kg z(DfJ|wfa>yOIf_ehJUlxtL#Y|Wp54RowhO?F0!Wv@Qlr?<}FcnAkl>dd%2c?owhuG z2lv{yt9g@@^@*49qP?t#98@nqjki0>dI?8BH-5KID?qsTH28Bh7Q~lnepf7o*BvE| zAof>NuWKtfUS0AJ;`b@*eqscluip09KZx&8)>U;2dz>Y&Al~H+pl1|3@*i~8N##y= z;+xK`>Q$YKws`bCyu(!*Z4jr6?D<|i;VN5PbID@oI}gO-uPG(4;0_f`a*b3-v`j91 zlGB-NG*DdD(n-U=N>e%GR4y|2B5=k!JR{CHKxUr~DAnsR@2kMkt z2f+>CC1M8lfRA)%APJAIa^9nRYRJ%QsGU5_AQLunoHEo8ZzJ%K)ht|KN3(7+mqihB zJoP9{bc5(q<;)<&FHJ>^vk}gya1q#${Hu(JrWqm4|DoB*pJUfFA`6BXn%2+!TdTUE z=|a@_E<*d8i^aRhp)3k<{?Tj`*`1<3_p``EPNmQ(@GEUS$O6!a9|{gayK?HRW665K z($E0ohw(RjoAP5Xaso8ags> Date: Fri, 26 Apr 2024 19:20:27 +0000 Subject: [PATCH 4/8] [autofix.ci] apply automated fixes --- ee/tabby-db/schema/schema.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ee/tabby-db/schema/schema.sql b/ee/tabby-db/schema/schema.sql index 7877f0cfe181..30bee964deb0 100644 --- a/ee/tabby-db/schema/schema.sql +++ b/ee/tabby-db/schema/schema.sql @@ -98,12 +98,6 @@ CREATE INDEX user_completions_completion_id_idx ON user_completions( ); CREATE INDEX idx_job_created_at ON job_runs(job, created_at); CREATE INDEX idx_repository_name ON repositories(name); -CREATE TABLE github_repository_provider( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - display_name TEXT NOT NULL, - access_token TEXT, - synced_at TIMESTAMP -); CREATE INDEX idx_user_completion_user_id_created_at_language ON user_completions( user_id, created_at, @@ -150,6 +144,12 @@ CREATE TABLE password_reset( created_at TIMESTAMP NOT NULL DEFAULT(DATETIME('now')), FOREIGN KEY(user_id) REFERENCES users(id) ); +CREATE TABLE github_repository_provider( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + display_name TEXT NOT NULL, + access_token TEXT, + synced_at TIMESTAMP +); CREATE TABLE gitlab_repository_provider( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, display_name TEXT NOT NULL, From ff7c5b8946ee73190541b9eab1d7db0d8a675a74 Mon Sep 17 00:00:00 2001 From: boxbeam Date: Fri, 26 Apr 2024 15:26:19 -0400 Subject: [PATCH 5/8] Perform status update logic in db layer --- ee/tabby-db/src/github_repository_provider.rs | 5 ++- ee/tabby-db/src/gitlab_repository_provider.rs | 5 ++- ee/tabby-webserver/src/schema/types.rs | 2 +- ee/tabby-webserver/src/service/dao.rs | 4 +- .../src/service/github_repository_provider.rs | 37 ++++++++++++++++--- .../src/service/gitlab_repository_provider.rs | 33 ++++++++++++++++- 6 files changed, 73 insertions(+), 13 deletions(-) diff --git a/ee/tabby-db/src/github_repository_provider.rs b/ee/tabby-db/src/github_repository_provider.rs index 8c9f191f662d..7dc3387c0639 100644 --- a/ee/tabby-db/src/github_repository_provider.rs +++ b/ee/tabby-db/src/github_repository_provider.rs @@ -96,11 +96,12 @@ impl DbConn { Ok(()) } - pub async fn update_github_provider_synced_at(&self, id: i64, success: bool) -> Result<()> { + pub async fn update_github_provider_sync_status(&self, id: i64, success: bool) -> Result<()> { let time = success.then_some(DateTimeUtc::now()); query!( - "UPDATE github_repository_provider SET synced_at = ? WHERE id = ?", + "UPDATE github_repository_provider SET synced_at = ?, access_token = IIF(?, access_token, NULL) WHERE id = ?", time, + success, id ) .execute(&self.pool) diff --git a/ee/tabby-db/src/gitlab_repository_provider.rs b/ee/tabby-db/src/gitlab_repository_provider.rs index f26d70e4f961..b4da3b0058c6 100644 --- a/ee/tabby-db/src/gitlab_repository_provider.rs +++ b/ee/tabby-db/src/gitlab_repository_provider.rs @@ -96,11 +96,12 @@ impl DbConn { Ok(()) } - pub async fn update_gitlab_provider_synced_at(&self, id: i64, success: bool) -> Result<()> { + pub async fn update_gitlab_provider_sync_status(&self, id: i64, success: bool) -> Result<()> { let time = success.then_some(DateTimeUtc::now()); query!( - "UPDATE gitlab_repository_provider SET synced_at = ? WHERE id = ?", + "UPDATE gitlab_repository_provider SET synced_at = ?, access_token = IIF(?, access_token, NULL) WHERE id = ?", time, + success, id ) .execute(&self.pool) diff --git a/ee/tabby-webserver/src/schema/types.rs b/ee/tabby-webserver/src/schema/types.rs index 49599e00f7ee..caff9449b590 100644 --- a/ee/tabby-webserver/src/schema/types.rs +++ b/ee/tabby-webserver/src/schema/types.rs @@ -32,7 +32,7 @@ pub enum RepositoryProviderStatus { } impl RepositoryProviderStatus { - pub fn get_status(access_token_set: bool, synced_at_set: bool) -> Self { + pub fn new(access_token_set: bool, synced_at_set: bool) -> Self { match (access_token_set, synced_at_set) { (true, true) => RepositoryProviderStatus::Ready, (true, false) => RepositoryProviderStatus::Pending, diff --git a/ee/tabby-webserver/src/service/dao.rs b/ee/tabby-webserver/src/service/dao.rs index 19ab7787d7ef..620abd705e57 100644 --- a/ee/tabby-webserver/src/service/dao.rs +++ b/ee/tabby-webserver/src/service/dao.rs @@ -131,7 +131,7 @@ impl From for GithubRepositoryProvider { Self { display_name: value.display_name, id: value.id.as_id(), - status: RepositoryProviderStatus::get_status( + status: RepositoryProviderStatus::new( value.access_token.is_some(), value.synced_at.is_some(), ), @@ -158,7 +158,7 @@ impl From for GitlabRepositoryProvider { Self { display_name: value.display_name, id: value.id.as_id(), - status: RepositoryProviderStatus::get_status( + status: RepositoryProviderStatus::new( value.access_token.is_some(), value.synced_at.is_some(), ), diff --git a/ee/tabby-webserver/src/service/github_repository_provider.rs b/ee/tabby-webserver/src/service/github_repository_provider.rs index 7dbf57ed4f32..b5d764929599 100644 --- a/ee/tabby-webserver/src/service/github_repository_provider.rs +++ b/ee/tabby-webserver/src/service/github_repository_provider.rs @@ -182,12 +182,8 @@ impl GithubRepositoryProviderService for GithubRepositoryProviderServiceImpl { id: ID, success: bool, ) -> Result<()> { - let id = id.as_rowid()?; - if !success { - self.db.reset_github_provider_access_token(id).await?; - } self.db - .update_github_provider_synced_at(id, success) + .update_github_provider_sync_status(id.as_rowid()?, success) .await?; Ok(()) } @@ -385,6 +381,37 @@ mod tests { ); } + #[tokio::test] + async fn test_sync_status() { + let db = DbConn::new_in_memory().await.unwrap(); + let service = create(db.clone()); + + let provider_id = db + .create_github_provider("provider1".into(), "token".into()) + .await + .unwrap(); + + service + .update_github_repository_provider_sync_status(provider_id.as_id(), true) + .await + .unwrap(); + + let provider = db.get_github_provider(provider_id).await.unwrap(); + + assert!(provider.access_token.is_some()); + assert!(provider.synced_at.is_some()); + + service + .update_github_repository_provider_sync_status(provider_id.as_id(), false) + .await + .unwrap(); + + let provider = db.get_github_provider(provider_id).await.unwrap(); + + assert!(provider.access_token.is_none()); + assert!(provider.synced_at.is_none()); + } + #[tokio::test] async fn test_delete_outdated_repos() { let db = DbConn::new_in_memory().await.unwrap(); diff --git a/ee/tabby-webserver/src/service/gitlab_repository_provider.rs b/ee/tabby-webserver/src/service/gitlab_repository_provider.rs index 4e75a187ce34..a948f9377ee0 100644 --- a/ee/tabby-webserver/src/service/gitlab_repository_provider.rs +++ b/ee/tabby-webserver/src/service/gitlab_repository_provider.rs @@ -186,7 +186,7 @@ impl GitlabRepositoryProviderService for GitlabRepositoryProviderServiceImpl { success: bool, ) -> Result<()> { self.db - .update_gitlab_provider_synced_at(id.as_rowid()?, success) + .update_gitlab_provider_sync_status(id.as_rowid()?, success) .await?; Ok(()) } @@ -353,6 +353,37 @@ mod tests { ); } + #[tokio::test] + async fn test_sync_status() { + let db = DbConn::new_in_memory().await.unwrap(); + let service = create(db.clone()); + + let provider_id = db + .create_gitlab_provider("provider1".into(), "token".into()) + .await + .unwrap(); + + service + .update_gitlab_repository_provider_sync_status(provider_id.as_id(), true) + .await + .unwrap(); + + let provider = db.get_gitlab_provider(provider_id).await.unwrap(); + + assert!(provider.access_token.is_some()); + assert!(provider.synced_at.is_some()); + + service + .update_gitlab_repository_provider_sync_status(provider_id.as_id(), false) + .await + .unwrap(); + + let provider = db.get_gitlab_provider(provider_id).await.unwrap(); + + assert!(provider.access_token.is_none()); + assert!(provider.synced_at.is_none()); + } + #[tokio::test] async fn test_provided_git_urls() { let db = DbConn::new_in_memory().await.unwrap(); From 57e401c7b08fa3753bf18ef3e93cc01650773011 Mon Sep 17 00:00:00 2001 From: boxbeam Date: Fri, 26 Apr 2024 15:27:38 -0400 Subject: [PATCH 6/8] Remove unused methods --- ee/tabby-db/src/github_repository_provider.rs | 17 ----------------- ee/tabby-db/src/gitlab_repository_provider.rs | 17 ----------------- 2 files changed, 34 deletions(-) diff --git a/ee/tabby-db/src/github_repository_provider.rs b/ee/tabby-db/src/github_repository_provider.rs index 7dc3387c0639..3be170a834f3 100644 --- a/ee/tabby-db/src/github_repository_provider.rs +++ b/ee/tabby-db/src/github_repository_provider.rs @@ -55,23 +55,6 @@ impl DbConn { Ok(()) } - pub async fn reset_github_provider_access_token(&self, id: i64) -> Result<()> { - let res = query!( - "UPDATE github_repository_provider SET access_token = NULL WHERE id = ?", - id - ) - .execute(&self.pool) - .await?; - - if res.rows_affected() != 1 { - return Err(anyhow!( - "The specified Github repository provider does not exist" - )); - } - - Ok(()) - } - pub async fn update_github_provider( &self, id: i64, diff --git a/ee/tabby-db/src/gitlab_repository_provider.rs b/ee/tabby-db/src/gitlab_repository_provider.rs index b4da3b0058c6..e12dddb37781 100644 --- a/ee/tabby-db/src/gitlab_repository_provider.rs +++ b/ee/tabby-db/src/gitlab_repository_provider.rs @@ -55,23 +55,6 @@ impl DbConn { Ok(()) } - pub async fn reset_gitlab_provider_access_token(&self, id: i64) -> Result<()> { - let res = query!( - "UPDATE gitlab_repository_provider SET access_token = NULL WHERE id = ?", - id - ) - .execute(&self.pool) - .await?; - - if res.rows_affected() != 1 { - return Err(anyhow!( - "The specified gitlab repository provider does not exist" - )); - } - - Ok(()) - } - pub async fn update_gitlab_provider( &self, id: i64, From f1e82caee85940bb0d88d2af077a98f775905f81 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Fri, 26 Apr 2024 13:22:42 -0700 Subject: [PATCH 7/8] update ui --- .../github/components/github-form.tsx | 8 +------- .../repository/github/components/github.tsx | 17 ++++++++++++---- .../github/detail/components/detail.tsx | 20 +++++++++++++------ ee/tabby-ui/lib/tabby/query.ts | 2 +- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/components/github-form.tsx b/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/components/github-form.tsx index 2b1c11cee917..0284528294fb 100644 --- a/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/components/github-form.tsx +++ b/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/components/github-form.tsx @@ -34,13 +34,7 @@ import { IconExternalLink, IconSpinner } from '@/components/ui/icons' import { Input } from '@/components/ui/input' export const createGithubProviderSchema = z.object({ - displayName: z - .string() - .trim() - .regex( - /^[\w-]+$/, - 'Display name must contain only alphanumeric characters, underscores, and hyphens' - ), + displayName: z.string(), accessToken: z.string() }) diff --git a/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/components/github.tsx b/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/components/github.tsx index 0535c097248c..d481588fcc3c 100644 --- a/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/components/github.tsx +++ b/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/components/github.tsx @@ -3,7 +3,7 @@ import Link from 'next/link' import { useQuery } from 'urql' -import { ListGithubRepositoryProvidersQuery } from '@/lib/gql/generates/graphql' +import { ListGithubRepositoryProvidersQuery, RepositoryProviderStatus } from '@/lib/gql/generates/graphql' import { listGithubRepositoryProviders } from '@/lib/tabby/query' import { buttonVariants } from '@/components/ui/button' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' @@ -66,9 +66,7 @@ const GitProvidersList: React.FC = ({ data }) => { Status - {item.node?.connected - ? 'Connected' - : 'access_token needs update'} + {toStatusMessage(item.node.status)} @@ -79,6 +77,17 @@ const GitProvidersList: React.FC = ({ data }) => { ) } +function toStatusMessage(status: RepositoryProviderStatus) { + switch (status) { + case RepositoryProviderStatus.Ready: + return "Ready"; + case RepositoryProviderStatus.Error: + return "Processing error. Please check if the access token is still valid" + case RepositoryProviderStatus.Pending: + return "Awaiting the next data synchronization" + } +} + const GitProvidersPlaceholder = () => { return (
diff --git a/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/detail/components/detail.tsx b/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/detail/components/detail.tsx index 5427f9251f5f..63421587def8 100644 --- a/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/detail/components/detail.tsx +++ b/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/detail/components/detail.tsx @@ -36,6 +36,7 @@ import { ListSkeleton } from '@/components/skeleton' import { updateGithubProvidedRepositoryActiveMutation } from '../query' import LinkRepositoryForm from './new-repository-form' import { UpdateProviderForm } from './provider-detail-form' +import { RepositoryProviderStatus } from '@/lib/gql/generates/graphql' type GithubRepositories = QueryResponseData< typeof listGithubRepositories @@ -68,7 +69,7 @@ const DetailPage: React.FC = () => { return ( - +
- {provider?.connected ? ( - Connected - ) : ( - Not Connected - )} + {provider && toStatusBadge(provider.status)}
@@ -108,6 +105,17 @@ const DetailPage: React.FC = () => { ) } +function toStatusBadge(status: RepositoryProviderStatus) { + switch (status) { + case RepositoryProviderStatus.Ready: + return Ready + case RepositoryProviderStatus.Error: + return Error + case RepositoryProviderStatus.Error: + return Pending + } +} + const LinkedRepoTable: React.FC<{ data: GithubRepositories | undefined onDelete?: () => void diff --git a/ee/tabby-ui/lib/tabby/query.ts b/ee/tabby-ui/lib/tabby/query.ts index 3b630e042025..dfb099da152b 100644 --- a/ee/tabby-ui/lib/tabby/query.ts +++ b/ee/tabby-ui/lib/tabby/query.ts @@ -186,7 +186,7 @@ export const listGithubRepositoryProviders = graphql(/* GraphQL */ ` node { id displayName - connected + status } cursor } From 94f2d2efc7a93546d2f7a9181310c29a2641b0cf Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 26 Apr 2024 20:24:10 +0000 Subject: [PATCH 8/8] [autofix.ci] apply automated fixes --- .../repository/github/components/github.tsx | 15 ++++++++------- .../github/detail/components/detail.tsx | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/components/github.tsx b/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/components/github.tsx index d481588fcc3c..39352adcf59b 100644 --- a/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/components/github.tsx +++ b/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/components/github.tsx @@ -3,7 +3,10 @@ import Link from 'next/link' import { useQuery } from 'urql' -import { ListGithubRepositoryProvidersQuery, RepositoryProviderStatus } from '@/lib/gql/generates/graphql' +import { + ListGithubRepositoryProvidersQuery, + RepositoryProviderStatus +} from '@/lib/gql/generates/graphql' import { listGithubRepositoryProviders } from '@/lib/tabby/query' import { buttonVariants } from '@/components/ui/button' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' @@ -65,9 +68,7 @@ const GitProvidersList: React.FC = ({ data }) => { Status - - {toStatusMessage(item.node.status)} - + {toStatusMessage(item.node.status)}
@@ -80,11 +81,11 @@ const GitProvidersList: React.FC = ({ data }) => { function toStatusMessage(status: RepositoryProviderStatus) { switch (status) { case RepositoryProviderStatus.Ready: - return "Ready"; + return 'Ready' case RepositoryProviderStatus.Error: - return "Processing error. Please check if the access token is still valid" + return 'Processing error. Please check if the access token is still valid' case RepositoryProviderStatus.Pending: - return "Awaiting the next data synchronization" + return 'Awaiting the next data synchronization' } } diff --git a/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/detail/components/detail.tsx b/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/detail/components/detail.tsx index 63421587def8..4e5f50cbf409 100644 --- a/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/detail/components/detail.tsx +++ b/ee/tabby-ui/app/(dashboard)/settings/(integrations)/repository/github/detail/components/detail.tsx @@ -5,6 +5,7 @@ import { useRouter, useSearchParams } from 'next/navigation' import { useQuery } from 'urql' import { DEFAULT_PAGE_SIZE } from '@/lib/constants' +import { RepositoryProviderStatus } from '@/lib/gql/generates/graphql' import { QueryResponseData, QueryVariables, useMutation } from '@/lib/tabby/gql' import { listGithubRepositories, @@ -36,7 +37,6 @@ import { ListSkeleton } from '@/components/skeleton' import { updateGithubProvidedRepositoryActiveMutation } from '../query' import LinkRepositoryForm from './new-repository-form' import { UpdateProviderForm } from './provider-detail-form' -import { RepositoryProviderStatus } from '@/lib/gql/generates/graphql' type GithubRepositories = QueryResponseData< typeof listGithubRepositories