64 lines
1.6 KiB
PHP
Executable File
64 lines
1.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace api\core;
|
|
|
|
use \manager\ManagerError;
|
|
|
|
|
|
class release{
|
|
|
|
/* PULLS A BRANCH FROM GIT
|
|
*
|
|
* @project<String> Project's name
|
|
* @branch<String> Git branch
|
|
*
|
|
*/
|
|
public static function pull($args){
|
|
extract($args);
|
|
|
|
/* [1] Load projects' configuration
|
|
=========================================================*/
|
|
/* (1) Fetch file */
|
|
$fc = file_get_contents(__CONFIG__.'/projects.json');
|
|
if( !$fc )
|
|
return ['ModuleError'=>ManagerError::UnreachableResource];
|
|
|
|
/* (2) Checks json format */
|
|
$js = json_decode( $fc, true );
|
|
|
|
if( !$js )
|
|
return ['ModuleError'=>ManagerError::ParsingFailed];
|
|
|
|
|
|
/* [2] Checks @project argument and files
|
|
=========================================================*/
|
|
/* (1) Checks @project */
|
|
if( !isset($js[$project]) )
|
|
return ['ModuleError'=>ManagerError::UnreachableResource];
|
|
|
|
/* (2) Checks @project's folder */
|
|
if( !is_dir($js[$project]['git']) )
|
|
return ['ModuleError'=>ManagerError::UnreachableResource];
|
|
|
|
/* (3) Checks @git directory */
|
|
if( !is_dir($js[$project]['git'].'/.git') )
|
|
return ['ModuleError'=>ManagerError::UnreachableResource];
|
|
|
|
|
|
/* [3] Launch script
|
|
=========================================================*/
|
|
/* (1) Launch command + test */
|
|
$stdout = shell_exec('cd '.$js[$project]['git'].'; git pull origin '.$branch.';');
|
|
|
|
/* (2) If error, raise error */
|
|
if( is_null($stdout) )
|
|
return ['ModuleError'=>ManagerError::PermissionError];
|
|
|
|
|
|
/* [4] Return success error
|
|
=========================================================*/
|
|
return [];
|
|
}
|
|
|
|
}
|