Skip to content

Commit

Permalink
List all issues and commit to index
Browse files Browse the repository at this point in the history
  • Loading branch information
boxbeam committed Jun 10, 2024
1 parent 7ba144c commit f433d95
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 39 deletions.
26 changes: 24 additions & 2 deletions crates/tabby-scheduler/src/doc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,35 @@ pub struct DocIndexer {
indexer: Indexer<SourceDocument>,
}

pub struct IssueDocument {
pub id: String,
pub link: String,
pub title: String,
pub body: String,
}

impl From<IssueDocument> for SourceDocument {
fn from(value: IssueDocument) -> Self {
Self {
id: value.id,
link: value.link,
title: value.title,
body: value.body,
}
}

Check warning on line 110 in crates/tabby-scheduler/src/doc/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-scheduler/src/doc/mod.rs#L103-L110

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

impl DocIndexer {
pub fn new(embedding: Arc<dyn Embedding>) -> Self {
let indexer = create_web_index(embedding);
Self { indexer }
}

Check warning on line 117 in crates/tabby-scheduler/src/doc/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-scheduler/src/doc/mod.rs#L114-L117

Added lines #L114 - L117 were not covered by tests

pub async fn index_document(&self, document: SourceDocument) {
self.indexer.add(document).await;
pub async fn index_issue(&self, document: IssueDocument) {
self.indexer.add(document.into()).await;
}

Check warning on line 121 in crates/tabby-scheduler/src/doc/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-scheduler/src/doc/mod.rs#L119-L121

Added lines #L119 - L121 were not covered by tests

pub fn commit(self) {
self.indexer.commit();
}

Check warning on line 125 in crates/tabby-scheduler/src/doc/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-scheduler/src/doc/mod.rs#L123-L125

Added lines #L123 - L125 were not covered by tests
}
4 changes: 3 additions & 1 deletion crates/tabby-scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use async_stream::stream;
pub use code::CodeIndexer;
use crawl::crawl_pipeline;
use doc::create_web_index;
pub use doc::{DocIndexer, SourceDocument};
pub use doc::{DocIndexer, IssueDocument};
use futures::StreamExt;
pub use indexer::{IndexAttributeBuilder, Indexer};

Expand All @@ -19,6 +19,8 @@ use std::{env, sync::Arc};
use tokio_cron_scheduler::{Job, JobScheduler};
use tracing::{debug, info, warn};

use crate::doc::SourceDocument;

pub async fn scheduler(now: bool, config: &tabby_common::config::Config) {
if now {
scheduler_pipeline(config).await;
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/service/background_job/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub async fn start(
warn!("Sync integration job failed: {:?}", err);
}

if let Err(err) = IndexIssuesJob::cron(now, sender.clone(), integration_service.clone()).await {
if let Err(err) = IndexIssuesJob::cron(now, sender.clone(), third_party_repository_service.clone()).await {
warn!("Index issues job failed: {err:?}");
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ impl SyncIntegrationJob {

#[derive(Serialize, Deserialize, Clone)]

Check warning on line 64 in ee/tabby-webserver/src/service/background_job/third_party_integration.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/third_party_integration.rs#L64

Added line #L64 was not covered by tests
pub struct IndexIssuesJob {
integration_id: ID,
repository_id: ID,
}

impl Job for IndexIssuesJob {
const NAME: &'static str = "index_issues";
}

impl IndexIssuesJob {
pub fn new(integration_id: ID) -> Self {
Self { integration_id }
pub fn new(repository_id: ID) -> Self {
Self { repository_id }
}

Check warning on line 76 in ee/tabby-webserver/src/service/background_job/third_party_integration.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/third_party_integration.rs#L74-L76

Added lines #L74 - L76 were not covered by tests

pub async fn run(
Expand All @@ -81,50 +81,42 @@ impl IndexIssuesJob {
repository_service: Arc<dyn ThirdPartyRepositoryService>,
integration_service: Arc<dyn IntegrationService>,
) -> tabby_schema::Result<()> {
let repository = repository_service
.get_provided_repository(self.repository_id)
.await?;
let integration = integration_service
.get_integration(self.integration_id)
.get_integration(repository.integration_id.clone())
.await?;

Check warning on line 89 in ee/tabby-webserver/src/service/background_job/third_party_integration.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/third_party_integration.rs#L78-L89

Added lines #L78 - L89 were not covered by tests

for repository in repository_service
.list_repositories_with_filter(
Some(vec![integration.id.clone()]),
None,
Some(true),
None,
None,
None,
None,
)
.await?
{
match &integration.kind {
IntegrationKind::Github | IntegrationKind::GithubSelfHosted => {
index_github_issues(
embedding.clone(),
integration.api_base(),
&repository.display_name,
&integration.access_token,
)
.await?;
}
IntegrationKind::Gitlab | IntegrationKind::GitlabSelfHosted => {}
debug!("Indexing issues for repository {}", repository.display_name);

Check warning on line 91 in ee/tabby-webserver/src/service/background_job/third_party_integration.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/third_party_integration.rs#L91

Added line #L91 was not covered by tests

match &integration.kind {

Check warning on line 93 in ee/tabby-webserver/src/service/background_job/third_party_integration.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/third_party_integration.rs#L93

Added line #L93 was not covered by tests
IntegrationKind::Github | IntegrationKind::GithubSelfHosted => {
index_github_issues(
embedding.clone(),
integration.api_base(),
&repository.display_name,
&integration.access_token,
)
.await?;

Check warning on line 101 in ee/tabby-webserver/src/service/background_job/third_party_integration.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/third_party_integration.rs#L95-L101

Added lines #L95 - L101 were not covered by tests
}
IntegrationKind::Gitlab | IntegrationKind::GitlabSelfHosted => {}

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

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/third_party_integration.rs#L103

Added line #L103 was not covered by tests
}
Ok(())
}

Check warning on line 106 in ee/tabby-webserver/src/service/background_job/third_party_integration.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/third_party_integration.rs#L105-L106

Added lines #L105 - L106 were not covered by tests

pub async fn cron(
_now: DateTime<Utc>,
sender: tokio::sync::mpsc::UnboundedSender<BackgroundJobEvent>,
integration_service: Arc<dyn IntegrationService>,
repository_service: Arc<dyn ThirdPartyRepositoryService>,
) -> tabby_schema::Result<()> {
for integration in integration_service
.list_integrations(None, None, None, None, None, None)
for repository in repository_service
.list_repositories_with_filter(None, None, Some(true), None, None, None, None)
.await?

Check warning on line 115 in ee/tabby-webserver/src/service/background_job/third_party_integration.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/third_party_integration.rs#L108-L115

Added lines #L108 - L115 were not covered by tests
{
sender
.send(BackgroundJobEvent::IndexIssues(integration.id))
.map_err(|_| anyhow!("Failed to enqueue issue index job"))?;
.send(BackgroundJobEvent::IndexIssues(repository.id))
.map_err(|_| anyhow!("Failed to enqueue scheduler job"))?;

Check warning on line 119 in ee/tabby-webserver/src/service/background_job/third_party_integration.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/third_party_integration.rs#L117-L119

Added lines #L117 - L119 were not covered by tests
}
Ok(())
}

Check warning on line 122 in ee/tabby-webserver/src/service/background_job/third_party_integration.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/third_party_integration.rs#L121-L122

Added lines #L121 - L122 were not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use anyhow::{anyhow, Result};
use octocrab::{models::issues::Issue, Octocrab};
use tabby_inference::Embedding;
use tabby_scheduler::{DocIndexer, SourceDocument};
use tabby_scheduler::{DocIndexer, IssueDocument};

async fn fetch_github_issues(
api_base: &str,
Expand All @@ -26,6 +26,7 @@ async fn fetch_github_issues(
let response = octocrab
.issues(owner, repo)
.list()
.state(octocrab::params::State::All)
.page(page)
.send()
.await?;

Check warning on line 32 in ee/tabby-webserver/src/service/background_job/third_party_integration/issues.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/third_party_integration/issues.rs#L26-L32

Added lines #L26 - L32 were not covered by tests
Expand All @@ -51,13 +52,15 @@ pub async fn index_github_issues(
let index = DocIndexer::new(embedding);

Check warning on line 52 in ee/tabby-webserver/src/service/background_job/third_party_integration/issues.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/third_party_integration/issues.rs#L46-L52

Added lines #L46 - L52 were not covered by tests

for issue in fetch_github_issues(api_base, full_name, access_token).await? {
let document = SourceDocument {
let document = IssueDocument {
id: format!("{full_name}/issues/{}", issue.id),
title: issue.title,
link: issue.url.to_string(),
body: issue.body.unwrap_or_default(),
};
index.index_document(document).await;
index.index_issue(document).await;

Check warning on line 61 in ee/tabby-webserver/src/service/background_job/third_party_integration/issues.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/third_party_integration/issues.rs#L54-L61

Added lines #L54 - L61 were not covered by tests
}

index.commit();
Ok(())
}

Check warning on line 66 in ee/tabby-webserver/src/service/background_job/third_party_integration/issues.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/service/background_job/third_party_integration/issues.rs#L64-L66

Added lines #L64 - L66 were not covered by tests
4 changes: 4 additions & 0 deletions ee/tabby-webserver/src/service/repository/third_party.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ impl ThirdPartyRepositoryService for ThirdPartyRepositoryServiceImpl {
.send(BackgroundJobEvent::Scheduler(RepositoryConfig::new(
git_url,
)));

let _ = self
.background_job
.send(BackgroundJobEvent::IndexIssues(repo.id));
}

Ok(())
Expand Down

0 comments on commit f433d95

Please sign in to comment.