diff --git a/README.md b/README.md index 95d5598..91d3b4c 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,28 @@ Version: 3 Status: succeeded ``` +**~rollback_app** + +If you would like to rollback your app to the code associated with a previous release of your app, you can do so with the ~rollback_app command. + +``` +you: ~rollback_app testing-nell-bot version-to-rollback-to +``` + +``` +you: ~rollback_app testing-nell-bot v5 + +crates-io-bot: @you App testing-nell-bot was successfully rolled back to the code at v5 +``` + +You can either specify the version with a "v" before the version number or with just the number. This command will also work. + +``` +you: ~rollback_app testing-nell-bot 5 + +crates-io-bot: @you App testing-nell-bot was successfully rolled back to the code at 5 +``` + **~scale_app** You can scale formations of dynos within your application through the ~scale_app command. diff --git a/src/commands/heroku.rs b/src/commands/heroku.rs index 4fed568..26ce77b 100644 --- a/src/commands/heroku.rs +++ b/src/commands/heroku.rs @@ -169,6 +169,38 @@ pub fn get_app_releases(ctx: &mut Context, msg: &Message, mut args: Args) -> Com Ok(()) } +#[command] +#[num_args(2)] +pub fn rollback_app(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult { + let app_name = args + .single::() + .expect("You must include an app name"); + + let version_to_rollback_to = args + .single::() + .expect("You must include the version to roll back to"); + + let response = heroku_client(ctx).request(&releases::ReleaseRollback { + app_id: app_name.clone(), + params: releases::ReleaseRollbackParams { + release: version_to_rollback_to.clone(), + }, + }); + + msg.reply( + ctx, + match response { + Ok(_response) => format!( + "App {} was successfully rolled back to the code at {}", + app_name, version_to_rollback_to + ), + Err(e) => format!("An error occured when trying to roll back your app:\n{}", e), + }, + )?; + + Ok(()) +} + #[command] pub fn get_apps(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult { let response = heroku_client(ctx).request(&apps::AppList {}); diff --git a/src/lib.rs b/src/lib.rs index 0ee2ecb..1bb92ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,7 +29,8 @@ use crate::authorizations::users::*; restart_app, scale_app, update_app_config, - get_app_releases + get_app_releases, + rollback_app )] struct General;