Adding / SVG support build status
This commit is contained in:
parent
3378945d9c
commit
d8e1a9d364
|
@ -37,31 +37,56 @@ class BuildStatusController extends \PHPCI\Controller
|
|||
$this->projectStore = Store\Factory::getStore('Project');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns status of the last build
|
||||
* @param $projectId
|
||||
* @return string
|
||||
*/
|
||||
protected function _getStatus($projectId)
|
||||
{
|
||||
$branch = $this->getParam('branch', 'master');
|
||||
try {
|
||||
$project = $this->projectStore->getById($projectId);
|
||||
$status = 'passing';
|
||||
|
||||
if (!$project->getAllowPublicStatus()) {
|
||||
die();
|
||||
}
|
||||
|
||||
if (isset($project) && $project instanceof Project) {
|
||||
$build = $project->getLatestBuild($branch, array(2,3));
|
||||
|
||||
if (isset($build) && $build instanceof Build && $build->getStatus() != 2) {
|
||||
$status = 'failed';
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$status = 'error';
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the appropriate build status image for a given project.
|
||||
*/
|
||||
public function image($projectId)
|
||||
{
|
||||
$branch = $this->getParam('branch', 'master');
|
||||
$project = $this->projectStore->getById($projectId);
|
||||
$status = 'ok';
|
||||
|
||||
if (!$project->getAllowPublicStatus()) {
|
||||
die();
|
||||
}
|
||||
|
||||
if (isset($project) && $project instanceof Project) {
|
||||
$build = $project->getLatestBuild($branch, array(2,3));
|
||||
|
||||
if (isset($build) && $build instanceof Build && $build->getStatus() != 2) {
|
||||
$status = 'failed';
|
||||
}
|
||||
}
|
||||
|
||||
$status = $this->_getStatus($projectId);
|
||||
header('Content-Type: image/png');
|
||||
die(file_get_contents(APPLICATION_PATH . 'public/assets/img/build-' . $status . '.png'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the appropriate build status image in SVG format for a given project.
|
||||
*/
|
||||
public function svg($projectId)
|
||||
{
|
||||
$status = $this->_getStatus($projectId);
|
||||
header('Content-Type: image/svg+xml');
|
||||
die(file_get_contents(APPLICATION_PATH . 'public/assets/img/build-' . $status . '.svg'));
|
||||
}
|
||||
|
||||
public function view($projectId)
|
||||
{
|
||||
$project = $this->projectStore->getById($projectId);
|
||||
|
|
1
public/assets/img/build-error.svg
Normal file
1
public/assets/img/build-error.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="76" height="18"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-opacity=".3"/><stop offset="1" stop-opacity=".5"/></linearGradient><rect rx="4" width="76" height="18" fill="#555"/><rect rx="4" x="37" width="39" height="18" fill="#fe7d37"/><path fill="#fe7d37" d="M37 0h4v18h-4z"/><rect rx="4" width="76" height="18" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="13" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="12">build</text><text x="55.5" y="13" fill="#010101" fill-opacity=".3">error</text><text x="55.5" y="12">error</text></g></svg>
|
After Width: | Height: | Size: 818 B |
1
public/assets/img/build-failed.svg
Normal file
1
public/assets/img/build-failed.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="78" height="18"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-opacity=".3"/><stop offset="1" stop-opacity=".5"/></linearGradient><rect rx="4" width="78" height="18" fill="#555"/><rect rx="4" x="37" width="41" height="18" fill="#e05d44"/><path fill="#e05d44" d="M37 0h4v18h-4z"/><rect rx="4" width="78" height="18" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="13" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="12">build</text><text x="56.5" y="13" fill="#010101" fill-opacity=".3">failed</text><text x="56.5" y="12">failed</text></g></svg>
|
After Width: | Height: | Size: 820 B |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
1
public/assets/img/build-passing.svg
Normal file
1
public/assets/img/build-passing.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="90" height="18"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-opacity=".3"/><stop offset="1" stop-opacity=".5"/></linearGradient><rect rx="4" width="90" height="18" fill="#555"/><rect rx="4" x="37" width="53" height="18" fill="#97CA00"/><path fill="#97CA00" d="M37 0h4v18h-4z"/><rect rx="4" width="90" height="18" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="13" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="12">build</text><text x="62.5" y="13" fill="#010101" fill-opacity=".3">passing</text><text x="62.5" y="12">passing</text></g></svg>
|
After Width: | Height: | Size: 822 B |
Loading…
Reference in a new issue