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

update new indexer endpoint #30

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions api/src/infrastructure/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#[async_trait]
impl indexer::Service for http::Client {
async fn index_repo(&self, repo_id: GithubRepoId) -> Result<()> {
self.post::<serde_json::Value>(format!("repo/{repo_id}")).await?;
self.post::<serde_json::Value>(format!("repo/{repo_id}"), None).await?;

Check warning on line 11 in api/src/infrastructure/indexer.rs

View check run for this annotation

Codecov / codecov/patch

api/src/infrastructure/indexer.rs#L11

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

async fn index_user(&self, user_id: GithubUserId) -> Result<()> {
self.post::<serde_json::Value>(format!("user/{user_id}")).await?;
self.post::<serde_json::Value>(format!("user/{user_id}"), None).await?;

Check warning on line 16 in api/src/infrastructure/indexer.rs

View check run for this annotation

Codecov / codecov/patch

api/src/infrastructure/indexer.rs#L16

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

Expand All @@ -22,7 +22,7 @@
repo_id: GithubRepoId,
issue_number: GithubIssueNumber,
) -> Result<()> {
self.post::<serde_json::Value>(format!("repo/{repo_id}/issue/{issue_number}"))
self.post::<serde_json::Value>(format!("repo/{repo_id}/issue/{issue_number}"), None)

Check warning on line 25 in api/src/infrastructure/indexer.rs

View check run for this annotation

Codecov / codecov/patch

api/src/infrastructure/indexer.rs#L25

Added line #L25 was not covered by tests
.await?;
Ok(())
}
Expand All @@ -32,7 +32,7 @@
repo_id: GithubRepoId,
pr_number: GithubPullRequestNumber,
) -> Result<()> {
self.post::<serde_json::Value>(format!("repo/{repo_id}/pull_request/{pr_number}"))
self.post::<serde_json::Value>(format!("repo/{repo_id}/pull_request/{pr_number}"), None)

Check warning on line 35 in api/src/infrastructure/indexer.rs

View check run for this annotation

Codecov / codecov/patch

api/src/infrastructure/indexer.rs#L35

Added line #L35 was not covered by tests
.await?;
Ok(())
}
Expand All @@ -49,9 +49,10 @@
}

let response: Response = self
.post(format!(
"repo/{repo_owner}/{repo_name}/pull_request/{pr_number}"
))
.post(
format!("repo/{repo_owner}/{repo_name}/pull_request/{pr_number}"),
None,
)

Check warning on line 55 in api/src/infrastructure/indexer.rs

View check run for this annotation

Codecov / codecov/patch

api/src/infrastructure/indexer.rs#L52-L55

Added lines #L52 - L55 were not covered by tests
.await?;

Ok(response.id)
Expand Down
9 changes: 8 additions & 1 deletion api/src/infrastructure/new_indexer.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
use anyhow::Result;
use domain::*;
use infrastructure::http;
use serde_json::json;

use crate::domain::services::new_indexer;

#[async_trait]
impl new_indexer::Service for http::Client {
async fn index_repo(&self, repo_id: GithubRepoId) -> Result<()> {
self.put(format!("api/v1/indexes/repos/{repo_id}")).await?;
self.post(
"api/v1/events/on-repo-link-changed".to_string(),
Some(json!({
"linkedRepoIds": [repo_id]
})),
)
.await?;

Check warning on line 17 in api/src/infrastructure/new_indexer.rs

View check run for this annotation

Codecov / codecov/patch

api/src/infrastructure/new_indexer.rs#L11-L17

Added lines #L11 - L17 were not covered by tests
Ok(())
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"request": {
"urlPattern": "/new_indexer/api/v1/indexes/repos/[0-9]*",
"method": "PUT",
"urlPattern": "/new_indexer/api/v1/events/on-repo-link-changed",
"method": "POST",
"headers": {
"Authorization": {
"contains": "Bearer "
Expand Down
13 changes: 11 additions & 2 deletions common/infrastructure/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,17 @@
Ok(url)
}

pub async fn post<R: DeserializeOwned>(&self, path: String) -> Result<R> {
let response = self.client.post(self.url(path)?).send().await?.error_for_status()?;
pub async fn post<R: DeserializeOwned>(
&self,
path: String,
body: Option<serde_json::Value>,
) -> Result<R> {
let mut request = self.client.post(self.url(path)?);
if let Some(body) = body {
request = request.body(body.to_string());
}

Check warning on line 39 in common/infrastructure/src/http/mod.rs

View check run for this annotation

Codecov / codecov/patch

common/infrastructure/src/http/mod.rs#L31-L39

Added lines #L31 - L39 were not covered by tests

let response = request.send().await?.error_for_status()?;

Check warning on line 41 in common/infrastructure/src/http/mod.rs

View check run for this annotation

Codecov / codecov/patch

common/infrastructure/src/http/mod.rs#L41

Added line #L41 was not covered by tests
let json = response.json().await?;
Ok(json)
}
Expand Down
Loading