Skip to content

Commit

Permalink
feat: add sanitize_context method
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinkys committed Nov 5, 2024
1 parent 545ce0f commit fac049d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,26 @@ pub struct ApprovalRequest {
pub context: String,
}

impl ApprovalRequest {
pub fn sanitize_context(context: impl Into<String>) -> String {
let context: String = context.into();
if context.is_empty() {
return context;
}

let context = context.trim();
let lines: Vec<&str> = context.lines().map(str::trim).collect();
lines.join("\n")
}
}

impl From<protos::GetApprovalRequest> for ApprovalRequest {
fn from(value: protos::GetApprovalRequest) -> Self {
Self {
id: ApprovalID::new(),
name: value.name,
parameters: value.parameters,
context: value.context,
context: Self::sanitize_context(value.context),
}
}
}
Expand Down

0 comments on commit fac049d

Please sign in to comment.