Extract review logic into bot_actions module
Move `exec_review`, `download_git_diff`, and review formatting to a new `bot_actions::review` module. Update the review flow to post inline review comments via the Gitea API and simplify the comment markdown to a summary. Add diff formatting that preprocesses added lines with line numbers for the LLM prompt.
This commit is contained in:
+50
-1
@@ -3,7 +3,10 @@ use std::time::Duration;
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::errors::AppError;
|
||||
use crate::{
|
||||
bot::{ReviewItem, ReviewResult},
|
||||
errors::AppError,
|
||||
};
|
||||
|
||||
pub struct GiteaAPI {
|
||||
base_url: String,
|
||||
@@ -80,6 +83,52 @@ impl GiteaAPI {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn post_pull_request_review(
|
||||
&self,
|
||||
review_result: &ReviewResult,
|
||||
full_name: &str,
|
||||
index: u64,
|
||||
) -> anyhow::Result<()> {
|
||||
let url = format!(
|
||||
"{}/api/v1/repos/{}/pulls/{}/reviews",
|
||||
self.base_url, full_name, index
|
||||
);
|
||||
|
||||
let comments = &&review_result
|
||||
.reviews
|
||||
.iter()
|
||||
.filter(|r| r.line.is_some())
|
||||
.map(|r| {
|
||||
let path = r.filename.clone();
|
||||
let line = r.line.unwrap_or(0);
|
||||
let body = r.message.clone();
|
||||
|
||||
json!({
|
||||
"path": path,
|
||||
"new_position": line,
|
||||
"body": body
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let res = self
|
||||
.client
|
||||
.post(url)
|
||||
.json(&json!({
|
||||
"event": "COMMENT",
|
||||
"body": review_result.comment,
|
||||
"comments": comments
|
||||
}))
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
if !res.status().is_success() {
|
||||
return Err(anyhow::anyhow!("Failed to post review: {}", res.status()));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
Reference in New Issue
Block a user