[-] Remove unnecessary multiple regex
This commit is contained in:
+15
-15
@@ -22,8 +22,8 @@ fn parses_value_tokens() {
|
||||
[[mirrors]]
|
||||
name = "personal"
|
||||
sync_visibility = "public"
|
||||
repo_whitelist = ["^important-", "-mirror$"]
|
||||
repo_blacklist = ["-archive$"]
|
||||
repo_whitelist = "^important-|-mirror$"
|
||||
repo_blacklist = "-archive$"
|
||||
create_missing = true
|
||||
visibility = "private"
|
||||
conflict_resolution = "auto_rebase_pull_request"
|
||||
@@ -51,11 +51,11 @@ fn parses_value_tokens() {
|
||||
assert_eq!(config.mirrors[0].sync_visibility, SyncVisibility::Public);
|
||||
assert_eq!(
|
||||
config.mirrors[0].repo_whitelist,
|
||||
vec!["^important-".to_string(), "-mirror$".to_string()]
|
||||
Some("^important-|-mirror$".to_string())
|
||||
);
|
||||
assert_eq!(
|
||||
config.mirrors[0].repo_blacklist,
|
||||
vec!["-archive$".to_string()]
|
||||
Some("-archive$".to_string())
|
||||
);
|
||||
let webhook = config.webhook.unwrap();
|
||||
assert!(webhook.install);
|
||||
@@ -105,8 +105,8 @@ fn validation_rejects_unknown_sites_and_single_endpoint_groups() {
|
||||
namespace: "alice".to_string(),
|
||||
}],
|
||||
sync_visibility: SyncVisibility::All,
|
||||
repo_whitelist: Vec::new(),
|
||||
repo_blacklist: Vec::new(),
|
||||
repo_whitelist: None,
|
||||
repo_blacklist: None,
|
||||
create_missing: true,
|
||||
visibility: Visibility::Private,
|
||||
conflict_resolution: ConflictResolutionStrategy::Fail,
|
||||
@@ -134,8 +134,8 @@ fn validation_rejects_unknown_sites_and_single_endpoint_groups() {
|
||||
},
|
||||
],
|
||||
sync_visibility: SyncVisibility::All,
|
||||
repo_whitelist: Vec::new(),
|
||||
repo_blacklist: Vec::new(),
|
||||
repo_whitelist: None,
|
||||
repo_blacklist: None,
|
||||
create_missing: true,
|
||||
visibility: Visibility::Private,
|
||||
conflict_resolution: ConflictResolutionStrategy::Fail,
|
||||
@@ -199,8 +199,8 @@ fn sync_visibility_matches_repo_privacy() {
|
||||
#[test]
|
||||
fn repo_name_filter_applies_whitelist_then_blacklist() {
|
||||
let mut mirror = mirror_config();
|
||||
mirror.repo_whitelist = vec!["^important-".to_string(), "-mirror$".to_string()];
|
||||
mirror.repo_blacklist = vec!["-archive$".to_string()];
|
||||
mirror.repo_whitelist = Some("^important-|-mirror$".to_string());
|
||||
mirror.repo_blacklist = Some("-archive$".to_string());
|
||||
let filter = mirror.repo_filter().unwrap();
|
||||
|
||||
assert!(filter.matches("important-api"));
|
||||
@@ -217,7 +217,7 @@ fn validation_rejects_invalid_repo_filter_regex() {
|
||||
mirrors: vec![mirror_config()],
|
||||
webhook: None,
|
||||
};
|
||||
config.mirrors[0].repo_whitelist = vec!["(".to_string()];
|
||||
config.mirrors[0].repo_whitelist = Some("(".to_string());
|
||||
|
||||
let err = validate_config(&config).unwrap_err().to_string();
|
||||
|
||||
@@ -238,8 +238,8 @@ fn validation_rejects_duplicate_mirror_endpoints() {
|
||||
name: "broken".to_string(),
|
||||
endpoints: vec![duplicate.clone(), duplicate],
|
||||
sync_visibility: SyncVisibility::All,
|
||||
repo_whitelist: Vec::new(),
|
||||
repo_blacklist: Vec::new(),
|
||||
repo_whitelist: None,
|
||||
repo_blacklist: None,
|
||||
create_missing: true,
|
||||
visibility: Visibility::Private,
|
||||
conflict_resolution: ConflictResolutionStrategy::Fail,
|
||||
@@ -284,8 +284,8 @@ fn mirror_config() -> MirrorConfig {
|
||||
},
|
||||
],
|
||||
sync_visibility: SyncVisibility::All,
|
||||
repo_whitelist: Vec::new(),
|
||||
repo_blacklist: Vec::new(),
|
||||
repo_whitelist: None,
|
||||
repo_blacklist: None,
|
||||
create_missing: true,
|
||||
visibility: Visibility::Private,
|
||||
conflict_resolution: ConflictResolutionStrategy::Fail,
|
||||
|
||||
+14
-14
@@ -211,8 +211,8 @@ fn wizard_starts_existing_config_at_sync_group_menu() {
|
||||
},
|
||||
],
|
||||
sync_visibility: SyncVisibility::All,
|
||||
repo_whitelist: Vec::new(),
|
||||
repo_blacklist: Vec::new(),
|
||||
repo_whitelist: None,
|
||||
repo_blacklist: None,
|
||||
create_missing: true,
|
||||
visibility: Visibility::Private,
|
||||
conflict_resolution: ConflictResolutionStrategy::Fail,
|
||||
@@ -240,8 +240,8 @@ fn wizard_can_ask_to_run_full_sync_after_config() {
|
||||
name: "sync-1".to_string(),
|
||||
endpoints: Vec::new(),
|
||||
sync_visibility: SyncVisibility::All,
|
||||
repo_whitelist: Vec::new(),
|
||||
repo_blacklist: Vec::new(),
|
||||
repo_whitelist: None,
|
||||
repo_blacklist: None,
|
||||
create_missing: true,
|
||||
visibility: Visibility::Private,
|
||||
conflict_resolution: ConflictResolutionStrategy::Fail,
|
||||
@@ -316,8 +316,8 @@ fn wizard_edits_existing_sync_group_from_menu() {
|
||||
},
|
||||
],
|
||||
sync_visibility: SyncVisibility::Private,
|
||||
repo_whitelist: vec!["^important-".to_string()],
|
||||
repo_blacklist: vec!["-archive$".to_string()],
|
||||
repo_whitelist: Some("^important-".to_string()),
|
||||
repo_blacklist: Some("-archive$".to_string()),
|
||||
create_missing: false,
|
||||
visibility: Visibility::Public,
|
||||
conflict_resolution: ConflictResolutionStrategy::Fail,
|
||||
@@ -357,8 +357,8 @@ fn wizard_edits_existing_sync_group_from_menu() {
|
||||
assert_eq!(mirror.endpoints[1].namespace, "bob");
|
||||
assert!(!mirror.create_missing);
|
||||
assert_eq!(mirror.sync_visibility, SyncVisibility::Public);
|
||||
assert_eq!(mirror.repo_whitelist, vec!["^public-".to_string()]);
|
||||
assert_eq!(mirror.repo_blacklist, vec!["-skip$".to_string()]);
|
||||
assert_eq!(mirror.repo_whitelist, Some("^public-".to_string()));
|
||||
assert_eq!(mirror.repo_blacklist, Some("-skip$".to_string()));
|
||||
assert_eq!(mirror.visibility, Visibility::Public);
|
||||
let output = String::from_utf8(output).unwrap();
|
||||
assert!(output.contains("Edit sync group"));
|
||||
@@ -403,8 +403,8 @@ fn wizard_prefills_existing_sync_group_when_editing() {
|
||||
},
|
||||
],
|
||||
sync_visibility: SyncVisibility::All,
|
||||
repo_whitelist: Vec::new(),
|
||||
repo_blacklist: Vec::new(),
|
||||
repo_whitelist: None,
|
||||
repo_blacklist: None,
|
||||
create_missing: true,
|
||||
visibility: Visibility::Private,
|
||||
conflict_resolution: ConflictResolutionStrategy::Fail,
|
||||
@@ -467,8 +467,8 @@ fn wizard_deletes_existing_sync_group_from_menu() {
|
||||
},
|
||||
],
|
||||
sync_visibility: SyncVisibility::All,
|
||||
repo_whitelist: Vec::new(),
|
||||
repo_blacklist: Vec::new(),
|
||||
repo_whitelist: None,
|
||||
repo_blacklist: None,
|
||||
create_missing: true,
|
||||
visibility: Visibility::Private,
|
||||
conflict_resolution: ConflictResolutionStrategy::Fail,
|
||||
@@ -526,8 +526,8 @@ fn wizard_can_go_back_from_delete_menu() {
|
||||
},
|
||||
],
|
||||
sync_visibility: SyncVisibility::All,
|
||||
repo_whitelist: Vec::new(),
|
||||
repo_blacklist: Vec::new(),
|
||||
repo_whitelist: None,
|
||||
repo_blacklist: None,
|
||||
create_missing: true,
|
||||
visibility: Visibility::Private,
|
||||
conflict_resolution: ConflictResolutionStrategy::Fail,
|
||||
|
||||
@@ -531,7 +531,7 @@ where
|
||||
W: Write,
|
||||
{
|
||||
let existing = existing.cloned().unwrap_or_default();
|
||||
let has_existing = !existing.whitelist.is_empty() || !existing.blacklist.is_empty();
|
||||
let has_existing = existing.whitelist.is_some() || existing.blacklist.is_some();
|
||||
if !prompt_bool(
|
||||
reader,
|
||||
writer,
|
||||
@@ -542,40 +542,34 @@ where
|
||||
}
|
||||
|
||||
Ok(RepoFilterInput {
|
||||
whitelist: prompt_repo_pattern_list(
|
||||
whitelist: prompt_repo_pattern(
|
||||
reader,
|
||||
writer,
|
||||
"Whitelist regexes (comma-separated, empty means all repo names)",
|
||||
"Whitelist regex (empty means all repo names)",
|
||||
&existing.whitelist,
|
||||
)?,
|
||||
blacklist: prompt_repo_pattern_list(
|
||||
reader,
|
||||
writer,
|
||||
"Blacklist regexes (comma-separated)",
|
||||
&existing.blacklist,
|
||||
)?,
|
||||
blacklist: prompt_repo_pattern(reader, writer, "Blacklist regex", &existing.blacklist)?,
|
||||
})
|
||||
}
|
||||
|
||||
fn prompt_repo_pattern_list<R, W>(
|
||||
fn prompt_repo_pattern<R, W>(
|
||||
reader: &mut R,
|
||||
writer: &mut W,
|
||||
label: &str,
|
||||
existing: &[String],
|
||||
) -> Result<Vec<String>>
|
||||
existing: &Option<String>,
|
||||
) -> Result<Option<String>>
|
||||
where
|
||||
R: BufRead,
|
||||
W: Write,
|
||||
{
|
||||
let value = if existing.is_empty() {
|
||||
prompt_optional(reader, writer, label)?
|
||||
} else {
|
||||
prompt_with_default(reader, writer, label, &existing.join(", "))?
|
||||
let value = match existing {
|
||||
Some(existing) => prompt_with_default(reader, writer, label, existing)?,
|
||||
None => prompt_optional(reader, writer, label)?,
|
||||
};
|
||||
if let Err(error) = validate_repo_pattern_list(&value) {
|
||||
if let Err(error) = validate_repo_pattern(&value) {
|
||||
bail!(error);
|
||||
}
|
||||
Ok(parse_repo_pattern_list(&value))
|
||||
Ok(parse_repo_pattern(&value))
|
||||
}
|
||||
|
||||
fn sync_visibility_value(sync_visibility: &SyncVisibility) -> &'static str {
|
||||
|
||||
+3
-3
@@ -344,7 +344,7 @@ fn all_visibility_keeps_state_only_repos_for_deletion_detection() {
|
||||
#[test]
|
||||
fn repo_name_filters_do_not_treat_state_only_repos_as_deleted() {
|
||||
let mut mirror = test_mirror();
|
||||
mirror.repo_whitelist = vec!["^public-".to_string()];
|
||||
mirror.repo_whitelist = Some("^public-".to_string());
|
||||
let repo_filter = mirror.repo_filter().unwrap();
|
||||
let mut ref_state = RefState::default();
|
||||
ref_state.set_repo(
|
||||
@@ -472,8 +472,8 @@ fn test_mirror() -> MirrorConfig {
|
||||
name: "sync-1".to_string(),
|
||||
endpoints: vec![endpoint("github"), endpoint("gitea")],
|
||||
sync_visibility: crate::config::SyncVisibility::All,
|
||||
repo_whitelist: Vec::new(),
|
||||
repo_blacklist: Vec::new(),
|
||||
repo_whitelist: None,
|
||||
repo_blacklist: None,
|
||||
create_missing: true,
|
||||
visibility: crate::config::Visibility::Private,
|
||||
conflict_resolution: ConflictResolutionStrategy::Fail,
|
||||
|
||||
@@ -112,8 +112,8 @@ fn matches_jobs_by_provider_and_namespace() {
|
||||
endpoint("gitea", NamespaceKind::User, "azalea"),
|
||||
],
|
||||
sync_visibility: SyncVisibility::All,
|
||||
repo_whitelist: Vec::new(),
|
||||
repo_blacklist: Vec::new(),
|
||||
repo_whitelist: None,
|
||||
repo_blacklist: None,
|
||||
create_missing: true,
|
||||
visibility: Visibility::Private,
|
||||
conflict_resolution: ConflictResolutionStrategy::Fail,
|
||||
@@ -139,8 +139,8 @@ fn matching_jobs_respects_repo_name_filters() {
|
||||
name: "sync-1".to_string(),
|
||||
endpoints: vec![endpoint("github", NamespaceKind::User, "alice")],
|
||||
sync_visibility: SyncVisibility::All,
|
||||
repo_whitelist: vec!["^important-".to_string()],
|
||||
repo_blacklist: vec!["-archive$".to_string()],
|
||||
repo_whitelist: Some("^important-".to_string()),
|
||||
repo_blacklist: Some("-archive$".to_string()),
|
||||
create_missing: true,
|
||||
visibility: Visibility::Private,
|
||||
conflict_resolution: ConflictResolutionStrategy::Fail,
|
||||
@@ -159,7 +159,7 @@ fn matching_jobs_respects_repo_name_filters() {
|
||||
assert!(matching_jobs(&config, &webhook_event("important-archive")).is_empty());
|
||||
assert!(matching_jobs(&config, &webhook_event("random")).is_empty());
|
||||
|
||||
mirror.repo_whitelist.clear();
|
||||
mirror.repo_whitelist = None;
|
||||
let config = Config {
|
||||
jobs: crate::config::DEFAULT_JOBS,
|
||||
sites: vec![site("github", ProviderKind::Github)],
|
||||
@@ -357,8 +357,8 @@ fn uninstall_webhooks_skips_blocked_provider_access() {
|
||||
endpoint("github-peer", NamespaceKind::User, "bob"),
|
||||
],
|
||||
sync_visibility: SyncVisibility::Public,
|
||||
repo_whitelist: Vec::new(),
|
||||
repo_blacklist: Vec::new(),
|
||||
repo_whitelist: None,
|
||||
repo_blacklist: None,
|
||||
create_missing: true,
|
||||
visibility: Visibility::Private,
|
||||
conflict_resolution: ConflictResolutionStrategy::Fail,
|
||||
@@ -710,8 +710,8 @@ fn filtered_mirror() -> MirrorConfig {
|
||||
endpoint("github-peer", NamespaceKind::User, "bob"),
|
||||
],
|
||||
sync_visibility: SyncVisibility::Public,
|
||||
repo_whitelist: vec!["^important-".to_string()],
|
||||
repo_blacklist: vec!["-archive$".to_string()],
|
||||
repo_whitelist: Some("^important-".to_string()),
|
||||
repo_blacklist: Some("-archive$".to_string()),
|
||||
create_missing: true,
|
||||
visibility: Visibility::Private,
|
||||
conflict_resolution: ConflictResolutionStrategy::Fail,
|
||||
|
||||
Reference in New Issue
Block a user