use crate::error::AppError; use crate::models::prs::PrCommit; use crate::service::PrService; use crate::session::Session; use super::util::clamp_limit_offset; impl PrService { pub async fn pr_commits( &self, ctx: &Session, wk_name: &str, repo_name: &str, number: i64, limit: i64, offset: i64, ) -> Result, 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?; let (limit, offset) = clamp_limit_offset(limit, offset); sqlx::query_as::<_, PrCommit>( "SELECT id, pull_request_id, repo_id, commit_sha, position, authored_at, committed_at, created_at \ FROM pr_commit WHERE pull_request_id = $1 ORDER BY position ASC LIMIT $2 OFFSET $3", ) .bind(pr.id).bind(limit).bind(offset) .fetch_all(self.ctx.db.reader()).await.map_err(AppError::Database) } }