Compare commits

47 Commits

Author SHA1 Message Date
azalea 81edd9b8bf [F] Fix logging 2026-05-10 10:45:33 +00:00
azalea 09cede6658 [F] Fix log sync 2026-05-10 06:14:32 +00:00
azalea 009ba9b247 [U] info 2026-05-10 05:46:50 +00:00
azalea fbf5534fe3 [F] Visibility sync 2026-05-10 01:36:06 +00:00
azalea b41f530d1e [O] Parallel everything (#5) 2026-05-10 09:28:38 +08:00
azalea 915a63a955 [F] Fix gitlab project listing 2026-05-10 01:07:47 +00:00
azalea b0469d80a7 [F] Fix webhook uninstall 2026-05-09 23:53:43 +00:00
azalea 260f42b973 [F] Webhook issues 2026-05-09 23:44:18 +00:00
azalea 44b1865b15 [F] Fix webhook uninstall missing url 2026-05-09 22:47:02 +00:00
azalea de88150445 [O] Webhook install respect filters 2026-05-09 22:38:50 +00:00
azalea f94a0f11b5 [F] Fix gitea pagination 2026-05-09 22:24:13 +00:00
azalea 0ee43ea58f [O] Test actual PR 2026-05-09 19:37:08 +00:00
azalea 10c55062eb [-] Remove legacy features 2026-05-09 17:41:20 +00:00
azalea f3c0b90a0d [U] Update deps 2026-05-09 17:07:45 +00:00
azalea 513bda3696 [O] UX 2026-05-09 08:22:31 +00:00
azalea 018f1f12d5 [O] UX 2026-05-08 16:24:23 +00:00
azalea 3d73f20c1f [+] End-to-end testing 2026-05-08 15:32:33 +00:00
azalea e43e555b37 [+] Track repo deletions 2026-05-08 07:01:32 +00:00
azalea bc6509ad59 [U] Readme 2026-05-08 06:59:17 +00:00
azalea f28f96f27c [U] Readme 2026-05-08 06:57:55 +00:00
azalea 527e69dc4a [O] Readme 2026-05-08 06:44:26 +00:00
azalea 566c3c1b59 [F] Fix build 2026-05-08 06:33:42 +00:00
azalea b7f3404f99 [+] Docker 2026-05-08 06:29:13 +00:00
azalea d19b061f7c [O] Rewrite readme 2026-05-08 05:58:02 +00:00
azalea 9a9cbba767 [M] Rebrand 2026-05-08 05:34:08 +00:00
azalea ebeb045c51 [+] Conflict resolution (#4)
* [+] Conflict resolution

* [F] Fix conflict resolution branches being synched
2026-05-08 13:16:13 +08:00
azalea 67dd55a1cf [O] Rework webhook 2026-05-08 04:13:45 +00:00
azalea 0566e97c6a [O] Better webhook error handling 2026-05-08 01:03:30 +00:00
azalea 60b6caf1a6 [O] Better interactive config 2026-05-08 00:52:37 +00:00
azalea 9c651728e4 [+] Github Actions builder 2026-05-07 18:48:04 +00:00
azalea 7fc3ab32ad [M] Move tests 2026-05-07 18:27:38 +00:00
azalea 17e3961267 [O] Cleanup codebase 2026-05-07 18:08:33 +00:00
azalea 19658c4ba9 [O] Clean up codebase 2026-05-07 16:41:18 +00:00
azalea 4545a5e515 Revert "[O] Use libraries"
This reverts commit b225c4bbd8.
2026-05-07 16:27:28 +00:00
azalea b225c4bbd8 [O] Use libraries 2026-05-07 15:03:47 +00:00
azalea c013ce1858 [+] Webhook mode 2026-05-07 04:55:49 +00:00
azalea 7b65d919d6 [+] Forgejo (#3)
* [+] Forgejo, tangled

* [-] Tangled
2026-05-07 12:45:01 +08:00
azalea 39ba96051c [F] Fix branch deletion awareness 2026-05-07 02:58:43 +00:00
azalea b70eaee2aa [F] Fix heuristic 2026-05-07 02:22:34 +00:00
azalea 92bcee49ea [O] Better multithreaded logging 2026-05-06 20:19:13 +00:00
azalea bb991d94f0 [+] Multithreading 2026-05-06 20:05:59 +00:00
azalea 61450e3a97 [O] Optimize sync with heuristic 2026-05-06 18:32:16 +00:00
azalea 18cf024b6e [+] Retry 2026-05-06 17:42:20 +00:00
azalea 3c0b3fc1e8 [O] Better CLI wizard (#2) 2026-05-04 06:49:25 +08:00
azalea 0cdabb09e6 [O] Better CLI wizard (#1) 2026-05-04 01:54:43 +08:00
azalea fd7e0db96d Initial commit 2026-05-03 17:27:50 +00:00
azalea 947e71d1fd [+] Create repo by codex 2026-05-03 17:24:24 +00:00
12 changed files with 150 additions and 312 deletions
+3 -3
View File
@@ -69,8 +69,8 @@ token = { value = "gitea_pat_..." }
[[mirrors]]
name = "personal"
sync_visibility = "all"
repo_whitelist = "^important-"
repo_blacklist = "-archive$"
repo_whitelist = ["^important-"]
repo_blacklist = ["-archive$"]
create_missing = true
visibility = "private"
conflict_resolution = "auto_rebase_pull_request"
@@ -179,7 +179,7 @@ Each mirror group is treated as a set of equivalent namespaces. Repositories are
Set `sync_visibility = "all"`, `"private"`, or `"public"` on a mirror group to choose which repository visibility is included in that group. When `refray` creates a missing repository, it mirrors the visibility of the existing repository it is syncing from; `visibility` is only a fallback when no source visibility is available.
Set `repo_whitelist = "..."` and/or `repo_blacklist = "..."` on a mirror group to filter repository names with regular expressions. Omit `repo_whitelist` to include all repository names, and blacklist matches are excluded after whitelist matches. These name filters are independent from `sync_visibility`; both must match for a repository to be synced.
Set `repo_whitelist = ["..."]` and/or `repo_blacklist = ["..."]` on a mirror group to filter repository names with regular expressions. An empty whitelist includes all repository names, and blacklist matches are excluded after whitelist matches. These name filters are independent from `sync_visibility`; both must match for a repository to be synced.
For every repository name found in any endpoint, `refray` will:
+23 -29
View File
@@ -56,10 +56,10 @@ pub struct MirrorConfig {
pub endpoints: Vec<EndpointConfig>,
#[serde(default)]
pub sync_visibility: SyncVisibility,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub repo_whitelist: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub repo_blacklist: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub repo_whitelist: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub repo_blacklist: Vec<String>,
#[serde(default = "default_true")]
pub create_missing: bool,
#[serde(default)]
@@ -135,8 +135,8 @@ pub enum SyncVisibility {
#[derive(Clone, Debug)]
pub struct RepoNameFilter {
whitelist: Option<Regex>,
blacklist: Option<Regex>,
whitelist: Vec<Regex>,
blacklist: Vec<Regex>,
}
impl SyncVisibility {
@@ -152,41 +152,35 @@ impl SyncVisibility {
impl MirrorConfig {
pub fn repo_filter(&self) -> Result<RepoNameFilter> {
Ok(RepoNameFilter {
whitelist: compile_repo_pattern(&self.name, "repo_whitelist", &self.repo_whitelist)?,
blacklist: compile_repo_pattern(&self.name, "repo_blacklist", &self.repo_blacklist)?,
whitelist: compile_repo_patterns(&self.name, "repo_whitelist", &self.repo_whitelist)?,
blacklist: compile_repo_patterns(&self.name, "repo_blacklist", &self.repo_blacklist)?,
})
}
}
impl RepoNameFilter {
pub fn matches(&self, repo_name: &str) -> bool {
let whitelisted = self
.whitelist
.as_ref()
.is_none_or(|pattern| pattern.is_match(repo_name));
let whitelisted = self.whitelist.is_empty()
|| self
.whitelist
.iter()
.any(|pattern| pattern.is_match(repo_name));
let blacklisted = self
.blacklist
.as_ref()
.is_some_and(|pattern| pattern.is_match(repo_name));
.iter()
.any(|pattern| pattern.is_match(repo_name));
whitelisted && !blacklisted
}
}
fn compile_repo_pattern(
mirror: &str,
field: &str,
pattern: &Option<String>,
) -> Result<Option<Regex>> {
let Some(pattern) = pattern
.as_deref()
.map(str::trim)
.filter(|pattern| !pattern.is_empty())
else {
return Ok(None);
};
Regex::new(pattern)
.with_context(|| format!("mirror '{mirror}' has invalid {field} regex '{pattern}'"))
.map(Some)
fn compile_repo_patterns(mirror: &str, field: &str, patterns: &[String]) -> Result<Vec<Regex>> {
patterns
.iter()
.map(|pattern| {
Regex::new(pattern)
.with_context(|| format!("mirror '{mirror}' has invalid {field} regex '{pattern}'"))
})
.collect()
}
fn default_true() -> bool {
+36 -27
View File
@@ -38,8 +38,8 @@ struct ParsedProfileUrl {
#[derive(Clone, Debug, Default)]
struct RepoFilterInput {
whitelist: Option<String>,
blacklist: Option<String>,
whitelist: Vec<String>,
blacklist: Vec<String>,
}
pub fn run_config_wizard(path: &Path) -> Result<ConfigWizardOutcome> {
@@ -780,7 +780,7 @@ fn prompt_repo_filters_styled(
existing: Option<&RepoFilterInput>,
) -> Result<RepoFilterInput> {
let existing = existing.cloned().unwrap_or_default();
let has_existing = existing.whitelist.is_some() || existing.blacklist.is_some();
let has_existing = !existing.whitelist.is_empty() || !existing.blacklist.is_empty();
if !Confirm::with_theme(theme)
.with_prompt("Configure repository name whitelist/blacklist?")
.default(has_existing)
@@ -790,44 +790,51 @@ fn prompt_repo_filters_styled(
}
Ok(RepoFilterInput {
whitelist: prompt_repo_pattern_styled(
whitelist: prompt_repo_pattern_list_styled(
theme,
"Whitelist regex (empty means all repo names)",
"Whitelist regexes (comma-separated, empty means all repo names)",
&existing.whitelist,
)?,
blacklist: prompt_repo_pattern_styled(theme, "Blacklist regex", &existing.blacklist)?,
blacklist: prompt_repo_pattern_list_styled(
theme,
"Blacklist regexes (comma-separated)",
&existing.blacklist,
)?,
})
}
fn prompt_repo_pattern_styled(
fn prompt_repo_pattern_list_styled(
theme: &ColorfulTheme,
prompt: &str,
existing: &Option<String>,
) -> Result<Option<String>> {
existing: &[String],
) -> Result<Vec<String>> {
let input = Input::<String>::with_theme(theme)
.with_prompt(prompt)
.allow_empty(true)
.validate_with(|value: &String| validate_repo_pattern(value));
let input = if let Some(existing) = existing {
input.default(existing.clone())
} else {
.validate_with(|value: &String| validate_repo_pattern_list(value));
let input = if existing.is_empty() {
input
} else {
input.default(existing.join(", "))
};
let value = input.interact_text()?;
Ok(parse_repo_pattern(&value))
Ok(parse_repo_pattern_list(&value))
}
fn validate_repo_pattern(value: &str) -> std::result::Result<(), String> {
let Some(pattern) = parse_repo_pattern(value) else {
return Ok(());
};
Regex::new(&pattern).map_err(|error| format!("invalid regex '{pattern}': {error}"))?;
fn validate_repo_pattern_list(value: &str) -> std::result::Result<(), String> {
for pattern in parse_repo_pattern_list(value) {
Regex::new(&pattern).map_err(|error| format!("invalid regex '{pattern}': {error}"))?;
}
Ok(())
}
fn parse_repo_pattern(value: &str) -> Option<String> {
let value = value.trim();
(!value.is_empty()).then(|| value.to_string())
fn parse_repo_pattern_list(value: &str) -> Vec<String> {
value
.split(',')
.map(str::trim)
.filter(|value| !value.is_empty())
.map(ToOwned::to_owned)
.collect()
}
fn sync_visibility_index(sync_visibility: &SyncVisibility) -> usize {
@@ -930,11 +937,13 @@ fn sync_visibility_label(sync_visibility: &SyncVisibility) -> &'static str {
}
fn repo_filter_label(mirror: &MirrorConfig) -> String {
match (&mirror.repo_whitelist, &mirror.repo_blacklist) {
(None, None) => "repos: all names".to_string(),
(Some(_), None) => "repos: whitelist".to_string(),
(None, Some(_)) => "repos: blacklist".to_string(),
(Some(_), Some(_)) => "repos: whitelist + blacklist".to_string(),
match (mirror.repo_whitelist.len(), mirror.repo_blacklist.len()) {
(0, 0) => "repos: all names".to_string(),
(whitelist, 0) => format!("repos: whitelist {whitelist}"),
(0, blacklist) => format!("repos: blacklist {blacklist}"),
(whitelist, blacklist) => {
format!("repos: whitelist {whitelist}, blacklist {blacklist}")
}
}
}
+23 -169
View File
@@ -1,27 +1,14 @@
use std::cell::RefCell;
use std::fmt;
use std::io::{self, IsTerminal, Write};
use std::io::{self, Write};
use std::sync::{Arc, Mutex, OnceLock};
use console::style;
static OUTPUT: OnceLock<Mutex<OutputState>> = OnceLock::new();
static OUTPUT: OnceLock<Mutex<()>> = OnceLock::new();
thread_local! {
static REPO_LOG: RefCell<Option<ActiveRepoLog>> = const { RefCell::new(None) };
}
#[derive(Default)]
struct OutputState {
status: Option<StatusState>,
}
struct StatusState {
slots: Vec<Option<String>>,
visible: bool,
interactive: bool,
}
#[derive(Clone)]
pub(crate) struct RepoLogContext {
inner: Arc<RepoLog>,
@@ -33,20 +20,9 @@ struct ActiveRepoLog {
}
struct RepoLog {
repo_name: String,
slot: usize,
width: usize,
lines: Mutex<Vec<String>>,
}
pub struct StatusGuard;
impl Drop for StatusGuard {
fn drop(&mut self) {
finish_status_area();
}
}
pub struct RepoLogGuard;
impl Drop for RepoLogGuard {
@@ -55,29 +31,9 @@ impl Drop for RepoLogGuard {
}
}
pub fn start_status_area(slots: usize) -> StatusGuard {
with_output(|output| {
if let Some(status) = output.status.as_mut() {
clear_status(status);
}
output.status = Some(StatusState {
slots: vec![None; slots],
visible: false,
interactive: io::stdout().is_terminal() && slots > 0,
});
if let Some(status) = output.status.as_mut() {
draw_status(status);
}
});
StatusGuard
}
pub fn start_repo_log(repo_name: String, slot: usize, width: usize) -> RepoLogGuard {
pub fn start_repo_log() -> RepoLogGuard {
let context = RepoLogContext {
inner: Arc::new(RepoLog {
repo_name,
slot,
width,
lines: Mutex::new(Vec::new()),
}),
};
@@ -144,31 +100,13 @@ pub fn finish_repo_log() {
std::mem::take(&mut *lines)
};
with_output(|output| {
if let Some(status) = output.status.as_mut() {
clear_status(status);
if repo_log.slot < status.slots.len() {
status.slots[repo_log.slot] = None;
}
}
with_output(|| {
for line in lines {
println!("{line}");
}
if let Some(status) = output.status.as_mut() {
draw_status(status);
}
});
}
pub fn repo_prefix(repo_name: &str, width: usize) -> String {
let mut prefix = repo_name.chars().take(width).collect::<String>();
if repo_name.chars().count() > width && width > 0 {
prefix.pop();
prefix.push('~');
}
format!("{prefix:<width$}")
}
pub fn line(args: fmt::Arguments<'_>) {
let text = args.to_string();
let context = current_repo_log_context();
@@ -177,119 +115,35 @@ pub fn line(args: fmt::Arguments<'_>) {
return;
}
with_output(|output| {
if let Some(status) = output.status.as_mut() {
clear_status(status);
}
with_output(|| {
println!("{text}");
if let Some(status) = output.status.as_mut() {
draw_status(status);
}
});
}
fn capture_repo_line(context: &RepoLogContext, text: &str) {
let mut status_updates = Vec::new();
{
let mut lines = context
.inner
.lines
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
if text.is_empty() {
lines.push(String::new());
return;
}
for line in text.lines() {
lines.push(line.to_string());
if !line.trim().is_empty() {
status_updates.push(line.trim().to_string());
}
}
}
for line in status_updates {
update_status(context, &line);
}
}
fn update_status(context: &RepoLogContext, line: &str) {
let repo_log = &context.inner;
let repo = repo_prefix(&repo_log.repo_name, repo_log.width);
let line = truncate_status(line, 96);
with_output(|output| {
let Some(status) = output.status.as_mut() else {
return;
};
if repo_log.slot >= status.slots.len() {
return;
}
clear_status(status);
status.slots[repo_log.slot] = Some(format!(
"{} {} {}",
style(format!("worker {}", repo_log.slot + 1)).dim(),
style(repo).cyan().bold(),
line
));
draw_status(status);
});
}
fn truncate_status(value: &str, max_chars: usize) -> String {
if value.chars().count() <= max_chars {
return value.to_string();
}
let mut output = value.chars().take(max_chars).collect::<String>();
output.pop();
output.push('~');
output
}
fn finish_status_area() {
with_output(|output| {
if let Some(status) = output.status.as_mut() {
clear_status(status);
}
output.status = None;
});
}
fn with_output(action: impl FnOnce(&mut OutputState)) {
let output = OUTPUT.get_or_init(|| Mutex::new(OutputState::default()));
let mut output = output
let mut lines = context
.inner
.lines
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
action(&mut output);
if text.is_empty() {
lines.push(String::new());
return;
}
for line in text.lines() {
lines.push(line.to_string());
}
}
fn with_output(action: impl FnOnce()) {
let output = OUTPUT.get_or_init(|| Mutex::new(()));
let _output = output
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
action();
let _ = io::stdout().flush();
}
fn clear_status(status: &mut StatusState) {
if !status.interactive || !status.visible {
return;
}
let lines = status.slots.len();
print!("\x1b[{lines}A\r");
for _ in 0..lines {
println!("\x1b[2K");
}
print!("\x1b[{lines}A\r");
status.visible = false;
}
fn draw_status(status: &mut StatusState) {
if !status.interactive {
return;
}
for slot in &status.slots {
match slot {
Some(line) => println!("{line}"),
None => println!("{}", style("idle").dim()),
}
}
status.visible = true;
}
#[macro_export]
macro_rules! logln {
() => {
+3 -16
View File
@@ -237,7 +237,6 @@ fn sync_group(
);
}
let repo_log_width = repo_log_width(&repo_names);
let repo_jobs = repo_names
.into_iter()
.map(|repo_name| {
@@ -260,11 +259,10 @@ fn sync_group(
let base_ref_state = context.ref_state.clone();
let queue = Arc::new(Mutex::new(repo_jobs));
let (sender, receiver) = mpsc::channel();
let use_status_area = worker_count > 1;
let use_repo_logs = worker_count > 1;
let jobs = context.options.jobs;
let _status_guard = use_status_area.then(|| logging::start_status_area(worker_count));
let failures = thread::scope(|scope| {
for worker_id in 0..worker_count {
for _ in 0..worker_count {
let queue = Arc::clone(&queue);
let sender = sender.clone();
let redactor = context.redactor.clone();
@@ -275,9 +273,7 @@ fn sync_group(
scope.spawn(move || {
while let Some(mut job) = pop_repo_job(&queue) {
let _repo_log_guard = use_status_area.then(|| {
logging::start_repo_log(job.repo_name.clone(), worker_id, repo_log_width)
});
let _repo_log_guard = use_repo_logs.then(logging::start_repo_log);
let repo_context = RepoSyncContext {
config,
mirror,
@@ -383,15 +379,6 @@ fn pop_repo_job(queue: &Arc<Mutex<VecDeque<RepoSyncJob>>>) -> Option<RepoSyncJob
.pop_front()
}
fn repo_log_width(repo_names: &BTreeSet<String>) -> usize {
repo_names
.iter()
.map(|name| name.chars().count())
.max()
.unwrap_or(4)
.clamp(4, 32)
}
struct RepoSyncJob {
repo_name: String,
existing: Vec<EndpointRepo>,
+2 -2
View File
@@ -339,7 +339,7 @@ secret = {{ value = "{WEBHOOK_SECRET}" }}
[[mirrors]]
name = "all"
sync_visibility = "all"
repo_whitelist = '{}'
repo_whitelist = ['{}']
create_missing = {}
visibility = "public"
conflict_resolution = "{}"
@@ -788,7 +788,7 @@ namespace = "{}"
let contents = fs::read_to_string(&self.config_path)
.with_context(|| format!("failed to read {}", self.config_path.display()))?;
let escaped_pattern = pattern.replace('\'', "''");
let replacement = format!("repo_whitelist = '{escaped_pattern}'");
let replacement = format!("repo_whitelist = ['{escaped_pattern}']");
let mut replaced = false;
let mut updated = contents
.lines()
+15 -15
View File
@@ -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,
Some("^important-|-mirror$".to_string())
vec!["^important-".to_string(), "-mirror$".to_string()]
);
assert_eq!(
config.mirrors[0].repo_blacklist,
Some("-archive$".to_string())
vec!["-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: None,
repo_blacklist: None,
repo_whitelist: Vec::new(),
repo_blacklist: Vec::new(),
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: None,
repo_blacklist: None,
repo_whitelist: Vec::new(),
repo_blacklist: Vec::new(),
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 = Some("^important-|-mirror$".to_string());
mirror.repo_blacklist = Some("-archive$".to_string());
mirror.repo_whitelist = vec!["^important-".to_string(), "-mirror$".to_string()];
mirror.repo_blacklist = vec!["-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 = Some("(".to_string());
config.mirrors[0].repo_whitelist = vec!["(".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: None,
repo_blacklist: None,
repo_whitelist: Vec::new(),
repo_blacklist: Vec::new(),
create_missing: true,
visibility: Visibility::Private,
conflict_resolution: ConflictResolutionStrategy::Fail,
@@ -284,8 +284,8 @@ fn mirror_config() -> MirrorConfig {
},
],
sync_visibility: SyncVisibility::All,
repo_whitelist: None,
repo_blacklist: None,
repo_whitelist: Vec::new(),
repo_blacklist: Vec::new(),
create_missing: true,
visibility: Visibility::Private,
conflict_resolution: ConflictResolutionStrategy::Fail,
+14 -14
View File
@@ -211,8 +211,8 @@ fn wizard_starts_existing_config_at_sync_group_menu() {
},
],
sync_visibility: SyncVisibility::All,
repo_whitelist: None,
repo_blacklist: None,
repo_whitelist: Vec::new(),
repo_blacklist: Vec::new(),
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: None,
repo_blacklist: None,
repo_whitelist: Vec::new(),
repo_blacklist: Vec::new(),
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: Some("^important-".to_string()),
repo_blacklist: Some("-archive$".to_string()),
repo_whitelist: vec!["^important-".to_string()],
repo_blacklist: vec!["-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, Some("^public-".to_string()));
assert_eq!(mirror.repo_blacklist, Some("-skip$".to_string()));
assert_eq!(mirror.repo_whitelist, vec!["^public-".to_string()]);
assert_eq!(mirror.repo_blacklist, vec!["-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: None,
repo_blacklist: None,
repo_whitelist: Vec::new(),
repo_blacklist: Vec::new(),
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: None,
repo_blacklist: None,
repo_whitelist: Vec::new(),
repo_blacklist: Vec::new(),
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: None,
repo_blacklist: None,
repo_whitelist: Vec::new(),
repo_blacklist: Vec::new(),
create_missing: true,
visibility: Visibility::Private,
conflict_resolution: ConflictResolutionStrategy::Fail,
+18 -12
View File
@@ -531,7 +531,7 @@ where
W: Write,
{
let existing = existing.cloned().unwrap_or_default();
let has_existing = existing.whitelist.is_some() || existing.blacklist.is_some();
let has_existing = !existing.whitelist.is_empty() || !existing.blacklist.is_empty();
if !prompt_bool(
reader,
writer,
@@ -542,34 +542,40 @@ where
}
Ok(RepoFilterInput {
whitelist: prompt_repo_pattern(
whitelist: prompt_repo_pattern_list(
reader,
writer,
"Whitelist regex (empty means all repo names)",
"Whitelist regexes (comma-separated, empty means all repo names)",
&existing.whitelist,
)?,
blacklist: prompt_repo_pattern(reader, writer, "Blacklist regex", &existing.blacklist)?,
blacklist: prompt_repo_pattern_list(
reader,
writer,
"Blacklist regexes (comma-separated)",
&existing.blacklist,
)?,
})
}
fn prompt_repo_pattern<R, W>(
fn prompt_repo_pattern_list<R, W>(
reader: &mut R,
writer: &mut W,
label: &str,
existing: &Option<String>,
) -> Result<Option<String>>
existing: &[String],
) -> Result<Vec<String>>
where
R: BufRead,
W: Write,
{
let value = match existing {
Some(existing) => prompt_with_default(reader, writer, label, existing)?,
None => prompt_optional(reader, writer, label)?,
let value = if existing.is_empty() {
prompt_optional(reader, writer, label)?
} else {
prompt_with_default(reader, writer, label, &existing.join(", "))?
};
if let Err(error) = validate_repo_pattern(&value) {
if let Err(error) = validate_repo_pattern_list(&value) {
bail!(error);
}
Ok(parse_repo_pattern(&value))
Ok(parse_repo_pattern_list(&value))
}
fn sync_visibility_value(sync_visibility: &SyncVisibility) -> &'static str {
+1 -13
View File
@@ -1,20 +1,8 @@
use super::*;
#[test]
fn repo_prefix_pads_and_truncates_to_fixed_width() {
assert_eq!(repo_prefix("api", 6), "api ");
assert_eq!(repo_prefix("very-long-repo", 8), "very-lo~");
}
#[test]
fn status_text_truncates_to_fixed_width() {
assert_eq!(truncate_status("short", 8), "short");
assert_eq!(truncate_status("very-long-status", 8), "very-lo~");
}
#[test]
fn repo_log_context_is_inherited_by_parallel_workers() {
let _guard = start_repo_log("repo-a".to_string(), 0, 8);
let _guard = start_repo_log();
crate::logln!("outer line");
crate::parallel::map(vec!["worker line"], 1, |line| {
+3 -3
View File
@@ -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 = Some("^public-".to_string());
mirror.repo_whitelist = vec!["^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: None,
repo_blacklist: None,
repo_whitelist: Vec::new(),
repo_blacklist: Vec::new(),
create_missing: true,
visibility: crate::config::Visibility::Private,
conflict_resolution: ConflictResolutionStrategy::Fail,
+9 -9
View File
@@ -112,8 +112,8 @@ fn matches_jobs_by_provider_and_namespace() {
endpoint("gitea", NamespaceKind::User, "azalea"),
],
sync_visibility: SyncVisibility::All,
repo_whitelist: None,
repo_blacklist: None,
repo_whitelist: Vec::new(),
repo_blacklist: Vec::new(),
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: Some("^important-".to_string()),
repo_blacklist: Some("-archive$".to_string()),
repo_whitelist: vec!["^important-".to_string()],
repo_blacklist: vec!["-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 = None;
mirror.repo_whitelist.clear();
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: None,
repo_blacklist: None,
repo_whitelist: Vec::new(),
repo_blacklist: Vec::new(),
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: Some("^important-".to_string()),
repo_blacklist: Some("-archive$".to_string()),
repo_whitelist: vec!["^important-".to_string()],
repo_blacklist: vec!["-archive$".to_string()],
create_missing: true,
visibility: Visibility::Private,
conflict_resolution: ConflictResolutionStrategy::Fail,