Skip to content

Commit fbf9b7e

Browse files
committed
Merge pull request #412 from pantheon-systems/site_workflows
Added `site workflows`, removed `site jobs` and `site notifications`
2 parents 6b88af9 + 8ddc55b commit fbf9b7e

File tree

9 files changed

+356
-100
lines changed

9 files changed

+356
-100
lines changed

CHANGELOG.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ All notable changes to this project starting with the 0.6.0 release will be docu
1212
- `site delete-env` now has an optional --remove-branch flag (#395)
1313
- Environment variables for --site (TERMINUS_SITE), --org (TERMINUS_ORG), --env (TERMINUS_ENV), and user (TERMINUS_USER). User may import these themselves, or add them to the .env file in the user's current directory. (#407)
1414
- `site tags <add|remove> --site=<site> --org=<org> --tag=<tag>` command will add tags to an organization site (#417)
15+
- `site workflows` commmand will show all workflows run on the site and their statuses (replaces `site jobs` and `site notifications`) (#412)
1516

1617
### Fixed
1718
- `organizations sites` shows all the organization's sites, not just the first 100 (#371)
@@ -28,6 +29,8 @@ All notable changes to this project starting with the 0.6.0 release will be docu
2829

2930
### Deprecated
3031
- `sites delete` will be removed in v1.0.0 (#370)
32+
- `site jobs` will be removed in v0.7.0 (#412)
33+
- `site notifications` will be removed in v0.7.0 (#412)
3134

3235
##[0.6.1] - 2015-08-11
3336
### Fixed

php/Terminus/Collections/Workflows.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ public function create($type, $options = array()) {
5959
return $model;
6060
}
6161

62+
public function fetchPaged() {
63+
$results = TerminusCommand::paged_request($this->url());
64+
65+
foreach ($results['data'] as $model_data) {
66+
$model = new Workflow($model_data, array(
67+
'owner' => $this->owner,
68+
'owner_type' => $this->owner_type,
69+
));
70+
$this->add($model);
71+
}
72+
73+
return $this;
74+
}
75+
6276
public function fetch() {
6377
$results = TerminusCommand::simple_request($this->url());
6478

php/Terminus/Models/Workflow.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,12 @@ public function logMessages() {
7373
\Terminus::error(sprintf('[%s] %s', $message->level, $message->message));
7474
}
7575
}
76+
77+
public function get($attribute) {
78+
if(isset($this->attributes->$attribute)) {
79+
return $this->attributes->$attribute;
80+
}
81+
return null;
82+
}
83+
7684
}

php/Terminus/Site.php

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class Site {
1919
public $environments = array();
2020
public $environmentsCollection;
2121
public $information;
22-
public $jobs;
2322
public $metadata;
2423
public $workflows;
2524

@@ -258,17 +257,6 @@ public function createBranch($branch) {
258257
return $response['data'];
259258
}
260259

261-
/**
262-
* fetch jobs
263-
**/
264-
public function jobs() {
265-
if (!$this->jobs) {
266-
$response = \TerminusCommand::request('sites', $this->getId(), 'jobs', 'GET');
267-
$this->jobs = $response['data'];
268-
}
269-
return $this->jobs;
270-
}
271-
272260
/**
273261
* Retrieve New Relic Info
274262
*/
@@ -278,16 +266,6 @@ public function newRelic() {
278266
return $response['data'];
279267
}
280268

281-
/**
282-
* fetch notifications
283-
**/
284-
public function notifications() {
285-
$path = 'notifications';
286-
$data = \TerminusCommand::request('sites', $this->getId(), $path, 'GET');
287-
return $data['data'];
288-
}
289-
290-
291269
/**
292270
* Import Archive
293271
*/
@@ -548,6 +526,7 @@ public function get($attribute) {
548526
}
549527

550528
/**
529+
<<<<<<< HEAD
551530
* Returns tags from the site/org join
552531
*
553532
* @return [array] $tags Tags in string format
@@ -584,4 +563,14 @@ public function getOrganizations() {
584563
$orgs = $this->org_memberships->fetch()->all();
585564
return $orgs;
586565
}
566+
567+
/**
568+
* Retrieves a list of workflows run and running on this site
569+
*
570+
* @return [array] $workflows An array of Workflow objects
571+
*/
572+
public function getWorkflows() {
573+
$workflows = $this->workflows->fetchPaged()->all();
574+
return $workflows;
575+
}
587576
}

php/class-terminus-command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ protected function waitOnWorkflow($object_name, $object_id, $workflow_id) {
351351
}
352352
} else {
353353
Terminus::error(
354-
PHP_EOL . "Couldn't complete jobs: '$type'" . PHP_EOL
354+
PHP_EOL . "Couldn't complete workflows: '$type'" . PHP_EOL
355355
);
356356
}
357357
}

php/commands/site.php

Lines changed: 63 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,33 @@ public function dashboard($args, $assoc_args) {
246246
}
247247
}
248248

249+
/**
250+
* Delete a site from pantheon
251+
*
252+
* ## OPTIONS
253+
* [--site=<site>]
254+
* : ID of the site you want to delete
255+
*
256+
* [--force]
257+
* : to skip the confirmations
258+
*/
259+
public function delete($args, $assoc_args) {
260+
$sitename = Input::sitename($assoc_args);
261+
$site_id = $this->sitesCache->findID($sitename);
262+
$site_to_delete = new Site($site_id);
263+
264+
if (!isset($assoc_args['force']) AND !Terminus::get_config('yes')) {
265+
// if the force option isn't used we'll ask you some annoying questions
266+
Terminus::confirm( sprintf( "Are you sure you want to delete %s?", $site_to_delete->information->name ));
267+
Terminus::confirm( "Are you really sure?" );
268+
}
269+
Terminus::line( sprintf( "Deleting %s ...", $site_to_delete->information->name ) );
270+
$response = \TerminusCommand::request( 'sites', $site_to_delete->id, '', 'DELETE' );
271+
272+
$this->sitesCache->remove($sitename);
273+
Terminus::success("Deleted %s!", $sitename);
274+
}
275+
249276
/**
250277
* Retrieve information about the site
251278
*
@@ -1193,30 +1220,6 @@ public function instrument($args, $assoc_args) {
11931220
}
11941221
}
11951222

1196-
/**
1197-
* List a site's job history
1198-
*
1199-
* ## OPTIONS
1200-
*
1201-
* [--site=<site>]
1202-
* : Site to deploy from
1203-
**/
1204-
public function jobs($args, $assoc_args) {
1205-
$site = SiteFactory::instance(Input::sitename($assoc_args));
1206-
$jobs = $site->jobs();
1207-
$data = array();
1208-
foreach ($jobs as $job) {
1209-
$data[] = array(
1210-
'slot' => $job->slot,
1211-
'name' => $job->human_name,
1212-
'env' => @$job->environment,
1213-
'status' => $job->status,
1214-
'updated' => $job->changed
1215-
);
1216-
}
1217-
$this->handleDisplay($data,$args);
1218-
}
1219-
12201223
/**
12211224
* Mount a site with sshfs
12221225
*
@@ -1283,32 +1286,6 @@ public function new_relic($args, $assoc_args) {
12831286
}
12841287
}
12851288

1286-
/**
1287-
* Open the Pantheon site dashboard a browser
1288-
*
1289-
* ## OPTIONS
1290-
*
1291-
* [--site=<site>]
1292-
* : site for which to retreive notifications
1293-
*
1294-
*/
1295-
public function notifications($args, $assoc_args) {
1296-
$site = SiteFactory::instance(Input::sitename($assoc_args));
1297-
$notifications = $site->notifications();
1298-
$data = array();
1299-
foreach ($notifications as $note) {
1300-
$data[] = array(
1301-
'time' => $note->start,
1302-
'name' => $note->name,
1303-
'id' => $note->build->number."@".$note->build->environment->HOSTNAME,
1304-
'status'=> $note->build->status,
1305-
'phase' => $note->build->phase,
1306-
'duration' => $note->build->estimated_duration,
1307-
);
1308-
}
1309-
$this->handleDisplay($data);
1310-
}
1311-
13121289
/**
13131290
* Get or set owner
13141291
*
@@ -1683,32 +1660,42 @@ public function wipe($args, $assoc_args) {
16831660
Terminus::success(sprintf("Successfully wiped %s - %s", $site->getName(), $environment_id));
16841661
}
16851662

1686-
/**
1687-
* Delete a site from pantheon
1688-
*
1689-
* ## OPTIONS
1690-
* [--site=<site>]
1691-
* : ID of the site you want to delete
1692-
*
1693-
* [--force]
1694-
* : to skip the confirmations
1695-
*/
1696-
function delete($args, $assoc_args) {
1697-
$sitename = Input::sitename($assoc_args);
1698-
$site_id = $this->sitesCache->findID($sitename);
1699-
$site_to_delete = new Site($site_id);
1700-
1701-
if (!isset($assoc_args['force']) AND !Terminus::get_config('yes')) {
1702-
// if the force option isn't used we'll ask you some annoying questions
1703-
Terminus::confirm( sprintf( "Are you sure you want to delete %s?", $site_to_delete->information->name ));
1704-
Terminus::confirm( "Are you really sure?" );
1705-
}
1706-
Terminus::line( sprintf( "Deleting %s ...", $site_to_delete->information->name ) );
1707-
$response = \TerminusCommand::request( 'sites', $site_to_delete->id, '', 'DELETE' );
1708-
1709-
$this->sitesCache->remove($sitename);
1710-
Terminus::success("Deleted %s!", $sitename);
1711-
}
1663+
/**
1664+
* List a site's workflows
1665+
*
1666+
* ## OPTIONS
1667+
* [--site=<site>]
1668+
* : Site to check
1669+
*
1670+
* @subcommand workflows
1671+
*/
1672+
public function workflows($args, $assoc_args) {
1673+
$site = SiteFactory::instance(Input::sitename($assoc_args));
1674+
$workflows = $site->getWorkflows();
1675+
$data = array();
1676+
foreach($workflows as $workflow) {
1677+
$user = 'Pantheon';
1678+
if (isset($workflow->get('user')->email)) {
1679+
$user = $workflow->get('user')->email;
1680+
}
1681+
$data[] = array(
1682+
'workflow' => $workflow->get('description'),
1683+
'user' => $user,
1684+
'status' => $workflow->get('phase'),
1685+
'last_update' => date(
1686+
'Y-m-dTH:i:s',
1687+
($workflow->get('created_at') + $workflow->get('total_time'))
1688+
),
1689+
'tasks/complete' =>
1690+
$workflow->get('step') . '/' . $workflow->get('number_of_tasks'),
1691+
);
1692+
}
1693+
if (count($data) > 0) {
1694+
$this->constructTableForResponse($data);
1695+
} else {
1696+
Terminus::error('No workflows have been run on ' . $site->getName());
1697+
}
1698+
}
17121699
}
17131700

17141701
\Terminus::add_command( 'site', 'Site_Command' );

tests/features/site.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,13 @@ Feature: site
1919
"""
2020
Git
2121
"""
22+
23+
Scenario: Site Workflows
24+
@vcr site-workflows
25+
Given I am authenticated
26+
And a site named "[[test_site_name]]"
27+
When I run "terminus site workflows --site=[[test_site_name]]"
28+
Then I should get:
29+
"""
30+
Converge "dev"
31+
"""

0 commit comments

Comments
 (0)