Skip to content

Instantly share code, notes, and snippets.

@tmpvar
Created April 5, 2010 00:28
Show Gist options
  • Save tmpvar/355847 to your computer and use it in GitHub Desktop.
Save tmpvar/355847 to your computer and use it in GitHub Desktop.
tmpvar's project dashboard
<?php
ob_start();
if (count($_POST) > 0 && isset($_POST['payload'])) {
$obj = json_decode(stripcslashes($_POST['payload']), true);
$project = preg_replace('/[^a-zA-Z0-9_-]/', '', $obj['repository']['name']);
$cmd = "cd /srv/www/tmpvar.com/project/$project";
set_time_limit(0);
$pull = $cmd . " && git pull";
exec($pull);
// run tests if available
$runTests = $cmd . " && /usr/local/bin/node-waf test";
exec($runTests);
file_put_contents("/srv/www/tmpvar.com/project/test.txt", ob_get_contents());
exit();
}
ob_clean();
?>
<html>
<head>
<style>
body {
font-family:verdana;
font-size:.65em;
background: black;
}
li,ul { list-style:none; margin:0px; padding:0px;}
li { padding-left: 5px; margin:0px; margin-top:5px;}
ul.todo li {
border-left:3px solid #991100;
}
ul.done li {
border-left:3px solid green;
}
body div.project {
margin-top:20px;
border:1px solid #777;
padding: 10px;
background: #333;
color: white;
width:550px;
margin-left:20px;
overflow:hidden;
}
a {
color: #FF6600;
float:right;
font-size:12px;
text-decoration: none;
margin-left:10px;
}
h2 {
display:inline;
margin:0px;
float:left;
}
span.percent {
margin-left:2px;
padding-top:5px;
font-size:10px;
}
div.rightheader {
float:right;
}
div.tests {
float:right;
width:100px;
border:1px solid #000;
clear:right;
margin-top:10px;
padding:5px;
background: #555;
}
div.tests .percent {
font-size:33px;
text-align:center;
}
div.tests .summary {
}
div.tests .passing {
}
</style>
</head>
<body>
<?php
$dirs = array_filter(glob($path.'*'), 'is_dir');
foreach ($dirs as $directory)
{
echo "<div class='project'>";
echo "<h2>$directory</h2><div class='rightheader'>";
if (is_file($directory . "/index.html")) {
echo "<a href='$directory'>demo</a>";
}
echo " <a href='http://github.com/tmpvar/$directory'>github</a></div>";
echo "<div class='tests'>";
$total = 0;
$percent = 0;
$pass = 0;
if (is_file($directory . "/test/status.json")) {
$tests = json_decode(file_get_contents($directory . "/test/status.json"), true);
$total = $tests['total'];
$pass = $tests['pass'];
$percent = floor(($pass/$total)*100);
}
echo "<div class='summary'>$pass/$total</div>";
echo "<div class='percent'>$percent%</div>";
echo "<div class='passing'>passing tests</div>";
echo "</div>";
$status = $directory . "/" . "status.json";
if (is_file($status) && ($s = json_decode(file_get_contents($status),true))) {
$percent = count($s['done']) / (count($s['done']) + count($s['todo']))*100;
echo "<span class='percent'> (" . floor($percent) . "% of tasks complete)</span>";
echo "<p><ul class='todo'>";
foreach ($s['todo'] as $todo)
{
echo "<li>$todo</li>";
}
echo "</ul><ul class='done'>";
foreach ($s['done'] as $done)
{
echo "<li>$done</li>";
}
echo "</ul></p>";
} else {
echo "<span class='percent'> (0% of tasks complete)</span>";
}
// show tests
echo "<div style='clear:both;'></div></div>";
}
?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-633948-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment