Skip to content

Commit

Permalink
Split PR
Browse files Browse the repository at this point in the history
  • Loading branch information
boxbeam committed Apr 10, 2024
1 parent 8749e8b commit fafa445
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ee/tabby-db/migrations/0024_github-provided-repos.down.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-- Add down migration script here
DROP TABLE github_provided_repositories;
2 changes: 2 additions & 0 deletions ee/tabby-db/migrations/0024_github-provided-repos.up.sql
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Binary file modified ee/tabby-db/schema.sqlite
Binary file not shown.
29 changes: 27 additions & 2 deletions ee/tabby-db/src/github_repository_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(())
}

Check warning on line 119 in ee/tabby-db/src/github_repository_provider.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/github_repository_provider.rs#L109-L119

Added lines #L109 - L119 were not covered by tests

Expand All @@ -139,6 +141,7 @@ impl DbConn {
"github_provided_repositories",
[
"id",
"vendor_id",
"name",
"git_url",
"active",
Expand All @@ -153,4 +156,26 @@ impl DbConn {
.await?;
Ok(repos)
}

Check warning on line 158 in ee/tabby-db/src/github_repository_provider.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/github_repository_provider.rs#L132-L158

Added lines #L132 - L158 were not covered by tests

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?;

Check warning on line 173 in ee/tabby-db/src/github_repository_provider.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/github_repository_provider.rs#L160-L173

Added lines #L160 - L173 were not covered by tests

if res.rows_affected() != 1 {
return Err(anyhow!("Repository active status was not changed"));
}

Ok(())
}

Check warning on line 180 in ee/tabby-db/src/github_repository_provider.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/github_repository_provider.rs#L175-L180

Added lines #L175 - L180 were not covered by tests
}
3 changes: 1 addition & 2 deletions ee/tabby-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 17 additions & 2 deletions ee/tabby-webserver/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ enum AuthMethod {
LOGIN
}

type GithubProvidedRepositoryConnection {
edges: [GithubProvidedRepositoryEdge!]!
pageInfo: PageInfo!
}

type RegisterResponse {
accessToken: String!
refreshToken: String!
Expand Down Expand Up @@ -164,6 +169,7 @@ type Mutation {
deleteEmailSetting: Boolean!
uploadLicense(license: String!): Boolean!
resetLicense: Boolean!
updateGithubProvidedRepositoryActive(id: ID!, active: Boolean!): Boolean!
}

type RepositoryEdge {
Expand All @@ -181,8 +187,11 @@ type FileEntrySearchResult {
indices: [Int!]!
}

input NetworkSettingInput {
externalUrl: String!
type GithubProvidedRepository {
id: ID!
githubRepositoryProviderId: ID!
name: String!
gitUrl: String!
}

type Query {
Expand All @@ -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
Expand Down Expand Up @@ -317,6 +327,11 @@ type PageInfo {
endCursor: String
}

type GithubProvidedRepositoryEdge {
node: GithubProvidedRepository!
cursor: String!
}

type Repository {
id: ID!
name: String!
Expand Down
3 changes: 3 additions & 0 deletions ee/tabby-webserver/src/schema/github_repository_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -86,4 +87,6 @@ pub trait GithubRepositoryProviderService: Send + Sync {
first: Option<usize>,
last: Option<usize>,
) -> Result<Vec<GithubProvidedRepository>>;

async fn update_github_provided_repository_active(&self, id: ID, active: bool) -> Result<()>;
}
14 changes: 13 additions & 1 deletion ee/tabby-webserver/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand Down Expand Up @@ -716,6 +716,18 @@ impl Mutation {
.await?;
Ok(true)
}

async fn update_github_provided_repository_active(
ctx: &Context,
id: ID,
active: bool,
) -> Result<bool> {
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> {
Expand Down
1 change: 1 addition & 0 deletions ee/tabby-webserver/src/service/dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl From<GithubProvidedRepositoryDAO> 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,
}
}

Check warning on line 142 in ee/tabby-webserver/src/service/dao.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/dao.rs#L134-L142

Added lines #L134 - L142 were not covered by tests
}
Expand Down
14 changes: 8 additions & 6 deletions ee/tabby-webserver/src/service/github_repository_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,19 @@ 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?;

Check warning on line 90 in ee/tabby-webserver/src/service/github_repository_provider.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/github_repository_provider.rs#L78-L90

Added lines #L78 - L90 were not covered by tests

Ok(repos
.into_iter()
.map(GithubProvidedRepository::from)
.collect())
}

Check warning on line 96 in ee/tabby-webserver/src/service/github_repository_provider.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/github_repository_provider.rs#L92-L96

Added lines #L92 - L96 were not covered by tests

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(())
}

Check warning on line 103 in ee/tabby-webserver/src/service/github_repository_provider.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/github_repository_provider.rs#L98-L103

Added lines #L98 - L103 were not covered by tests
}

0 comments on commit fafa445

Please sign in to comment.