From 36bdf18c1c1cfd2bfe1fef5f72137702e114be60 Mon Sep 17 00:00:00 2001 From: Josh Koenig Date: Thu, 4 Sep 2014 10:00:50 -0700 Subject: [PATCH 1/2] first bits of boilerplate --- terminus.drush.inc | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/terminus.drush.inc b/terminus.drush.inc index 419ea3c..c308e47 100644 --- a/terminus.drush.inc +++ b/terminus.drush.inc @@ -683,6 +683,34 @@ function terminus_drush_command() { 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, ); + $items['pantheon-site-upstream-info'] = array( + 'description' => 'Get available upstream update status for a site.', + 'arguments' => array( + 'site' => 'UUID of the site.', + ), + 'examples' => array( + 'drush psite-upstream-info SITE_UUID' => 'See if there are upstream udpates available.', + ), + 'aliases' => array('psite-upstream-info'), + 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, + ); + + $items['pantheon-site-upstream-update'] = array( + 'description' => 'Apply available upstream update status for a site.', + 'arguments' => array( + 'site' => 'UUID of the site.', + ), + 'options' => array( + 'overwrite' => 'Allow upstream changes to overwrite if there are conflicts.', + 'update' => 'Run update.php after deploying code.', + ), + 'examples' => array( + 'drush psite-upstream-info SITE_UUID --overwrite' => 'Apply available upstream updates .', + ), + 'aliases' => array('psite-upstream-update'), + 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, + ); + /** * Utility Functions. */ @@ -1220,6 +1248,35 @@ function drush_terminus_pantheon_site_clone($site_uuid, $env_source, $env_target } } +/** + * Apply upstream updates. + */ +function drush_terminus_pantheon_site_upstream_update_validate($site_uuid = FALSE) { + $session_data = terminus_bootstrap(); + if ($session_data === FALSE) { + return drush_set_error('DRUSH_PSITE_INFO_NO_SESSION', dt('You must authenticate before using this command.')); + } + + if (!$site_uuid = terminus_site_input($site_uuid, TRUE, TRUE)) { + return drush_set_error('DRUSH_PSITE_INFO_NO_UUID', dt('You must specify a valid site UUID.')); + } + drush_set_option('site_uuid', $site_uuid); +} + +/** + * Site info. + */ +function drush_terminus_pantheon_site_upstream_update() { + $site_uuid = drush_get_option('site_uuid'); + $result = terminus_api_site_info($site_uuid); + if (drush_get_option('json')) { + drush_print($result['json']); + } + else { + drush_print_r(json_decode($result['json'])); + } +} + /** * User data about self. */ From 9d40f5ded7c5985769e29bdb4dea67f6534bb098 Mon Sep 17 00:00:00 2001 From: Josh Koenig Date: Fri, 5 Sep 2014 11:35:37 -0700 Subject: [PATCH 2/2] working upstrea update commands --- terminus.drush.inc | 161 +++++++++++++++++++++++++++++++++++++----- terminus.site.api.inc | 28 ++++++++ 2 files changed, 172 insertions(+), 17 deletions(-) diff --git a/terminus.drush.inc b/terminus.drush.inc index c308e47..9f4ed99 100644 --- a/terminus.drush.inc +++ b/terminus.drush.inc @@ -684,7 +684,7 @@ function terminus_drush_command() { ); $items['pantheon-site-upstream-info'] = array( - 'description' => 'Get available upstream update status for a site.', + 'description' => 'Get the upstream info for a site.', 'arguments' => array( 'site' => 'UUID of the site.', ), @@ -695,19 +695,31 @@ function terminus_drush_command() { 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, ); - $items['pantheon-site-upstream-update'] = array( + $items['pantheon-site-upstream-updates'] = array( + 'description' => 'Get available upstream update status for a site.', + 'arguments' => array( + 'site' => 'UUID of the site.', + ), + 'examples' => array( + 'drush psite-upstream-updates SITE_UUID' => 'See if there are upstream udpates available.', + ), + 'aliases' => array('psite-upstream-updates'), + 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, + ); + + $items['pantheon-site-upstream-updates-apply'] = array( 'description' => 'Apply available upstream update status for a site.', 'arguments' => array( 'site' => 'UUID of the site.', ), 'options' => array( 'overwrite' => 'Allow upstream changes to overwrite if there are conflicts.', - 'update' => 'Run update.php after deploying code.', + 'updatedb' => 'Run a "drush updatedb" after deploying code.', ), 'examples' => array( - 'drush psite-upstream-info SITE_UUID --overwrite' => 'Apply available upstream updates .', + 'drush psite-upstream-updates-apply SITE_UUID --overwrite --updatedb' => 'Apply available upstream updates .', ), - 'aliases' => array('psite-upstream-update'), + 'aliases' => array('psite-upstream-updates-apply'), 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, ); @@ -1249,31 +1261,96 @@ function drush_terminus_pantheon_site_clone($site_uuid, $env_source, $env_target } /** - * Apply upstream updates. + * Upstream update info validate. */ -function drush_terminus_pantheon_site_upstream_update_validate($site_uuid = FALSE) { - $session_data = terminus_bootstrap(); - if ($session_data === FALSE) { - return drush_set_error('DRUSH_PSITE_INFO_NO_SESSION', dt('You must authenticate before using this command.')); +function drush_terminus_pantheon_site_upstream_info_validate($site_uuid = FALSE) { + return terminus_validate_session_data() && terminus_validate_site_uuid_input($site_uuid); +} + +/** + * Upstream update info. + */ +function drush_terminus_pantheon_site_upstream_info() { + $site_uuid = drush_get_option('site_uuid'); + $result = terminus_api_site_uptream_get($site_uuid); + if (drush_get_option('json')) { + drush_print($result['json']); } + else { + $upstream = json_decode($result['json']); + drush_print("Upstream: $upstream->url", 2); + drush_print("Branch: $upstream->branch", 2); + } +} - if (!$site_uuid = terminus_site_input($site_uuid, TRUE, TRUE)) { - return drush_set_error('DRUSH_PSITE_INFO_NO_UUID', dt('You must specify a valid site UUID.')); + +/** + * Upstream updates validate. + */ +function drush_terminus_pantheon_site_upstream_updates_validate($site_uuid = FALSE) { + return terminus_validate_session_data() && terminus_validate_site_uuid_input($site_uuid); +} + +/** + * Upstream updates available?. + */ +function drush_terminus_pantheon_site_upstream_updates() { + $site_uuid = drush_get_option('site_uuid'); + $result = terminus_api_site_uptream_updates_get($site_uuid); + if (drush_get_option('json')) { + drush_print($result['json']); + } + else { + $updates = json_decode($result['json']); + if ($updates->behind == 0) { + drush_log('No updates available. The dev env is up to date.', 'ok'); + } + else { + $rows = array(); + foreach ($updates->update_log as $commit => $info) { + $rows[] = array($info->email, $info->datetime, $info->message); + } + array_unshift($rows, array("Author", "Date", "Message")); + drush_log('Updates found', 'ok'); + drush_print_table($rows, TRUE); + } } - drush_set_option('site_uuid', $site_uuid); } /** - * Site info. + * Apply upstream updates validate. + */ +function drush_terminus_pantheon_site_upstream_updates_apply_validate($site_uuid = FALSE) { + return terminus_validate_session_data() && terminus_validate_site_uuid_input($site_uuid); +} + +/** + * Apply upstream updates. */ -function drush_terminus_pantheon_site_upstream_update() { +function drush_terminus_pantheon_site_upstream_updates_apply() { $site_uuid = drush_get_option('site_uuid'); - $result = terminus_api_site_info($site_uuid); + $updatedb = drush_get_option('updatedb') ? TRUE : FALSE; + $overwrite = drush_get_option('overwrite') ? TRUE : FALSE; + $result = terminus_api_site_uptream_updates_apply($site_uuid, $updatedb, $overwrite); if (drush_get_option('json')) { drush_print($result['json']); } else { - drush_print_r(json_decode($result['json'])); + drush_log('Applying upstream updates...', 'ok'); + $result = json_decode($result['json']); + if ($result->conflicts == '') { + drush_log('Success!', 'ok'); + } + else { + drush_log('Conflicts detected!', 'error'); + print_r($result->conflicts); + if (!$overwrite) { + drush_print("Try re-running with the --overwrite option to prioritize upstream updates and resolve these conflicts."); + } + else { + drush_print("We were not able to auto-resolve these. You will need to clone the repository, pull the updates, and resolve the conflicts manually."); + } + } } } @@ -4479,3 +4556,53 @@ function terminus_validate_sites($json) { function terminus_validate_hostname($hostname) { return preg_match('/(?=^.{1,254}$)(^(?:(?!\d|-)[a-z0-9\-]{1,63}(? $updatedb); + if ($overwrite) { + $data['xoption'] = 'theirs'; + } + + return terminus_request($realm, $uuid, $path, $method, $data); +} + /** * API Function to Get Site Attributes */