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

feat(webserver, db): refactor gitlab and github integrations into unified integration / third party repository services #2088

Merged
merged 24 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "crates/llama-cpp-bindings/llama.cpp"]
[submodule "crates/llama-cpp-server/llama.cpp"]
path = crates/llama-cpp-server/llama.cpp
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be a bug introduced by a previous PR? Tests were failing until making this change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did rebase against main

url = https://github.com/ggerganov/llama.cpp
2 changes: 1 addition & 1 deletion ee/tabby-db-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub fn query_paged_as(input: TokenStream) -> TokenStream {
let backwards = input.backwards;
quote! {
sqlx::query_as(&crate::make_pagination_query_with_condition({
let _ = sqlx::query_as!(#typ, "SELECT " + #columns + " FROM " + #table_name);
let _ = sqlx::query_as!(#typ, "SELECT " + #columns + " FROM (SELECT * FROM " + #table_name + ")");
&#table_name
}, &[ #(#column_args),* ], #limit, #skip_id, #backwards, #condition))
}
Expand Down
11 changes: 9 additions & 2 deletions ee/tabby-db/migrations/0029_merged-provider-tables.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ CREATE TABLE integration_access_tokens(
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
wsxiaoys marked this conversation as resolved.
Show resolved Hide resolved
kind TEXT NOT NULL,
display_name TEXT NOT NULL,
access_token TEXT,
access_token TEXT NOT NULL,
error TEXT,
created_at TIMESTAMP NOT NULL DEFAULT (DATETIME('now')),
updated_at TIMESTAMP NOT NULL DEFAULT (DATETIME('now'))
updated_at TIMESTAMP NOT NULL DEFAULT (DATETIME('now')),
synced_at TIMESTAMP NOT NULL DEFAULT (DATETIME('now'))
);

CREATE TABLE provided_repositories(
Expand All @@ -20,3 +21,9 @@ CREATE TABLE provided_repositories(
FOREIGN KEY (integration_access_token_id) REFERENCES integration_access_tokens(id) ON DELETE CASCADE,
CONSTRAINT idx_unique_provider_id_vendor_id UNIQUE (integration_access_token_id, vendor_id)
);

INSERT INTO integration_access_tokens(kind, display_name, access_token)
SELECT 'github', display_name, access_token FROM github_repository_provider WHERE access_token IS NOT NULL;

INSERT INTO integration_access_tokens(kind, display_name, access_token)
SELECT 'gitlab', display_name, access_token FROM gitlab_repository_provider WHERE access_token IS NOT NULL;
Binary file modified ee/tabby-db/schema.sqlite
Binary file not shown.
4 changes: 2 additions & 2 deletions ee/tabby-db/schema/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ CREATE TABLE integration_access_tokens(
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
kind TEXT NOT NULL,
display_name TEXT NOT NULL,
access_token TEXT,
access_token TEXT NOT NULL,
error TEXT,
created_at TIMESTAMP NOT NULL DEFAULT(DATETIME('now')),
updated_at TIMESTAMP NOT NULL DEFAULT(DATETIME('now'))
synced_at TIMESTAMP NOT NULL DEFAULT(DATETIME('now'))
);
CREATE TABLE provided_repositories(
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-db/schema/schema.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 26 additions & 17 deletions ee/tabby-db/src/integration_access_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
pub kind: String,
pub error: Option<String>,
pub display_name: String,
pub access_token: Option<String>,
pub access_token: String,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub synced_at: DateTimeUtc,
}

impl DbConn {
pub async fn create_integration_access_token(
&self,
kind: &str,
name: &str,
access_token: &str,
kind: String,
name: String,
access_token: String,

Check warning on line 24 in ee/tabby-db/src/integration_access_tokens.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/integration_access_tokens.rs#L22-L24

Added lines #L22 - L24 were not covered by tests
) -> Result<i64> {
let res = query!(
"INSERT INTO integration_access_tokens(kind, display_name, access_token) VALUES (?, ?, ?);",
Expand All @@ -42,8 +43,9 @@
error,
display_name,
access_token,
created_at AS "created_at: DateTimeUtc",
updated_at AS "updated_at: DateTimeUtc"
updated_at,
created_at,
synced_at
FROM integration_access_tokens WHERE id = ?;"#,
id
)
Expand All @@ -52,10 +54,14 @@
Ok(provider)
}

pub async fn delete_integration_access_token(&self, id: i64) -> Result<()> {
let res = query!("DELETE FROM integration_access_tokens WHERE id = ?;", id)
.execute(&self.pool)
.await?;
pub async fn delete_integration_access_token(&self, id: i64, kind: &str) -> Result<()> {
let res = query!(
"DELETE FROM integration_access_tokens WHERE id = ? AND kind = ?;",
id,
kind
)
.execute(&self.pool)
.await?;

Check warning on line 64 in ee/tabby-db/src/integration_access_tokens.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/integration_access_tokens.rs#L57-L64

Added lines #L57 - L64 were not covered by tests
if res.rows_affected() != 1 {
return Err(anyhow!("No integration access token to delete"));
}
Expand All @@ -65,19 +71,21 @@
pub async fn update_integration_access_token(
&self,
id: i64,
kind: &str,

Check warning on line 74 in ee/tabby-db/src/integration_access_tokens.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/integration_access_tokens.rs#L74

Added line #L74 was not covered by tests
display_name: String,
access_token: Option<String>,
) -> Result<()> {
let access_token = match access_token {
Some(access_token) => Some(access_token),
Some(access_token) => access_token,

Check warning on line 79 in ee/tabby-db/src/integration_access_tokens.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/integration_access_tokens.rs#L79

Added line #L79 was not covered by tests
None => self.get_integration_access_token(id).await?.access_token,
};

let res = query!(
"UPDATE integration_access_tokens SET display_name = ?, access_token=? WHERE id = ?;",
"UPDATE integration_access_tokens SET display_name = ?, access_token = ?, updated_at = DATETIME('now') WHERE id = ? AND kind = ?;",

Check warning on line 84 in ee/tabby-db/src/integration_access_tokens.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/integration_access_tokens.rs#L84

Added line #L84 was not covered by tests
display_name,
access_token,
id
id,
kind

Check warning on line 88 in ee/tabby-db/src/integration_access_tokens.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/integration_access_tokens.rs#L87-L88

Added lines #L87 - L88 were not covered by tests
)
.execute(&self.pool)
.await?;
Expand All @@ -97,7 +105,7 @@
error: Option<String>,
) -> Result<()> {
query!(
"UPDATE integration_access_tokens SET updated_at = DATETIME('now'), error = ? WHERE id = ?",
"UPDATE integration_access_tokens SET synced_at = DATETIME('now'), error = ? WHERE id = ?",

Check warning on line 108 in ee/tabby-db/src/integration_access_tokens.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/integration_access_tokens.rs#L108

Added line #L108 was not covered by tests
error,
id
)
Expand Down Expand Up @@ -126,7 +134,7 @@
});
conditions.extend(id_condition);

let kind_condition = kind.map(|kind| format!("kind = {kind}"));
let kind_condition = kind.map(|kind| format!("kind = '{kind}'"));
conditions.extend(kind_condition);

let condition = (!conditions.is_empty()).then(|| conditions.join(" AND "));
Expand All @@ -140,8 +148,9 @@
"error",
"display_name",
"access_token",
"created_at" as "created_at: DateTimeUtc",
"updated_at" as "updated_at: DateTimeUtc"
"created_at",
"updated_at",
"synced_at"
],
limit,
skip_id,
Expand Down
2 changes: 2 additions & 0 deletions ee/tabby-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ use chrono::{DateTime, Duration, NaiveDateTime, Utc};
pub use email_setting::EmailSettingDAO;
pub use github_repository_provider::{GithubProvidedRepositoryDAO, GithubRepositoryProviderDAO};
pub use gitlab_repository_provider::{GitlabProvidedRepositoryDAO, GitlabRepositoryProviderDAO};
pub use integration_access_tokens::IntegrationAccessTokenDAO;
pub use invitations::InvitationDAO;
pub use job_runs::JobRunDAO;
pub use oauth_credential::OAuthCredentialDAO;
pub use provided_repositories::ProvidedRepositoryDAO;
pub use repositories::RepositoryDAO;
pub use server_setting::ServerSettingDAO;
use sqlx::{
Expand Down
31 changes: 23 additions & 8 deletions ee/tabby-db/src/provided_repositories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

pub async fn list_provided_repositories(
&self,
provider_ids: Vec<i64>,
integration_ids: Vec<i64>,

Check warning on line 64 in ee/tabby-db/src/provided_repositories.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/provided_repositories.rs#L64

Added line #L64 was not covered by tests
kind: Option<String>,
active: Option<bool>,
limit: Option<usize>,
Expand All @@ -70,35 +70,37 @@
) -> Result<Vec<ProvidedRepositoryDAO>> {
let mut conditions = vec![];

let provider_ids = provider_ids
let integration_ids = integration_ids

Check warning on line 73 in ee/tabby-db/src/provided_repositories.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/provided_repositories.rs#L73

Added line #L73 was not covered by tests
.into_iter()
.map(|id| id.to_string())
.collect::<Vec<_>>()
.join(", ");
if !provider_ids.is_empty() {
conditions.push(format!("access_token_provider_id IN ({provider_ids})"));
if !integration_ids.is_empty() {
conditions.push(format!(
"integration_access_token_id IN ({integration_ids})"
));

Check warning on line 81 in ee/tabby-db/src/provided_repositories.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/provided_repositories.rs#L78-L81

Added lines #L78 - L81 were not covered by tests
}

let active_filter = active.map(|active| format!("active = {active}"));
conditions.extend(active_filter);

let kind_filter = kind.map(|kind| format!("kind = {kind}"));
let kind_filter = kind.map(|kind| format!("kind = '{kind}'"));

Check warning on line 87 in ee/tabby-db/src/provided_repositories.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-db/src/provided_repositories.rs#L87

Added line #L87 was not covered by tests
conditions.extend(kind_filter);

let condition = (!conditions.is_empty()).then(|| conditions.join(" AND "));

let repos = query_paged_as!(
ProvidedRepositoryDAO,
"provided_repositories",
"provided_repositories JOIN integration_access_tokens ON integration_access_token_id = integration_access_tokens.id",
[
"id",
"vendor_id",
"name",
"git_url",
"active",
"integration_access_token_id",
"created_at" as "created_at: DateTimeUtc",
"updated_at" as "updated_at: DateTimeUtc"
"created_at",
"updated_at"
],
limit,
skip_id,
Expand Down Expand Up @@ -128,3 +130,16 @@
Ok(())
}
}

#[cfg(test)]
mod tests {
use crate::DbConn;

#[tokio::test]
async fn test_list_provided_repositories() {
let db = DbConn::new_in_memory().await.unwrap();
db.list_github_provided_repositories(vec![], None, None, None, false)
.await
.unwrap();
}
}
17 changes: 0 additions & 17 deletions ee/tabby-schema/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ enum RepositoryProviderStatus {
FAILED
}

enum WorkerKind {
COMPLETION
CHAT
}

input CreateRepositoryProviderInput {
displayName: String!
accessToken: String!
Expand Down Expand Up @@ -370,7 +365,6 @@ type PageInfo {
}

type Query {
workers: [Worker!]!
registrationToken: String!
me: User!
users(after: String, before: String, first: Int, last: Int): UserConnection!
Expand Down Expand Up @@ -482,14 +476,3 @@ type UserEventEdge {
node: UserEvent!
cursor: String!
}

type Worker {
kind: WorkerKind!
name: String!
addr: String!
device: String!
arch: String!
cpuInfo: String!
cpuCount: Int!
cudaDevices: [String!]!
}