From fafa445bacb55c61e0f5ebb27bc44ebc21c086e8 Mon Sep 17 00:00:00 2001 From: boxbeam Date: Tue, 9 Apr 2024 21:18:20 -0400 Subject: [PATCH] Split PR --- .../0024_github-provided-repos.down.sql | 2 +- .../0024_github-provided-repos.up.sql | 2 ++ ee/tabby-db/schema.sqlite | Bin 147456 -> 147456 bytes ee/tabby-db/src/github_repository_provider.rs | 29 ++++++++++++++++-- ee/tabby-db/src/lib.rs | 3 +- ee/tabby-webserver/graphql/schema.graphql | 19 ++++++++++-- .../src/schema/github_repository_provider.rs | 3 ++ ee/tabby-webserver/src/schema/mod.rs | 14 ++++++++- ee/tabby-webserver/src/service/dao.rs | 1 + .../src/service/github_repository_provider.rs | 14 +++++---- 10 files changed, 73 insertions(+), 14 deletions(-) diff --git a/ee/tabby-db/migrations/0024_github-provided-repos.down.sql b/ee/tabby-db/migrations/0024_github-provided-repos.down.sql index d2f607c5b8bd..92d711019fc3 100644 --- a/ee/tabby-db/migrations/0024_github-provided-repos.down.sql +++ b/ee/tabby-db/migrations/0024_github-provided-repos.down.sql @@ -1 +1 @@ --- Add down migration script here +DROP TABLE github_provided_repositories; diff --git a/ee/tabby-db/migrations/0024_github-provided-repos.up.sql b/ee/tabby-db/migrations/0024_github-provided-repos.up.sql index e6443f774ab3..7ec9760211bd 100644 --- a/ee/tabby-db/migrations/0024_github-provided-repos.up.sql +++ b/ee/tabby-db/migrations/0024_github-provided-repos.up.sql @@ -1,6 +1,8 @@ CREATE TABLE github_provided_repositories( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, github_repository_provider_id INTEGER NOT NULL, + -- vendor_id from https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repositories-for-a-user + vendor_id TEXT NOT NULL, name TEXT NOT NULL, git_url TEXT NOT NULL, active BOOLEAN NOT NULL DEFAULT TRUE, diff --git a/ee/tabby-db/schema.sqlite b/ee/tabby-db/schema.sqlite index 2bce8e694b88307279bc4acc208af3cd6f1ef234..c333d74bcc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}Ih{R#QE_6=`H34+CPy>&ZH{K-Vch;T zh*6iF@xXNDC`Pa83qlx+w%?CpRAp5YWN2aFKhEFBXUcP(+mOqai-DtoEuZxkYbmP` z^8w~;rnL+$Od%5&MsYR!DzS^Zx-z!OPFF}`yfVElneo%~y@`yG+bdESJGi$`2w;q4 ooSqxSSj5P?nX%!&{-Oy2izXN>auC?$z#_1i#Xw;*i@_gx0F_7v_W%F@ diff --git a/ee/tabby-db/src/github_repository_provider.rs b/ee/tabby-db/src/github_repository_provider.rs index 0b5f8c2de0b5..148b45e3f2d3 100644 --- a/ee/tabby-db/src/github_repository_provider.rs +++ b/ee/tabby-db/src/github_repository_provider.rs @@ -16,6 +16,7 @@ pub struct GithubRepositoryProviderDAO { #[derive(FromRow)] pub struct GithubProvidedRepositoryDAO { pub id: i64, + pub vendor_id: String, pub github_repository_provider_id: i64, pub name: String, pub git_url: String, @@ -108,11 +109,12 @@ impl DbConn { pub async fn create_github_provided_repository( &self, github_provider_id: i64, + vendor_id: String, name: String, git_url: String, ) -> Result<()> { - query!("INSERT INTO github_provided_repositories (github_repository_provider_id, name, git_url) VALUES (?, ?, ?)", - github_provider_id, name, git_url).execute(&self.pool).await?; + query!("INSERT INTO github_provided_repositories (github_repository_provider_id, vendor_id, name, git_url) VALUES (?, ?, ?, ?)", + github_provider_id, vendor_id, name, git_url).execute(&self.pool).await?; Ok(()) } @@ -139,6 +141,7 @@ impl DbConn { "github_provided_repositories", [ "id", + "vendor_id", "name", "git_url", "active", @@ -153,4 +156,26 @@ impl DbConn { .await?; Ok(repos) } + + pub async fn update_github_provided_repository_active( + &self, + id: i64, + active: bool, + ) -> Result<()> { + let not_active = !active; + let res = query!( + "UPDATE github_provided_repositories SET active = ? WHERE id = ? AND active = ?", + active, + id, + not_active + ) + .execute(&self.pool) + .await?; + + if res.rows_affected() != 1 { + return Err(anyhow!("Repository active status was not changed")); + } + + Ok(()) + } } diff --git a/ee/tabby-db/src/lib.rs b/ee/tabby-db/src/lib.rs index 2d2ad9023e15..c63809e3d068 100644 --- a/ee/tabby-db/src/lib.rs +++ b/ee/tabby-db/src/lib.rs @@ -4,8 +4,7 @@ use anyhow::anyhow; use cache::Cache; use chrono::{DateTime, NaiveDateTime, Utc}; pub use email_setting::EmailSettingDAO; -pub use github_repository_provider::GithubProvidedRepositoryDAO; -pub use github_repository_provider::GithubRepositoryProviderDAO; +pub use github_repository_provider::{GithubProvidedRepositoryDAO, GithubRepositoryProviderDAO}; pub use invitations::InvitationDAO; pub use job_runs::JobRunDAO; pub use oauth_credential::OAuthCredentialDAO; diff --git a/ee/tabby-webserver/graphql/schema.graphql b/ee/tabby-webserver/graphql/schema.graphql index 23ef1a79eb1e..a749d42b7093 100644 --- a/ee/tabby-webserver/graphql/schema.graphql +++ b/ee/tabby-webserver/graphql/schema.graphql @@ -25,6 +25,11 @@ enum AuthMethod { LOGIN } +type GithubProvidedRepositoryConnection { + edges: [GithubProvidedRepositoryEdge!]! + pageInfo: PageInfo! +} + type RegisterResponse { accessToken: String! refreshToken: String! @@ -164,6 +169,7 @@ type Mutation { deleteEmailSetting: Boolean! uploadLicense(license: String!): Boolean! resetLicense: Boolean! + updateGithubProvidedRepositoryActive(id: ID!, active: Boolean!): Boolean! } type RepositoryEdge { @@ -181,8 +187,11 @@ type FileEntrySearchResult { indices: [Int!]! } -input NetworkSettingInput { - externalUrl: String! +type GithubProvidedRepository { + id: ID! + githubRepositoryProviderId: ID! + name: String! + gitUrl: String! } type Query { @@ -193,6 +202,7 @@ type Query { users(after: String, before: String, first: Int, last: Int): UserConnection! invitations(after: String, before: String, first: Int, last: Int): InvitationConnection! githubRepositoryProviders(after: String, before: String, first: Int, last: Int): GithubRepositoryProviderConnection! + githubProvidedRepositories(githubRepositoryProviderId: ID!, after: String, before: String, first: Int, last: Int): GithubProvidedRepositoryConnection! jobRuns(ids: [ID!], jobs: [String!], after: String, before: String, first: Int, last: Int): JobRunConnection! jobRunStats(jobs: [String!]): JobStats! emailSetting: EmailSetting @@ -317,6 +327,11 @@ type PageInfo { endCursor: String } +type GithubProvidedRepositoryEdge { + node: GithubProvidedRepository! + cursor: String! +} + type Repository { id: ID! name: String! diff --git a/ee/tabby-webserver/src/schema/github_repository_provider.rs b/ee/tabby-webserver/src/schema/github_repository_provider.rs index 6b5cead433f7..040c03e61221 100644 --- a/ee/tabby-webserver/src/schema/github_repository_provider.rs +++ b/ee/tabby-webserver/src/schema/github_repository_provider.rs @@ -33,6 +33,7 @@ impl NodeType for GithubRepositoryProvider { #[graphql(context = Context)] pub struct GithubProvidedRepository { pub id: ID, + pub vendor_id: String, pub github_repository_provider_id: ID, pub name: String, pub git_url: String, @@ -86,4 +87,6 @@ pub trait GithubRepositoryProviderService: Send + Sync { first: Option, last: Option, ) -> Result>; + + async fn update_github_provided_repository_active(&self, id: ID, active: bool) -> Result<()>; } diff --git a/ee/tabby-webserver/src/schema/mod.rs b/ee/tabby-webserver/src/schema/mod.rs index f69befcfca7d..f28cb475df67 100644 --- a/ee/tabby-webserver/src/schema/mod.rs +++ b/ee/tabby-webserver/src/schema/mod.rs @@ -256,7 +256,7 @@ impl Query { .await } - async fn github_provided_repositories( + async fn github_repositories_by_provider( ctx: &Context, github_repository_provider_id: ID, after: Option, @@ -716,6 +716,18 @@ impl Mutation { .await?; Ok(true) } + + async fn update_github_provided_repository_active( + ctx: &Context, + id: ID, + active: bool, + ) -> Result { + ctx.locator + .github_repository_provider() + .update_github_provided_repository_active(id, active) + .await?; + Ok(true) + } } async fn check_analytic_access(ctx: &Context, users: &[ID]) -> Result<(), CoreError> { diff --git a/ee/tabby-webserver/src/service/dao.rs b/ee/tabby-webserver/src/service/dao.rs index cc517c58c3c6..91bdbb305084 100644 --- a/ee/tabby-webserver/src/service/dao.rs +++ b/ee/tabby-webserver/src/service/dao.rs @@ -137,6 +137,7 @@ impl From for GithubProvidedRepository { github_repository_provider_id: value.github_repository_provider_id.as_id(), name: value.name, git_url: value.git_url, + vendor_id: value.vendor_id, } } } diff --git a/ee/tabby-webserver/src/service/github_repository_provider.rs b/ee/tabby-webserver/src/service/github_repository_provider.rs index 69123f09d3d8..122ffec727a2 100644 --- a/ee/tabby-webserver/src/service/github_repository_provider.rs +++ b/ee/tabby-webserver/src/service/github_repository_provider.rs @@ -86,12 +86,7 @@ impl GithubRepositoryProviderService for GithubRepositoryProviderServiceImpl { let (limit, skip_id, backwards) = graphql_pagination_to_filter(after, before, last, first)?; let repos = self .db - .list_github_provided_repositories( - provider.as_rowid()? as i64, - limit, - skip_id, - backwards, - ) + .list_github_provided_repositories(provider.as_rowid()?, limit, skip_id, backwards) .await?; Ok(repos @@ -99,4 +94,11 @@ impl GithubRepositoryProviderService for GithubRepositoryProviderServiceImpl { .map(GithubProvidedRepository::from) .collect()) } + + async fn update_github_provided_repository_active(&self, id: ID, active: bool) -> Result<()> { + self.db + .update_github_provided_repository_active(id.as_rowid()?, active) + .await?; + Ok(()) + } }