Add default authorization header for gitea api (remove query string)

Add review cost
This commit is contained in:
2026-06-05 18:39:38 +00:00
parent cd5c5b9478
commit 01e13f0081
4 changed files with 53 additions and 38 deletions
+24 -22
View File
@@ -9,17 +9,18 @@ use crate::{
};
#[derive(Deserialize, Debug)]
struct ReviewResult {
reviews: Vec<ReviewItem>,
comment: String,
pub struct ReviewResult {
pub reviews: Vec<ReviewItem>,
pub comment: String,
pub cost: Option<f64>,
}
#[derive(Deserialize, Debug)]
struct ReviewItem {
filename: String,
line: Option<u64>,
code: String,
message: String,
pub struct ReviewItem {
pub filename: String,
pub line: Option<u64>,
pub code: String,
pub message: String,
}
/// Map a filename to a markdown language identifier for syntax highlighting.
@@ -69,7 +70,7 @@ pub struct Bot {
impl Bot {
pub fn new(config: EnvConfig) -> anyhow::Result<Self> {
Ok(Self {
gitea_api: GiteaAPI::new(&config.gitea_url, &config.gitea_token, config.gitea_timeout),
gitea_api: GiteaAPI::new(&config.gitea_url, &config.gitea_token, config.gitea_timeout)?,
open_router_client: OpenRouterClient::new(
&config.open_router_api_key,
&config.open_router_model,
@@ -112,7 +113,7 @@ impl Bot {
)
.await?;
let bot_result: Result<String, anyhow::Error> = async {
let bot_result: Result<ReviewResult, anyhow::Error> = async {
let git_diff = self
.download_git_diff(&review_payload.pull_request.diff_url)
.await?;
@@ -122,7 +123,12 @@ impl Bot {
.replace("{comment}", &review_payload.comment.body)
.replace("{diff}", &git_diff);
self.open_router_client.chat(&bot_request).await
let chat_result = self.open_router_client.chat(&bot_request).await?;
let mut review_result = serde_json::from_str::<ReviewResult>(&chat_result.message)?;
review_result.cost = chat_result.cost;
Ok(review_result)
}
.await;
@@ -142,17 +148,7 @@ impl Bot {
Ok(())
}
fn review_result_to_markdown(&self, result: &str) -> String {
let review_result: ReviewResult = match serde_json::from_str(result) {
Ok(review_result) => review_result,
Err(_) => {
return format!(
"Failed to parse review result. Raw output:\n\n```json\n{}\n```",
result
);
}
};
fn review_result_to_markdown(&self, review_result: &ReviewResult) -> String {
if review_result.reviews.is_empty() {
return String::from("No issues found. ✅");
}
@@ -181,6 +177,12 @@ impl Bot {
md.push('\n');
}
if let Some(cost) = review_result.cost {
md.push_str("\n---\n\n");
md.push_str(&format!("### Cost: ${}", cost));
md.push('\n');
}
md
}