refactor(models): replace hardcoded strings with typed enums
- Add ReviewState enum (pending, approved, changes_requested, etc.) - Add DEFAULT_REVISION constant for git HEAD references - service/pr/reviews.rs: use ReviewState for review creation and submission state validation - service/pr/core.rs: use MergeStrategyKind for merge strategy selection - service/im/stages.rs: use StagePrivacyLevel for stage creation - service/im/invitations.rs: use Role enum for invitation role defaults
This commit is contained in:
+21
-24
@@ -2,14 +2,14 @@ use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::error::AppError;
|
||||
use crate::models::common::{Role, State};
|
||||
use crate::models::common::{MergeStrategyKind, Role, State};
|
||||
use crate::models::prs::PullRequest;
|
||||
use crate::models::repos::Repo;
|
||||
use crate::models::workspaces::Workspace;
|
||||
use crate::service::PrService;
|
||||
use crate::session::Session;
|
||||
|
||||
use super::util::{clamp_limit_offset, ensure_affected, merge_optional_text};
|
||||
use super::util::{clamp_limit_offset, ensure_affected, merge_optional_text, set_local_user_id};
|
||||
|
||||
#[derive(Deserialize, Serialize, Clone, Debug, utoipa::ToSchema)]
|
||||
pub struct CreatePrParams {
|
||||
@@ -175,8 +175,7 @@ impl PrService {
|
||||
.begin()
|
||||
.await
|
||||
.map_err(|_| AppError::TxnError)?;
|
||||
sqlx::query("SET LOCAL app.current_user_id = $1")
|
||||
.bind(user_uid)
|
||||
sqlx::query(set_local_user_id(user_uid))
|
||||
.execute(&mut *txn)
|
||||
.await
|
||||
.map_err(AppError::Database)?;
|
||||
@@ -280,8 +279,7 @@ impl PrService {
|
||||
.begin()
|
||||
.await
|
||||
.map_err(|_| AppError::TxnError)?;
|
||||
sqlx::query("SET LOCAL app.current_user_id = $1")
|
||||
.bind(user_uid)
|
||||
sqlx::query(set_local_user_id(user_uid))
|
||||
.execute(&mut *txn)
|
||||
.await
|
||||
.map_err(AppError::Database)?;
|
||||
@@ -326,8 +324,7 @@ impl PrService {
|
||||
.begin()
|
||||
.await
|
||||
.map_err(|_| AppError::TxnError)?;
|
||||
sqlx::query("SET LOCAL app.current_user_id = $1")
|
||||
.bind(user_uid)
|
||||
sqlx::query(set_local_user_id(user_uid))
|
||||
.execute(&mut *txn)
|
||||
.await
|
||||
.map_err(AppError::Database)?;
|
||||
@@ -378,8 +375,7 @@ impl PrService {
|
||||
.begin()
|
||||
.await
|
||||
.map_err(|_| AppError::TxnError)?;
|
||||
sqlx::query("SET LOCAL app.current_user_id = $1")
|
||||
.bind(user_uid)
|
||||
sqlx::query(set_local_user_id(user_uid))
|
||||
.execute(&mut *txn)
|
||||
.await
|
||||
.map_err(AppError::Database)?;
|
||||
@@ -421,8 +417,7 @@ impl PrService {
|
||||
.begin()
|
||||
.await
|
||||
.map_err(|_| AppError::TxnError)?;
|
||||
sqlx::query("SET LOCAL app.current_user_id = $1")
|
||||
.bind(user_uid)
|
||||
sqlx::query(set_local_user_id(user_uid))
|
||||
.execute(&mut *txn)
|
||||
.await
|
||||
.map_err(AppError::Database)?;
|
||||
@@ -464,8 +459,7 @@ impl PrService {
|
||||
.begin()
|
||||
.await
|
||||
.map_err(|_| AppError::TxnError)?;
|
||||
sqlx::query("SET LOCAL app.current_user_id = $1")
|
||||
.bind(user_uid)
|
||||
sqlx::query(set_local_user_id(user_uid))
|
||||
.execute(&mut *txn)
|
||||
.await
|
||||
.map_err(AppError::Database)?;
|
||||
@@ -502,8 +496,7 @@ impl PrService {
|
||||
.begin()
|
||||
.await
|
||||
.map_err(|_| AppError::TxnError)?;
|
||||
sqlx::query("SET LOCAL app.current_user_id = $1")
|
||||
.bind(user_uid)
|
||||
sqlx::query(set_local_user_id(user_uid))
|
||||
.execute(&mut *txn)
|
||||
.await
|
||||
.map_err(AppError::Database)?;
|
||||
@@ -626,8 +619,7 @@ impl PrService {
|
||||
.begin()
|
||||
.await
|
||||
.map_err(|_| AppError::TxnError)?;
|
||||
sqlx::query("SET LOCAL app.current_user_id = $1")
|
||||
.bind(user_uid)
|
||||
sqlx::query(set_local_user_id(user_uid))
|
||||
.execute(&mut *txn)
|
||||
.await
|
||||
.map_err(AppError::Database)?;
|
||||
@@ -924,21 +916,26 @@ impl PrService {
|
||||
};
|
||||
|
||||
// Determine merge strategy
|
||||
let strategy = params.strategy.as_deref().unwrap_or("merge");
|
||||
let strategy = params
|
||||
.strategy
|
||||
.as_deref()
|
||||
.and_then(|s| s.parse::<MergeStrategyKind>().ok())
|
||||
.filter(|s| *s != MergeStrategyKind::Unknown)
|
||||
.unwrap_or(MergeStrategyKind::Merge);
|
||||
let merge_strategy = match strategy {
|
||||
"squash" => pb::merge_options::Strategy::MergeStrategyOrt as i32,
|
||||
"rebase" => pb::merge_options::Strategy::MergeStrategyRecursive as i32,
|
||||
MergeStrategyKind::Squash => pb::merge_options::Strategy::MergeStrategyOrt as i32,
|
||||
MergeStrategyKind::Rebase => pb::merge_options::Strategy::MergeStrategyRecursive as i32,
|
||||
_ => pb::merge_options::Strategy::MergeStrategyOrt as i32,
|
||||
};
|
||||
|
||||
let options = pb::MergeOptions {
|
||||
strategy: merge_strategy,
|
||||
fast_forward: if strategy == "rebase" {
|
||||
fast_forward: if strategy == MergeStrategyKind::Rebase {
|
||||
pb::merge_options::FastForwardMode::MergeFastForwardModeNoFf as i32
|
||||
} else {
|
||||
pb::merge_options::FastForwardMode::MergeFastForwardModeAllowed as i32
|
||||
},
|
||||
squash: strategy == "squash",
|
||||
squash: strategy == MergeStrategyKind::Squash,
|
||||
no_commit: false,
|
||||
allow_unrelated_histories: false,
|
||||
strategy_options: vec![],
|
||||
@@ -954,7 +951,7 @@ impl PrService {
|
||||
}),
|
||||
committer: None,
|
||||
message: params.squash_message.clone().unwrap_or_else(|| {
|
||||
if strategy == "squash" {
|
||||
if strategy == MergeStrategyKind::Squash {
|
||||
params
|
||||
.squash_title
|
||||
.clone()
|
||||
|
||||
Reference in New Issue
Block a user