Last active
August 29, 2015 14:17
-
-
Save j13k/4addfc987570acb82db2 to your computer and use it in GitHub Desktop.
This config script facilitates ini-file configuration of Sismo projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This config script facilitates INI-file configuration of | |
* Sismo (http://sismo.sensiolabs.org/) projects | |
* | |
* Installation: | |
* | |
* 1. Place this file in ~/.sismo/ (or SISMO_CONFIG_PATH) | |
* 2. Create projects.ini file in ~/.sismo (or SISMO_CONFIG_PATH), specifying | |
* one config per project | |
* | |
* Sample config section: | |
* | |
* [project1] | |
* type = github | |
* name = Twig | |
* repository = twigphp/Twig | |
* branch = master | |
* commands[] = "if [ -f composer.json ]; then composer install; fi" | |
* commands[] = "phpunit" | |
* urlPattern = https://github.com/twigphp/Twig/commit/%commit% | |
* | |
* - This sample config is available as a gist: | |
* https://gist.github.com/j13k/935648483c08a462565f | |
* - Some properties here are redundant in github project configs (e.g. branch and | |
* urlPattern have sensible defaults in Sismo) but included here for clarity | |
* - commands[] params are shell command lines, joined and executed as the | |
* Sismo build command | |
* | |
* TODO Support for notifications | |
* TODO Test Bitbucket and other project types | |
*/ | |
$projects = []; | |
// Loop over INI config sections, creating a Sismo project from each | |
$projectConfigs = parse_ini_file( | |
dirname($app['config.file']).'/projects.ini', | |
true | |
); | |
foreach ($projectConfigs as $i => $projectConfig) { | |
// New project object based on 'type' param [github|bitbucket|default] | |
switch ($projectConfig['type']) { | |
case 'github': | |
$projects[$i] = new Sismo\GithubProject($projectConfig['name']); | |
break; | |
case 'bitbucket': | |
$project[$i] = new Sismo\BitbucketProject($projectConfig['name']); | |
break; | |
case 'default': | |
default: | |
$projects[$i] = new Sismo\Project($projectConfig['name']); | |
} | |
// Set all remaining properties (skip 'type' and 'name') | |
foreach ($projectConfig as $key => $val) { | |
switch ($key) { | |
case 'type': | |
case 'name': | |
// skip - do nothing | |
break; | |
case 'commands': | |
$command = join(' && ', $projectConfig['commands']); | |
$projects[$i]->setCommand($command); | |
break; | |
default: | |
$projects[$i]->{'set'.ucfirst($key)}($val); | |
} | |
} | |
} | |
return $projects; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment