30 lines
1.0 KiB
Rust
30 lines
1.0 KiB
Rust
use crate::error::AppError;
|
|
use crate::models::prs::PrStatus;
|
|
use crate::service::PrService;
|
|
use crate::session::Session;
|
|
|
|
impl PrService {
|
|
pub async fn pr_status(
|
|
&self,
|
|
ctx: &Session,
|
|
wk_name: &str,
|
|
repo_name: &str,
|
|
number: i64,
|
|
) -> Result<PrStatus, AppError> {
|
|
let user_uid = ctx.user().ok_or(AppError::Unauthorized)?;
|
|
let pr = self.resolve_pr(wk_name, repo_name, number).await?;
|
|
self.ensure_pr_readable(user_uid, &pr).await?;
|
|
sqlx::query_as::<_, PrStatus>(
|
|
"SELECT pull_request_id, head_commit_sha, checks_state, mergeable_state, conflicts, \
|
|
approvals_count, requested_reviews_count, changed_files_count, additions_count, \
|
|
deletions_count, updated_at \
|
|
FROM pr_status WHERE pull_request_id = $1",
|
|
)
|
|
.bind(pr.id)
|
|
.fetch_optional(self.ctx.db.reader())
|
|
.await
|
|
.map_err(AppError::Database)?
|
|
.ok_or(AppError::NotFound("PR status not found".into()))
|
|
}
|
|
}
|