fn create_or_update_github_team(
        app: &App,
        conn: &PgConnection,
        login: &str,
        org_name: &str,
        team_name: &str,
        req_user: &User,
    ) -> AppResult<Self> {
        // GET orgs/:org/teams
        // check that `team` is the `slug` in results, and grab its data

        // "sanitization"
        fn whitelist(c: char) -> bool {
            match c {
                'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_' => false,
                _ => true,
            }
        }

        if let Some(c) = org_name.chars().find(|c| whitelist(*c)) {
            return Err(cargo_err(&format_args!(
                "organization cannot contain special \
                 characters like {}",
                c
            )));
        }

        #[derive(Deserialize)]
        struct GithubTeam {
            id: i32,              // unique GH id (needed for membership queries)
            name: Option<String>, // Pretty name
        }

        let url = format!("/orgs/{}/teams/{}", org_name, team_name);
        let token = AccessToken::new(req_user.gh_access_token.clone());
        let team = github_api::<GithubTeam>(app, &url, &token).map_err(|_| {
            cargo_err(&format_args!(
                "could not find the github team {}/{}",
                org_name, team_name
            ))
        })?;

        if !team_with_gh_id_contains_user(app, team.id, req_user)? {
            return Err(cargo_err("only members of a team can add it as an owner"));
        }

        #[derive(Deserialize)]
        struct Org {
            avatar_url: Option<String>,
        }

        let url = format!("/orgs/{}", org_name);
        let org = github_api::<Org>(app, &url, &token)?;

        NewTeam::new(&login.to_lowercase(), team.id, team.name, org.avatar_url)
            .create_or_update(conn)
            .map_err(Into::into)
    }
/// Tries to create or update a Github Team. Assumes `org` and `team` are
/// correctly parsed out of the full `name`. `name` is passed as a
/// convenience to avoid rebuilding it.
Tries to create or update a Github Team.
Tries to create or update a Github Team .
fn create_or_update_github_team(
        app: &App,
        conn: &PgConnection,
        login: &str,
        org_name: &str,
        team_name: &str,
        req_user: &User,
    ) -> AppResult<Self> {
        // GET orgs/:org/teams
        // check that `team` is the `slug` in results, and grab its data
        // "sanitization"
        fn whitelist(c: char) -> bool {
            match c {
                'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_' => false,
                _ => true,
            }
        }
        if let Some(c) = org_name.chars().find(|c| whitelist(*c)) {
            return Err(cargo_err(&format_args!(
                "organization cannot contain special \
                 characters like {}",
                c
            )));
        }
        #[derive(Deserialize)]
        struct GithubTeam {
            id: i32,              // unique GH id (needed for membership queries)
            name: Option<String>, // Pretty name
        }
        let url = format!("/orgs/{}/teams/{}", org_name, team_name);
        let token = AccessToken::new(req_user.gh_access_token.clone());
        let team = github_api::<GithubTeam>(app, &url, &token).map_err(|_| {
            cargo_err(&format_args!(
                "could not find the github team {}/{}",
                org_name, team_name
            ))
        })?;
        if !team_with_gh_id_contains_user(app, team.id, req_user)? {
            return Err(cargo_err("only members of a team can add it as an owner"));
        }
        #[derive(Deserialize)]
        struct Org {
            avatar_url: Option<String>,
        }
        let url = format!("/orgs/{}", org_name);
        let org = github_api::<Org>(app, &url, &token)?;
        NewTeam::new(&login.to_lowercase(), team.id, team.name, org.avatar_url)
            .create_or_update(conn)
            .map_err(Into::into)
    }
fn create_or_update_github_team ( app : & App , conn : & PgConnection , login : & str , org_name : & str , team_name : & str , req_user : & User , ) -> AppResult < Self > { // GET orgs/:org/teams // check that `team` is the `slug` in results, and grab its data // "sanitization" fn whitelist ( c : char ) -> bool { match c { 'a' ..= 'z' | 'A' ..= 'Z' | '0' ..= '9' | '-' | '_' => false , _ => true , } } if let Some ( c ) = org_name . chars ( ) . find ( | c | whitelist ( * c ) ) { return Err ( cargo_err ( & format_args ! ( " \
 " c ) ) ) ; } # [ derive ( Deserialize ) ] struct GithubTeam { id : i32 , // unique GH id (needed for membership queries) name : Option < String > , // Pretty name } let url = format ! ( " " org_name team_name ) ; let token = AccessToken :: new ( req_user . gh_access_token . clone ( ) ) ; let team = github_api :: < GithubTeam > ( app , & url , & token ) . map_err ( | _ | { cargo_err ( & format_args ! ( " " org_name team_name ) ) } ) ? ; if ! team_with_gh_id_contains_user ( app , team . id , req_user ) ? { return Err ( cargo_err ( " " ) ) ; } # [ derive ( Deserialize ) ] struct Org { avatar_url : Option < String > , } let url = format ! ( " " org_name ) ; let org = github_api :: < Org > ( app , & url , & token ) ? ; NewTeam :: new ( & login . to_lowercase ( ) , team . id , team . name , org . avatar_url ) . create_or_update ( conn ) . map_err ( Into :: into ) }
Tries to create or update a Github Team.
Tries to create or update a Github Team .
app
&App
conn
&PgConnection
login
&str
org_name
&str
team_name
&str
req_user
&User