Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/github_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,15 @@ fn trainees_from_sheet(sheet: &Sheet) -> Result<BTreeMap<GithubLogin, Trainee>,
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))?,
Expand Down
13 changes: 2 additions & 11 deletions src/mentoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Result<Vec<_>, _>>()?;
let headings = cells.iter().take(6).map(cell_string).collect::<Vec<_>>();
if headings != ["Name", "Region", "Date", "Staff", "Status", "Notes"] {
return Err(Error::Fatal(anyhow::anyhow!(
"Mentoring data sheet contained wrong headings: {}",
Expand All @@ -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);
Expand Down
34 changes: 9 additions & 25 deletions src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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::<Result<Vec<_>, _>>()?;
let headings = cells.iter().take(7).map(cell_string).collect::<Vec<_>>();
if headings
!= [
"Name",
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 6 additions & 13 deletions src/reviewer_staff_info.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::BTreeMap;

use anyhow::Context;
use sheets::types::Sheet;

use crate::{
Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
);
Expand Down
12 changes: 6 additions & 6 deletions src/sheets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ use crate::{
Error, ServerState,
};

pub(crate) fn cell_string(cell: &CellData) -> Result<String, anyhow::Error> {
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<bool, anyhow::Error> {
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
}
}

Expand Down