Skip to content
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

Merged
merged 2 commits into from
Oct 3, 2024
Merged

Conversation

dfrankland
Copy link
Member

@dfrankland dfrankland commented Oct 1, 2024

depends on #109

Adds validation for git repo details we collect independently from other context we collect

@dfrankland dfrankland changed the title add bundle repo validator 4. add bundle repo validator Oct 1, 2024
Copy link

trunk-staging-io bot commented Oct 1, 2024

✅ 86 passed ⋅ (learn more)

settingsdocs ⋅ learn more about trunk.io


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;
Copy link
Member Author

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

Copy link
Member Author

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.

Copy link
Member Author

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

@dfrankland dfrankland marked this pull request as ready for review October 2, 2024 00:33
@dfrankland dfrankland requested review from riya-n and gnalh October 2, 2024 00:33
@dfrankland dfrankland force-pushed the dylan/split-api-test-utils-and-bundlrepo-from-cli branch from 7924e52 to c72e8f9 Compare October 2, 2024 16:21
@dfrankland dfrankland force-pushed the dylan/bundle-repo-validator branch from 93bc18f to ee13d21 Compare October 2, 2024 16:22
@dfrankland dfrankland force-pushed the dylan/split-api-test-utils-and-bundlrepo-from-cli branch from c72e8f9 to a1702f1 Compare October 2, 2024 16:51
@dfrankland dfrankland force-pushed the dylan/bundle-repo-validator branch from ee13d21 to 68e72f4 Compare October 2, 2024 16:52
Copy link
Contributor

@riya-n riya-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! lgtm

Base automatically changed from dylan/split-api-test-utils-and-bundlrepo-from-cli to main October 3, 2024 15:18
@dfrankland dfrankland force-pushed the dylan/bundle-repo-validator branch from 68e72f4 to 6e04e29 Compare October 3, 2024 15:19
@dfrankland dfrankland merged commit 5f06588 into main Oct 3, 2024
6 checks passed
@dfrankland dfrankland deleted the dylan/bundle-repo-validator branch October 3, 2024 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants