async fn handle_configs_push(api_context: &Context, event: GitHubWebhook) -> Result<HttpResponseAccepted<String>, HttpError> {
    // Get the repo.
    let github_repo = api_context.github.repo(api_context.github_org.to_string(), event.repository.name.to_string());

    // Get the commit.
    let mut commit = event.commits.get(0).unwrap().clone();

    // Ignore any changes that are not to the `configs/` directory.
    let dir = "configs/";
    commit.filter_files_by_path(dir);
    if !commit.has_changed_files() {
        // No files changed that we care about.
        // We can throw this out, log it and return early.
        println!("`push` event commit `{}` does not include any changes to the `{}` directory", commit.id, dir);
        return Ok(HttpResponseAccepted("ok".to_string()));
    }

    // Get the branch name.
    let branch = event.refv.trim_start_matches("refs/heads/");
    // Make sure this is to the default branch, we don't care about anything else.
    if branch != event.repository.default_branch {
        // We can throw this out, log it and return early.
        return Ok(HttpResponseAccepted("ok".to_string()));
    }

    // Get the configs from our repo.
    let configs = get_configs_from_repo(&api_context.github).await;

    // Check if the links.toml file changed.
    if commit.file_changed("configs/links.toml") || commit.file_changed("configs/huddles.toml") {
        // Update our links in the database.
        sync_links(&api_context.db, configs.links, configs.huddles).await;

        // We need to update the short URLs for the links.
        generate_shorturls_for_configs_links(&api_context.db, &github_repo).await;
        println!("generated shorturls for the configs links");
    }

    // Check if the groups.toml file changed.
    // IMPORTANT: we need to sync the groups _before_ we sync the users in case we
    // added a new group to GSuite.
    if commit.file_changed("configs/groups.toml") {
        sync_groups(&api_context.db, configs.groups).await;
    }

    // Check if the users.toml file changed.
    if commit.file_changed("configs/users.toml") {
        sync_users(&api_context.db, &api_context.github, configs.users).await;
    }

    if commit.file_changed("configs/users.toml") || commit.file_changed("configs/groups.toml") {
        // Sync okta users and group from the database.
        // Do this after we update the users and groups in the database.
        generate_terraform_files_for_okta(&api_context.github, &api_context.db).await;
    }

    // Check if the buildings.toml file changed.
    // Buildings needs to be synchronized _before_ we move on to conference rooms.
    if commit.file_changed("configs/buildings.toml") {
        sync_buildings(&api_context.db, configs.buildings).await;
    }

    // Check if the resources.toml file changed.
    if commit.file_changed("configs/resources.toml") {
        sync_conference_rooms(&api_context.db, configs.resources).await;
    }

    // Check if the certificates.toml file changed.
    if commit.file_changed("configs/certificates.toml") {
        sync_certificates(&api_context.db, &api_context.github, configs.certificates).await;
    }

    // Check if the github-outside-collaborators.toml file changed.
    if commit.file_changed("configs/github-outside-collaborators.toml") {
        // Sync github outside collaborators.
        sync_github_outside_collaborators(&api_context.github, configs.github_outside_collaborators).await;
    }

    // TODO: do huddles, labels, etc.

    Ok(HttpResponseAccepted("ok".to_string()))
}
/// Handle a `push` event for the configs repo.
Handle a `push` event for the configs repo.
Handle a ` push ` event for the configs repo .
async fn handle_configs_push(api_context: &Context, event: GitHubWebhook) -> Result<HttpResponseAccepted<String>, HttpError> {
    // Get the repo.
    let github_repo = api_context.github.repo(api_context.github_org.to_string(), event.repository.name.to_string());
    // Get the commit.
    let mut commit = event.commits.get(0).unwrap().clone();
    // Ignore any changes that are not to the `configs/` directory.
    let dir = "configs/";
    commit.filter_files_by_path(dir);
    if !commit.has_changed_files() {
        // No files changed that we care about.
        // We can throw this out, log it and return early.
        println!("`push` event commit `{}` does not include any changes to the `{}` directory", commit.id, dir);
        return Ok(HttpResponseAccepted("ok".to_string()));
    }
    // Get the branch name.
    let branch = event.refv.trim_start_matches("refs/heads/");
    // Make sure this is to the default branch, we don't care about anything else.
    if branch != event.repository.default_branch {
        // We can throw this out, log it and return early.
        return Ok(HttpResponseAccepted("ok".to_string()));
    }
    // Get the configs from our repo.
    let configs = get_configs_from_repo(&api_context.github).await;
    // Check if the links.toml file changed.
    if commit.file_changed("configs/links.toml") || commit.file_changed("configs/huddles.toml") {
        // Update our links in the database.
        sync_links(&api_context.db, configs.links, configs.huddles).await;
        // We need to update the short URLs for the links.
        generate_shorturls_for_configs_links(&api_context.db, &github_repo).await;
        println!("generated shorturls for the configs links");
    }
    // Check if the groups.toml file changed.
    // IMPORTANT: we need to sync the groups _before_ we sync the users in case we
    // added a new group to GSuite.
    if commit.file_changed("configs/groups.toml") {
        sync_groups(&api_context.db, configs.groups).await;
    }
    // Check if the users.toml file changed.
    if commit.file_changed("configs/users.toml") {
        sync_users(&api_context.db, &api_context.github, configs.users).await;
    }
    if commit.file_changed("configs/users.toml") || commit.file_changed("configs/groups.toml") {
        // Sync okta users and group from the database.
        // Do this after we update the users and groups in the database.
        generate_terraform_files_for_okta(&api_context.github, &api_context.db).await;
    }
    // Check if the buildings.toml file changed.
    // Buildings needs to be synchronized _before_ we move on to conference rooms.
    if commit.file_changed("configs/buildings.toml") {
        sync_buildings(&api_context.db, configs.buildings).await;
    }
    // Check if the resources.toml file changed.
    if commit.file_changed("configs/resources.toml") {
        sync_conference_rooms(&api_context.db, configs.resources).await;
    }
    // Check if the certificates.toml file changed.
    if commit.file_changed("configs/certificates.toml") {
        sync_certificates(&api_context.db, &api_context.github, configs.certificates).await;
    }
    // Check if the github-outside-collaborators.toml file changed.
    if commit.file_changed("configs/github-outside-collaborators.toml") {
        // Sync github outside collaborators.
        sync_github_outside_collaborators(&api_context.github, configs.github_outside_collaborators).await;
    }
    // TODO: do huddles, labels, etc.
    Ok(HttpResponseAccepted("ok".to_string()))
}
async fn handle_configs_push ( api_context : & Context , event : GitHubWebhook ) -> Result < HttpResponseAccepted < String > , HttpError > { // Get the repo. let github_repo = api_context . github . repo ( api_context . github_org . to_string ( ) , event . repository . name . to_string ( ) ) ; // Get the commit. let mut commit = event . commits . get ( 0 ) . unwrap ( ) . clone ( ) ; // Ignore any changes that are not to the `configs/` directory. let dir = " " ; commit . filter_files_by_path ( dir ) ; if ! commit . has_changed_files ( ) { // No files changed that we care about. // We can throw this out, log it and return early. println ! ( " " commit id dir ) ; return Ok ( HttpResponseAccepted ( " " . to_string ( ) ) ) ; } // Get the branch name. let branch = event . refv . trim_start_matches ( " " ) ; // Make sure this is to the default branch, we don't care about anything else. if branch != event . repository . default_branch { // We can throw this out, log it and return early. return Ok ( HttpResponseAccepted ( " " . to_string ( ) ) ) ; } // Get the configs from our repo. let configs = get_configs_from_repo ( & api_context . github ) . await ; // Check if the links.toml file changed. if commit . file_changed ( " " ) || commit . file_changed ( " " ) { // Update our links in the database. sync_links ( & api_context . db , configs . links , configs . huddles ) . await ; // We need to update the short URLs for the links. generate_shorturls_for_configs_links ( & api_context . db , & github_repo ) . await ; println ! ( " " ) ; } // Check if the groups.toml file changed. // IMPORTANT: we need to sync the groups _before_ we sync the users in case we // added a new group to GSuite. if commit . file_changed ( " " ) { sync_groups ( & api_context . db , configs . groups ) . await ; } // Check if the users.toml file changed. if commit . file_changed ( " " ) { sync_users ( & api_context . db , & api_context . github , configs . users ) . await ; } if commit . file_changed ( " " ) || commit . file_changed ( " " ) { // Sync okta users and group from the database. // Do this after we update the users and groups in the database. generate_terraform_files_for_okta ( & api_context . github , & api_context . db ) . await ; } // Check if the buildings.toml file changed. // Buildings needs to be synchronized _before_ we move on to conference rooms. if commit . file_changed ( " " ) { sync_buildings ( & api_context . db , configs . buildings ) . await ; } // Check if the resources.toml file changed. if commit . file_changed ( " " ) { sync_conference_rooms ( & api_context . db , configs . resources ) . await ; } // Check if the certificates.toml file changed. if commit . file_changed ( " " ) { sync_certificates ( & api_context . db , & api_context . github , configs . certificates ) . await ; } // Check if the github-outside-collaborators.toml file changed. if commit . file_changed ( " " ) { // Sync github outside collaborators. sync_github_outside_collaborators ( & api_context . github , configs . github_outside_collaborators ) . await ; } // TODO: do huddles, labels, etc. Ok ( HttpResponseAccepted ( " " . to_string ( ) ) ) }
Handle a `push` event for the configs repo.
Handle a ` push ` event for the configs repo .
api_context
&Context
event
GitHubWebhook
api_context
&Context
event
GitHubWebhook