diff --git a/src/github_accounts.rs b/src/github_accounts.rs index f917da8..bebbf8d 100644 --- a/src/github_accounts.rs +++ b/src/github_accounts.rs @@ -78,19 +78,15 @@ fn trainees_from_sheet(sheet: &Sheet) -> Result, return Err(Error::Fatal(anyhow::anyhow!("Reading trainee data from Google Sheets API, row {} didn't have at least 5 columns", row_index))); } - let github_login = GithubLogin::from( - cell_string(&cells[3]).context("Failed to read trainee github login")?, - ); + let github_login = GithubLogin::from(cell_string(&cells[3])); - let email = cell_string(&cells[4]).context("Failed to read trainee email")?; + let email = cell_string(&cells[4]); trainees.insert( github_login.clone(), Trainee { - name: cell_string(&cells[1]).context("Failed to read trainee name")?, - region: Region( - cell_string(&cells[2]).context("Failed to read trainee region")?, - ), + name: cell_string(&cells[1]), + region: Region(cell_string(&cells[2])), github_login, email: new_case_insensitive_email_address(&email) .with_context(|| format!("Failed to parse trainee email {}", email))?, diff --git a/src/mentoring.rs b/src/mentoring.rs index 10b1051..0206d44 100644 --- a/src/mentoring.rs +++ b/src/mentoring.rs @@ -94,15 +94,7 @@ pub async fn get_mentoring_records( continue; } if row_number == 0 { - let headings = cells - .iter() - .take(6) - .enumerate() - .map(|(col_number, cell)| { - cell_string(cell) - .with_context(|| format!("Failed to get row 0 column {}", col_number)) - }) - .collect::, _>>()?; + let headings = cells.iter().take(6).map(cell_string).collect::>(); if headings != ["Name", "Region", "Date", "Staff", "Status", "Notes"] { return Err(Error::Fatal(anyhow::anyhow!( "Mentoring data sheet contained wrong headings: {}", @@ -113,8 +105,7 @@ pub async fn get_mentoring_records( if cells[0].effective_value.is_none() { break; } - let name = cell_string(&cells[0]) - .with_context(|| format!("Failed to read name from row {}", row_number + 1))?; + let name = cell_string(&cells[0]); let date = cell_date(&cells[2]) .with_context(|| format!("Failed to parse date from row {}", row_number + 1))?; let entry = mentoring_records.records.entry(name); diff --git a/src/register.rs b/src/register.rs index 1121cd1..8465e32 100644 --- a/src/register.rs +++ b/src/register.rs @@ -125,10 +125,7 @@ fn read_module( for (row_number, row) in data.row_data.into_iter().enumerate() { let cells = row.values; // Some sheets have documentation or pivot table - if row_number == 0 - && !cells.is_empty() - && cell_string(&cells[0]).unwrap_or_default() != "Name" - { + if row_number == 0 && !cells.is_empty() && cell_string(&cells[0]) != "Name" { continue 'sheet; } if cells.len() < 7 { @@ -140,15 +137,7 @@ fn read_module( )); } if row_number == 0 { - let headings = cells - .iter() - .take(7) - .enumerate() - .map(|(col_number, cell)| { - cell_string(cell) - .with_context(|| format!("Failed to get row 0 column {}", col_number)) - }) - .collect::, _>>()?; + let headings = cells.iter().take(7).map(cell_string).collect::>(); if headings != [ "Name", @@ -200,18 +189,13 @@ fn read_row( cells: &[CellData], register_url: String, ) -> Result<(usize, Attendance), anyhow::Error> { - let sprint_number = extract_sprint_number( - &cell_string(&cells[5]).context("Couldn't get sprint value from column 5")?, - )?; - let name = cell_string(&cells[0]).context("Failed to read name")?; - let email = new_case_insensitive_email_address( - &cell_string(&cells[1]).context("Failed to read email")?, - )?; - let timestamp = - DateTime::parse_from_rfc3339(&cell_string(&cells[2]).context("Failed to read timestamp")?) - .context("Failed to parse timestamp")? - .to_utc(); - let region = cell_string(&cells[6]).context("Failed to read region")?; + let sprint_number = extract_sprint_number(&cell_string(&cells[5]))?; + let name = cell_string(&cells[0]); + let email = new_case_insensitive_email_address(&cell_string(&cells[1]))?; + let timestamp = DateTime::parse_from_rfc3339(&cell_string(&cells[2])) + .context("Failed to parse timestamp")? + .to_utc(); + let region = cell_string(&cells[6]); Ok(( sprint_number, Attendance { diff --git a/src/reviewer_staff_info.rs b/src/reviewer_staff_info.rs index 910c088..0661727 100644 --- a/src/reviewer_staff_info.rs +++ b/src/reviewer_staff_info.rs @@ -1,6 +1,5 @@ use std::collections::BTreeMap; -use anyhow::Context; use sheets::types::Sheet; use crate::{ @@ -70,19 +69,14 @@ fn reviewer_staff_detail_from_sheet( continue; } - let github_login = GithubLogin::from( - cell_string(&cells[0]).context("Failed to read reviewer github login")?, - ); + let github_login = GithubLogin::from(cell_string(&cells[0])); let notes = match cells.get(6) { - Some(cell) => cell_string(cell).context("Failed to read reviewer notes")?, + Some(cell) => cell_string(cell), None => String::new(), }; - let checked = match ( - cell_bool(&cells[3]).context("Failed to read reviewer checked")?, - cell_bool(&cells[4]).context("Failed to read reviewer check again")?, - ) { + let checked = match (cell_bool(&cells[3]), cell_bool(&cells[4])) { (true, false) => CheckStatus::CheckedAndOk, (true, true) => CheckStatus::CheckedAndCheckAgain, (false, _) => CheckStatus::Unchecked, @@ -91,11 +85,10 @@ fn reviewer_staff_detail_from_sheet( reviewers.insert( github_login.clone(), ReviewerStaffOnlyDetails { - name: cell_string(&cells[1]).context("Failed to read reviewer name")?, - attended_training: cell_bool(&cells[2]) - .context("Failed to read reviewer attended training state")?, + name: cell_string(&cells[1]), + attended_training: cell_bool(&cells[2]), checked, - quality: cell_string(&cells[5]).context("Failed to read reviewer quality")?, + quality: cell_string(&cells[5]), notes, }, ); diff --git a/src/sheets.rs b/src/sheets.rs index ea62400..7f13ddd 100644 --- a/src/sheets.rs +++ b/src/sheets.rs @@ -8,21 +8,21 @@ use crate::{ Error, ServerState, }; -pub(crate) fn cell_string(cell: &CellData) -> Result { +pub(crate) fn cell_string(cell: &CellData) -> String { let value = cell.effective_value.clone(); if let Some(value) = value { - Ok(value.string_value) + value.string_value } else { - Ok(String::new()) + String::new() } } -pub(crate) fn cell_bool(cell: &CellData) -> Result { +pub(crate) fn cell_bool(cell: &CellData) -> bool { let value = cell.effective_value.clone(); if let Some(value) = value { - Ok(value.bool_value) + value.bool_value } else { - Ok(false) + false } }