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
6 changes: 3 additions & 3 deletions src/github_accounts.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{collections::BTreeMap, str::FromStr};
use std::collections::BTreeMap;

use anyhow::Context;
use email_address::EmailAddress;
use serde::{Deserialize, Serialize};
use sheets::types::Sheet;

use crate::{
newtypes::{GithubLogin, Region},
newtypes::{new_case_insensitive_email_address, GithubLogin, Region},
sheets::{cell_string, SheetsClient},
Error,
};
Expand Down Expand Up @@ -96,7 +96,7 @@ fn trainees_from_sheet(
cell_string(&cells[2]).context("Failed to read trainee region")?,
),
github_login,
email: EmailAddress::from_str(&email)
email: new_case_insensitive_email_address(&email)
.with_context(|| format!("Failed to parse trainee email {}", email))?,
},
);
Expand Down
10 changes: 4 additions & 6 deletions src/google_groups.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
collections::{BTreeMap, BTreeSet},
str::FromStr,
};
use std::collections::{BTreeMap, BTreeSet};

use anyhow::Context;
use email_address::EmailAddress;
Expand All @@ -15,6 +12,7 @@ use tower_sessions::Session;

use crate::{
google_auth::{make_redirect_uri, redirect_endpoint, GoogleScope},
newtypes::new_case_insensitive_email_address,
Error, ServerState,
};

Expand Down Expand Up @@ -98,13 +96,13 @@ pub(crate) async fn get_groups(client: &Client) -> Result<GoogleGroups, Error> {
let members =
error_for_status(members.context("Failed to list Google group members")?)?;
Ok(GoogleGroup {
email: EmailAddress::from_str(&group.email).with_context(|| {
email: new_case_insensitive_email_address(&group.email).with_context(|| {
format!("Failed to parse group email address {}", group.email)
})?,
members: members
.into_iter()
.map(|Member { email, .. }| {
EmailAddress::from_str(&email).with_context(|| {
new_case_insensitive_email_address(&email).with_context(|| {
format!(
"Failed to parse group member email address {} (member of {})",
email, group.email
Expand Down
7 changes: 6 additions & 1 deletion src/newtypes.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use std::fmt::Display;
use std::{fmt::Display, str::FromStr};

use case_insensitive_string::CaseInsensitiveString;
use email_address::EmailAddress;
use serde::{Deserialize, Serialize};

pub fn new_case_insensitive_email_address(s: &str) -> Result<EmailAddress, email_address::Error> {
EmailAddress::from_str(&s.to_ascii_lowercase())
}

#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct GithubLogin(CaseInsensitiveString);
Expand Down
7 changes: 4 additions & 3 deletions src/register.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::str::FromStr;

use anyhow::Context;
use chrono::{DateTime, NaiveDate, Utc};
use email_address::EmailAddress;
Expand All @@ -8,6 +6,7 @@ use sheets::types::{CellData, GridData};
use tracing::warn;

use crate::{
newtypes::new_case_insensitive_email_address,
sheets::{cell_string, SheetsClient},
Error,
};
Expand Down Expand Up @@ -204,7 +203,9 @@ fn read_row(
&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 = EmailAddress::from_str(&cell_string(&cells[1]).context("Failed to read email")?)?;
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")?
Expand Down
Loading