-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4. add bundle repo validator #110
Conversation
✅ 86 passed ⋅ (learn more) |
|
||
fn safe_truncate_string<'a, const MAX_LEN: usize, T: AsRef<str>>(value: &'a T) -> &'a str { | ||
safe_truncate_str::<MAX_LEN>(value.as_ref()) | ||
} | ||
|
||
fn safe_truncate_str<'a, const MAX_LEN: usize>(value: &'a str) -> &'a str { | ||
&value.trim()[..value.floor_char_boundary(MAX_LEN)] | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
enum FieldLen { | ||
TooShort(String), | ||
TooLong(String), | ||
Valid, | ||
} | ||
|
||
fn validate_field_len<const MAX_LEN: usize, T: AsRef<str>>(field: T) -> FieldLen { | ||
let trimmed_field = field.as_ref().trim(); | ||
let trimmed_field_len = trimmed_field.len(); | ||
|
||
if trimmed_field_len == 0 { | ||
FieldLen::TooShort(String::from(trimmed_field)) | ||
} else if (1..=MAX_LEN).contains(&trimmed_field_len) { | ||
FieldLen::Valid | ||
} else { | ||
FieldLen::TooLong(String::from(safe_truncate_string::<MAX_LEN, _>( | ||
&trimmed_field, | ||
))) | ||
} | ||
} | ||
mod string_safety; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this to its own module for better organization
context/src/repo/validator.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we don't validate this data we collect independently from other pieces of context like env. This helps to check independently whether we have this information before we mash everything together.
context/src/string_safety.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved from lib.rs
for organization
7924e52
to
c72e8f9
Compare
93bc18f
to
ee13d21
Compare
c72e8f9
to
a1702f1
Compare
ee13d21
to
68e72f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! lgtm
68e72f4
to
6e04e29
Compare
depends on #109
Adds validation for git repo details we collect independently from other context we collect