start of sub commands
@@ -14,6 +14,7 @@ extern crate serde_json;
use std::env;
use anyhow::Result;
+use cio_api::{companies::Companys, db::Database};
use clap::{AppSettings, Clap};
use sentry::IntoDsn;
use slog::Drain;
@@ -35,6 +36,8 @@ struct Opts {
#[derive(Clap)]
enum SubCommand {
Server(Server),
+
+ SyncRepos(SyncRepos),
}
/// A subcommand for running the server.
@@ -49,6 +52,10 @@ pub struct Server {
spec_file: Option<std::path::PathBuf>,
}
+/// A subcommand for running the background job of syncing repos.
+#[derive(Clap)]
+pub struct SyncRepos {}
+
#[tokio::main]
async fn main() -> Result<()> {
let opts: Opts = Opts::parse();
@@ -93,6 +100,17 @@ async fn main() -> Result<()> {
SubCommand::Server(s) => {
crate::server::server(&s, logger).await?;
}
+ SubCommand::SyncRepos(_) => {
+ let db = Database::new();
+ let companies = Companys::get_from_db(&db, 1)?;
+
+ // Iterate over the companies and update.
+ for company in companies {
+ let github = company.authenticate_github().unwrap();
+ cio_api::repos::sync_all_repo_settings(&db, &github, &company).await?;
+ cio_api::repos::refresh_db_github_repos(&db, &github, &company).await?;
+ }
+ }
}
Ok(())
