diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2024-07-20 18:20:30 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-07-20 18:20:30 -0400 |
commit | 97452c235d6702111af7aba837754beb58b6b0a1 (patch) | |
tree | 7bd558bd3a97bc17dedb5f730f00bcd8cb6638ee | |
parent | f0b171b409817a7a4ac6f6eb845fe47ac618b4a2 (diff) |
Handle malformed user configs
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r-- | src/bin/cgi.rs | 5 | ||||
-rw-r--r-- | src/bin/gc-results.rs | 12 | ||||
-rw-r--r-- | src/bin/gen-job-list.rs | 5 | ||||
-rw-r--r-- | src/lib.rs | 4 |
4 files changed, 16 insertions, 10 deletions
diff --git a/src/bin/cgi.rs b/src/bin/cgi.rs index 9bac1c7..a340dba 100644 --- a/src/bin/cgi.rs +++ b/src/bin/cgi.rs @@ -302,7 +302,10 @@ fn ci_user(ci: &Ci) -> cgi::Response { writeln!(&mut out, "<body>").unwrap(); - ci_list_branches(ci, &u, &mut out); + match u { + Ok(u) => ci_list_branches(ci, &u, &mut out), + Err(e) => writeln!(out, "error parsing user config: {}", e).unwrap(), + } writeln!(&mut out, "</body>").unwrap(); writeln!(&mut out, "</html>").unwrap(); diff --git a/src/bin/gc-results.rs b/src/bin/gc-results.rs index d2f17ec..ce81b5e 100644 --- a/src/bin/gc-results.rs +++ b/src/bin/gc-results.rs @@ -49,11 +49,13 @@ fn get_live_commits(rc: &CiConfig) -> HashSet<String> let mut ret: HashSet<String> = HashSet::new(); for (_, user) in rc.users.iter() { - for (branch, branch_config) in user.branch.iter() { - for test_group in branch_config.tests.iter() { - let max_commits = user.test_group.get(test_group).map(|x| x.max_commits).unwrap_or(0); - for commit in branch_get_commits(&repo, &branch, max_commits) { - ret.insert(commit); + if let Ok(user) = user { + for (branch, branch_config) in user.branch.iter() { + for test_group in branch_config.tests.iter() { + let max_commits = user.test_group.get(test_group).map(|x| x.max_commits).unwrap_or(0); + for commit in branch_get_commits(&repo, &branch, max_commits) { + ret.insert(commit); + } } } } diff --git a/src/bin/gen-job-list.rs b/src/bin/gen-job-list.rs index c41fc29..e71c1a9 100644 --- a/src/bin/gen-job-list.rs +++ b/src/bin/gen-job-list.rs @@ -167,7 +167,8 @@ fn user_test_jobs(rc: &CiConfig, repo: &git2::Repository, fn rc_test_jobs(rc: &CiConfig, repo: &git2::Repository, verbose: bool) -> Vec<TestJob> { let mut ret: Vec<_> = rc.users.iter() - .flat_map(|(_, user)| user_test_jobs(rc, repo, &user, verbose)) + .filter_map(|u| u.1.as_ref().ok()) + .flat_map(|user| user_test_jobs(rc, repo, &user, verbose)) .collect(); /* sort by commit, dedup */ @@ -211,7 +212,7 @@ fn write_test_jobs(rc: &CiConfig, jobs_in: Vec<TestJob>, verbose: bool) -> anyho fn fetch_remotes(rc: &CiConfig, repo: &git2::Repository) -> anyhow::Result<bool> { fn fetch_remotes_locked(rc: &CiConfig, repo: &git2::Repository) -> Result<(), git2::Error> { - for (_, userconfig) in &rc.users { + for userconfig in rc.users.iter().filter_map(|u| u.1.as_ref().ok()) { for (branch, branchconfig) in &userconfig.branch { let fetch = branchconfig.fetch .split_whitespace() @@ -50,7 +50,7 @@ pub fn ktestrc_read() -> anyhow::Result<Ktestrc> { pub struct CiConfig { pub ktest: Ktestrc, - pub users: BTreeMap<String, Userrc>, + pub users: BTreeMap<String, anyhow::Result<Userrc>>, } pub fn ciconfig_read() -> anyhow::Result<CiConfig> { @@ -63,7 +63,7 @@ pub fn ciconfig_read() -> anyhow::Result<CiConfig> { .filter_map(|x| x.ok()) .map(|i| i.path()){ rc.users.insert(i.file_stem().unwrap().to_string_lossy().to_string(), - users::userrc_read(&i)?); + users::userrc_read(&i)); } Ok(rc) |