File size: 3,911 Bytes
158b61b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
<?php
class StaticData
{
const logs_path = "./data/";
}
function get_all_branch_names()
{
$branches = array();
$dir_hdl = opendir(StaticData::logs_path);
while (($file = readdir($dir_hdl)) !== false) {
if (($pos = strpos($file, ".revlist")) > 0) {
array_push($branches, substr($file, 0, $pos));
}
}
return $branches;
}
class Branch
{
public function __construct($name)
{
$this->name = $name;
$this->create_revlist_hdl();
}
public function get_next_commit()
{
return new Commit( chop( fgets($this->revlist_hdl) ) );
}
public function set_line($line)
{
$this->reset();
$index = 0;
while ($this->revlist_hdl && $index < $line) {
fgets($this->revlist_hdl);
$index++;
}
}
public function reset()
{
fclose($this->revlist_hdl);
$this->create_revlist_hdl();
}
private function create_revlist_hdl()
{
$this->revlist_hdl = fopen(StaticData::logs_path . "/" . $this->name . ".revlist", "r");
}
private $name;
private $revlist_hdl;
}
class Commit
{
public function __construct($name)
{
$this->name = $name;
}
public function read_log()
{
if (! $this->was_tested()) {
return;
}
$log_hdl = fopen(StaticData::logs_path . "/" . substr($this->name, 0, 1) . "/" . $this->name . ".log", "r");
while (($line = fgets($log_hdl)) !== false) {
if (preg_match('/tests passed/', $line)) {
$this->passed_percent = substr($line, 0, strpos('%', $line));
}
else if (preg_match('/INVESTIGATE THESE FAILED TESTS/', $line)) {
$this->failed_tests = substr($line, 39);
}
else if (! $this->is_ok() && preg_match('/## Status:/', $line)) {
$this->failed_at = substr($line, 16);
}
}
}
public function read_info()
{
$info_hdl = fopen(StaticData::logs_path . "/" . substr($this->name, 0, 1) . "/" . $this->name . ".info", "r");
while (($line = fgets($info_hdl)) !== false) {
if (preg_match('/Author:/', $line)) {
$this->author = substr("$line", 7);
}
else if (preg_match('/Date:/', $line)) {
$this->timestamp = substr("$line", 12);
break;
}
}
while (($line = fgets($info_hdl)) !== false) {
$this->message .= chop($line);
}
$this->message = preg_replace('/\s+/', ' ', $this->message);
}
public function was_tested()
{
return file_exists(StaticData::logs_path . "/" . substr($this->name, 0, 1) . "/" . $this->name . ".log");
}
public function is_ok()
{
if (! $this->was_tested()) {
return false;
} else {
return file_exists(StaticData::logs_path . "/" . substr($this->name, 0, 1) . "/" . $this->name . ".OK");
}
}
public function get_status()
{
return $this->was_tested()
? ($this->is_ok() ? "OK" : "Failed: " . $this->get_failed_at()) : "Not tested";
}
public function get_passed_percent()
{
return $this->passed_percent;
}
public function get_failed_tests()
{
return $this->failed_tests;
}
public function get_failed_at()
{
return $this->failed_at;
}
public function get_message()
{
return $this->message;
}
public function get_author()
{
return $this->author;
}
public function get_timestamp()
{
return $this->timestamp;
}
public function get_name()
{
return $this->name;
}
public function get_log_file()
{
return "show_commit.php?commit_id=$this->name&type=log";
}
public function get_info_file()
{
return "show_commit.php?commit_id=$this->name&type=info";
}
private function open_log()
{
return fopen($this->get_log_file());
}
private function open_info()
{
return fopen($this->get_info_file());
}
private $name;
private $passed_percent;
private $failed_tests;
private $failed_at;
private $message;
private $author;
private $timestamp;
}
?>
|