forked from dancryer/PHPCI
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dancryer#2 from Block8/master
update fork
- Loading branch information
Showing
53 changed files
with
1,038 additions
and
499 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace PHPCI\Helper; | ||
|
||
use b8\Cache; | ||
use b8\Config; | ||
use b8\HttpClient; | ||
|
||
class Github | ||
{ | ||
public function makeRequest($url, $params) | ||
{ | ||
$http = new HttpClient('https://api.github.com'); | ||
$res = $http->get($url, $params); | ||
|
||
return $res['body']; | ||
} | ||
|
||
/** | ||
* Get an array of repositories from Github's API. | ||
*/ | ||
public function getRepositories() | ||
{ | ||
$token = Config::getInstance()->get('phpci.github.token'); | ||
|
||
if (!$token) { | ||
die(json_encode(null)); | ||
} | ||
|
||
$cache = Cache::getCache(Cache::TYPE_APC); | ||
$rtn = $cache->get('phpci_github_repos'); | ||
|
||
if (!$rtn) { | ||
$orgs = $this->makeRequest('/user/orgs', array('access_token' => $token)); | ||
|
||
$params = array('type' => 'all', 'access_token' => $token); | ||
$repos = array(); | ||
$repos['user'] = $this->makeRequest('/user/repos', $params); | ||
|
||
|
||
foreach ($orgs as $org) { | ||
$repos[$org['login']] = $this->makeRequest('/orgs/'.$org['login'].'/repos', $params); | ||
} | ||
|
||
$rtn = array(); | ||
foreach ($repos as $repoGroup) { | ||
foreach ($repoGroup as $repo) { | ||
$rtn['repos'][] = $repo['full_name']; | ||
} | ||
} | ||
|
||
$cache->set('phpci_github_repos', $rtn); | ||
} | ||
|
||
return $rtn; | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace PHPCI\Helper; | ||
|
||
class SshKey | ||
{ | ||
public function generate() | ||
{ | ||
$tempPath = sys_get_temp_dir() . '/'; | ||
|
||
// FastCGI fix for Windows machines, where temp path is not available to | ||
// PHP, and defaults to the unwritable system directory. If the temp | ||
// path is pointing to the system directory, shift to the 'TEMP' | ||
// sub-folder, which should also exist, but actually be writable. | ||
if (IS_WIN && $tempPath == getenv("SystemRoot") . '/') { | ||
$tempPath = getenv("SystemRoot") . '/TEMP/'; | ||
} | ||
|
||
$keyFile = $tempPath . md5(microtime(true)); | ||
|
||
if (!is_dir($tempPath)) { | ||
mkdir($tempPath); | ||
} | ||
|
||
$return = array(); | ||
|
||
if ($this->canGenerateKeys()) { | ||
shell_exec('ssh-keygen -q -t rsa -b 2048 -f '.$keyFile.' -N "" -C "deploy@phpci"'); | ||
|
||
$pub = file_get_contents($keyFile . '.pub'); | ||
$prv = file_get_contents($keyFile); | ||
|
||
$return = array('private_key' => $prv, 'public_key' => $pub); | ||
} | ||
|
||
return $return; | ||
} | ||
|
||
public function canGenerateKeys() | ||
{ | ||
$keygen = @shell_exec('ssh-keygen'); | ||
$canGenerateKeys = !empty($keygen); | ||
|
||
return $canGenerateKeys; | ||
} | ||
} |
Oops, something went wrong.