-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
20 changes: 20 additions & 0 deletions
20
ee/tabby-webserver/src/schema/github_repository_provider.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use juniper::{GraphQLObject, ID}; | ||
|
||
#[derive(GraphQLObject)] | ||
pub struct GithubRepositoryProvider { | ||
pub display_name: String, | ||
pub application_id: String, | ||
} | ||
|
||
#[async_trait] | ||
pub trait GithubRepositoryProviderService: Send + Sync { | ||
async fn get_github_repository_provider(&self, id: ID) -> Result<GithubRepositoryProvider>; | ||
async fn read_github_repository_provider_secret(&self, id: ID) -> Result<String>; | ||
async fn set_github_repository_provider_token( | ||
&self, | ||
id: ID, | ||
access_token: String, | ||
) -> Result<()>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
ee/tabby-webserver/src/service/github_repository_provider.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use juniper::ID; | ||
use tabby_db::DbConn; | ||
|
||
use crate::schema::github_repository_provider::{ | ||
GithubRepositoryProvider, GithubRepositoryProviderService, | ||
}; | ||
|
||
use super::AsRowid; | ||
|
||
struct GithubRepositoryProviderServiceImpl { | ||
db: DbConn, | ||
} | ||
|
||
pub fn new_github_repository_provider_service(db: DbConn) -> impl GithubRepositoryProviderService { | ||
GithubRepositoryProviderServiceImpl { db } | ||
} | ||
|
||
#[async_trait] | ||
impl GithubRepositoryProviderService for GithubRepositoryProviderServiceImpl { | ||
async fn get_github_repository_provider(&self, id: ID) -> Result<GithubRepositoryProvider> { | ||
let provider = self.db.get_github_provider(id.as_rowid()? as i64).await?; | ||
Ok(GithubRepositoryProvider { | ||
display_name: provider.display_name, | ||
application_id: provider.application_id, | ||
}) | ||
} | ||
|
||
async fn read_github_repository_provider_secret(&self, id: ID) -> Result<String> { | ||
let provider = self.db.get_github_provider(id.as_rowid()? as i64).await?; | ||
Ok(provider.secret) | ||
} | ||
|
||
async fn set_github_repository_provider_token( | ||
&self, | ||
id: ID, | ||
access_token: String, | ||
) -> Result<()> { | ||
self.db | ||
.update_github_provider_token(id.as_rowid()? as i64, access_token) | ||
.await?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters