require_once 'MTrack/Interface/CommitHookBridge.php';
require_once 'MTrack/Interface/CommitHookBridge2.php';
-require_once 'MTrack/Issue.php';
-require_once 'MTrack/DB.php';
-//require_once 'MTrack/Changeset.php';
-require_once 'MTrack/Config.php';
-
-require_once 'MTrack/ACL.php';
-require_once 'MTrack/Auth.php';
+//require_once 'MTrack/Issue.php';
+ //require_once 'MTrack/Changeset.php';
+
+
-class MTrackCommitChecker {
+class MTrack_CommitChecker {
+
static $fileChecks = array(
'php' => 'checkPHP',
);
+
+
static $listeners = array();
static function addCheck($name)
var $repo;
var $bridge;
+ var $authUser;
+
+ var $checks = array();
- function __construct($repo) {
- $this->repo = $repo;
+ function __construct($ar) {
+ foreach($ar as $k=>$v) {
+ $this->$k = $v;
+ }
+ foreach($this->checks as $chk) {
+ self::addCheck($chk);
+ }
+
+
}
+
function checkVeto()
{
function preCommit(IMTrackCommitHookBridge $bridge)
{
+ die("NOT SUPPORTED YET!");
+
//echo "Pre-commit";
$this->bridge = $bridge;
- MTrackACL::requireAllRights("repo:" . $this->repo->repoid, 'commit');
+ MTrackACL::requireAllRights("repo:" . $this->repo->id, 'commit');
$files = $bridge->enumChangedOrModifiedFileNames();
} else {
require_once 'MTrack/CommitHookChangeEvent.php';
$c = new MTrackCommitHookChangeEvent;
- $c->rev = $bridge->getChangesetDescriptor();
- $c->changelog = $bridge->getCommitMessage();
- $c->changeby = MTrackAuth::whoami();
- $c->ctime = time();
+ $c->rev = $bridge->getChangesetDescriptor();
+ $c->changelog = $bridge->getCommitMessage();
+ $c->changeby = $this->authUser->email; //???
+ $c->changeby_id = $this->authUser->id; //???
+ $c->ctime = time();
+ $c->fileActions = $bridge->fileActions;
$changes[] = $c;
}
return $changes;
function postCommit(IMTrackCommitHookBridge $bridge)
{
+
+ // this might be run on multiple commits (big push...)
+
+
+ // in our system, we not only log commits that are against a
+ // ticket, but also ones that are not..
+
+
$files = $bridge->enumChangedOrModifiedFileNames();
$fqfiles = array();
foreach ($files as $filename) {
- $fqfiles[] = $this->repo->shortname . '/' . $filename;
+ $fqfiles[] = $this->repo->shortname . '/' . $filename;
}
// build up overall picture of what needs to be applied to tickets
$changes = $this->_getChanges($bridge);
+
+
+ print_R($changes);
+
// Deferred by tid
$deferred = array();
// Changes that didn't ref a ticket; we want to show something
// on the timeline
$no_ticket = array();
+
+ $me = $this->authUser;
+
+
- $me = mtrack_canon_username(MTrackAuth::whoami());
foreach ($changes as $c) {
- $tickets = array();
- $log = $c->changelog;
-
- $actions = $this->parseCommitMessage($log);
- foreach ($actions as $act) {
- $what = $act[0];
- $tkt = $act[1];
- $tickets[$tkt][$what] = $what;
- if (isset($act[2])) {
- $tickets[$tkt]['spent'] += $act[2];
+ $tickets = array();
+ $log = $c->changelog;
+
+ $actions = $this->parseCommitMessage($log);
+ foreach ($actions as $act) {
+ $what = $act[0];
+ $tkt = $act[1];
+ $tickets[$tkt][$what] = $what;
+ if (isset($act[2])) {
+ $tickets[$tkt]['spent'] += $act[2];
+ }
}
- }
- if (count($tickets) == 0) {
- $no_ticket[] = $c;
- continue;
- }
- // apply changes to tickets
- foreach ($tickets as $tkt => $act) {
- if (strlen($tkt) == 32 && isset($T_by_tid[$tkt])) {
- $T = $T_by_tid[$tkt];
- } else {
- if (strlen($tkt) == 32) {
- $T = MTrackIssue::loadById($tkt);
- } else {
- $T = MTrackIssue::loadByNSIdent($tkt);
- }
- $T_by_tid[$T->tid] = $T;
+ if (count($tickets) == 0) {
+ $no_ticket[] = $c;
+
+ continue;
}
-
+
+ // apply changes to tickets
+ foreach ($tickets as $tkt => $act) {
+ // removed all the code that handles hashed ticked ids...
+ $T = clone($this->ticketProvider);
+ if (!$T->get($tkt)) {
+ continue;
+ }
+
+ $T_by_tid[$T->id] = $T;
+ }
+ /*
$accounted = false;
+
if ($c->hash !== null) {
- if (isset($hashed[$T->tid][$c->hash])) {
- $accounted = true;
- } else {
- list($accounted) = MTrackDB::q(
- 'select count(hash) from ticket_changeset_hashes
- where tid = ? and hash = ?',
+ if (isset($hashed[$T->tid][$c->hash])) {
+ $accounted = true;
+ } else {
+ // see if we already have a reference
+
+
+ list($accounted) = MTrackDB::q(
+ 'select count(hash) from ticket_changeset_hashes
+ where tid = ? and hash = ?',
$T->tid, $c->hash)->fetchAll(PDO::FETCH_COLUMN, 0);
if (!$accounted) {
$hashed[$T->tid][$c->hash] = $c->hash;
$this->repo->getBrowseRootName() . "]";
continue;
}
+
+ */
+
$log = "(In " . $c->rev . ") ";
- if ($c->changeby != $me) {
- $log .= " (on behalf of [user:$c->changeby]) ";
- }
+ /*
+ .. we do not support commits on behalf of yet..
+ .. to fix this we need to change the auth code to
+ .. really pick up auth data..
+
+ if ($c->changeby != $me) {
+ $log .= " (on behalf of [user:$c->changeby]) ";
+ }
+ */
+
$log .= $c->changelog;
- $deferred[$T->tid]['comments'][] = $log;
+
+ $deferred[$T->id]['comments'][] = $log;
+
if (isset($act['spent']) && $c->changeby != $me) {
- $spent_by_tid_by_user[$T->tid][$c->changeby][] = $act['spent'];
- unset($act['spent']);
+ $spent_by_tid_by_user[$T->id][$c->changeby_id][] = $act['spent'];
+ unset($act['spent']);
}
$deferred[$T->tid]['act'][] = $act;
-
- }
- $this->checkVeto('postCommit', $log, $fqfiles, $actions);
+
+ //???
+ $this->checkVeto('postCommit', $log, $fqfiles, $actions);
}
+
+
+ // defered is a list of actions...
+ $this->no_ticket = $no_ticket;
+ $this->deferred = $deferred;
+ $this->spent_by_tid_by_user = $spent_by_tid_by_user;
+
+
+ return true;
+
+ /*
+ $ret = array();
// print_r($deferred);
foreach ($deferred as $tid => $info) {
- $T = $T_by_tid[$tid];
-
- $log = join("\n\n", $info['comments']);
-
+ $T = $T_by_tid[$tid];
+
+ $log = join("\n\n", $info['comments']);
+
+
+
+
+
$CS = MTrackChangeset::begin("ticket:" . $T->tid, $log);
if (isset($hashed[$T->tid])) {
}
$log .= $c->changelog . "\n\n";
}
- $CS = MTrackChangeset::begin("repo:" . $this->repo->repoid, $log);
+ $CS = MTrackChangeset::begin("repo:" . $this->repo->id, $log);
$CS->commit();
+
+ */
}