diff --git a/src/IDF/Commit.php b/src/IDF/Commit.php index 8ee82c8..87032c1 100644 --- a/src/IDF/Commit.php +++ b/src/IDF/Commit.php @@ -141,15 +141,16 @@ class IDF_Commit extends Pluf_Model $sql = new Pluf_SQL('project=%s AND scm_id=%s', array($project->id, $change->commit)); $r = Pluf::factory('IDF_Commit')->getList(array('filter'=>$sql->gen())); - if ($r->count()) { + if ($r->count() > 0) { return $r[0]; } + $scm = IDF_Scm::get($project); $commit = new IDF_Commit(); $commit->project = $project; $commit->scm_id = $change->commit; $commit->summary = $change->title; $commit->fullmessage = $change->full_message; - $commit->author = null; + $commit->author = $scm->findAuthor($change->author); $commit->origauthor = $change->author; $commit->creation_dtime = $change->date; $commit->create(); diff --git a/src/IDF/Scm.php b/src/IDF/Scm.php index d314bb8..39dccf0 100644 --- a/src/IDF/Scm.php +++ b/src/IDF/Scm.php @@ -30,15 +30,16 @@ class IDF_Scm /** * Returns an instance of the correct scm backend object. * + * @param IDF_Project * @return Object */ - public static function get($request=null) + public static function get($project=null) { // Get scm type from project conf ; defaults to git - $scm = $request->conf->getVal('scm', 'git'); + // We will need to cache the factory + $scm = $project->getConf()->getVal('scm', 'git'); $scms = Pluf::f('allowed_scm'); - return call_user_func(array($scms[$scm], 'factory'), - $request->project); + return call_user_func(array($scms[$scm], 'factory'), $project); } /** @@ -91,7 +92,7 @@ class IDF_Scm $cache = Pluf_Cache::factory(); $key = 'IDF_Scm:'.$request->project->shortname.':lastsync'; if (null === ($res=$cache->get($key))) { - $scm = IDF_Scm::get($request); + $scm = IDF_Scm::get($request->project); foreach ($scm->getBranches() as $branche) { foreach ($scm->getChangeLog($branche, 25) as $change) { IDF_Commit::getOrAdd($change, $request->project); @@ -100,6 +101,5 @@ class IDF_Scm $cache->set($key, true, (int)(Pluf::f('cache_timeout', 300)/2)); } } - } diff --git a/src/IDF/Scm/Git.php b/src/IDF/Scm/Git.php index 144a242..993d5f8 100644 --- a/src/IDF/Scm/Git.php +++ b/src/IDF/Scm/Git.php @@ -36,6 +36,26 @@ class IDF_Scm_Git } /** + * Given the string describing the author from the log find the + * author in the database. + * + * @param string Author + * @return mixed Pluf_User or null + */ + public function findAuthor($author) + { + // We extract the email. + $match = array(); + if (!preg_match('/<(.*)>/', $author, $match)) { + return null; + } + $sql = new Pluf_SQL('email=%s', array($match[1])); + $users = Pluf::factory('Pluf_User')->getList(array('filter'=>$sql->gen())); + return ($users->count() > 0) ? $users[0] : null; + } + + + /** * Returns the URL of the git daemon. * * @param IDF_Project diff --git a/src/IDF/Scm/Mercurial.php b/src/IDF/Scm/Mercurial.php index 94e4aec..9c800c9 100644 --- a/src/IDF/Scm/Mercurial.php +++ b/src/IDF/Scm/Mercurial.php @@ -35,6 +35,25 @@ class IDF_Scm_Mercurial } /** + * Given the string describing the author from the log find the + * author in the database. + * + * @param string Author + * @return mixed Pluf_User or null + */ + public function findAuthor($author) + { + // We extract the email. + $match = array(); + if (!preg_match('/<(.*)>/', $author, $match)) { + return null; + } + $sql = new Pluf_SQL('email=%s', array($match[1])); + $users = Pluf::factory('Pluf_User')->getList(array('filter'=>$sql->gen())); + return ($users->count() > 0) ? $users[0] : null; + } + + /** * Returns the URL of the git daemon. * * @param IDF_Project diff --git a/src/IDF/Scm/Svn.php b/src/IDF/Scm/Svn.php index 48198e4..677e81a 100644 --- a/src/IDF/Scm/Svn.php +++ b/src/IDF/Scm/Svn.php @@ -42,6 +42,20 @@ class IDF_Scm_Svn } /** + * Given the string describing the author from the log find the + * author in the database. + * + * @param string Author + * @return mixed Pluf_User or null + */ + public function findAuthor($author) + { + $sql = new Pluf_SQL('login=%s', array(trim($author))); + $users = Pluf::factory('Pluf_User')->getList(array('filter'=>$sql->gen())); + return ($users->count() > 0) ? $users[0] : null; + } + + /** * Returns the URL of the subversion repository. * * @param IDF_Project diff --git a/src/IDF/Template/IssueComment.php b/src/IDF/Template/IssueComment.php index 2bfe3e3..ef4b9c7 100644 --- a/src/IDF/Template/IssueComment.php +++ b/src/IDF/Template/IssueComment.php @@ -36,7 +36,7 @@ class IDF_Template_IssueComment extends Pluf_Template_Tag { $this->project = $request->project; $this->request = $request; - $this->scm = IDF_Scm::get($request); + $this->scm = IDF_Scm::get($request->project); if ($wordwrap) $text = wordwrap($text, 69, "\n", true); if ($esc) $text = Pluf_esc($text); if ($autolink) { diff --git a/src/IDF/Views/Review.php b/src/IDF/Views/Review.php index cffe893..4578bbb 100644 --- a/src/IDF/Views/Review.php +++ b/src/IDF/Views/Review.php @@ -196,7 +196,7 @@ class IDF_Views_Review 'user' => $request->user, 'patch' => $patch,)); } - $scm = IDF_Scm::get($request); + $scm = IDF_Scm::get($request->project); $files = array(); $reviewers = array(); foreach ($diff->files as $filename => $def) { diff --git a/src/IDF/Views/Source.php b/src/IDF/Views/Source.php index b3a6bb0..c0b0958 100644 --- a/src/IDF/Views/Source.php +++ b/src/IDF/Views/Source.php @@ -42,7 +42,7 @@ class IDF_Views_Source { $title = sprintf(__('%1$s %2$s Change Log'), (string) $request->project, $this->getScmType($request)); - $scm = IDF_Scm::get($request); + $scm = IDF_Scm::get($request->project); $branches = $scm->getBranches(); $commit = $match[2]; if ('commit' != $scm->testHash($commit)) { @@ -76,7 +76,7 @@ class IDF_Views_Source { $title = sprintf(__('%1$s %2$s Source Tree'), (string) $request->project, $this->getScmType($request)); - $scm = IDF_Scm::get($request); + $scm = IDF_Scm::get($request->project); $commit = $match[2]; $branches = $scm->getBranches(); if ('commit' != $scm->testHash($commit)) { @@ -114,7 +114,7 @@ class IDF_Views_Source { $title = sprintf(__('%1$s %2$s Source Tree'), (string) $request->project, $this->getScmType($request)); - $scm = IDF_Scm::get($request); + $scm = IDF_Scm::get($request->project); $branches = $scm->getBranches(); $commit = $match[2]; $request_file = $match[3]; @@ -203,7 +203,7 @@ class IDF_Views_Source public $commit_precond = array('IDF_Precondition::accessSource'); public function commit($request, $match) { - $scm = IDF_Scm::get($request); + $scm = IDF_Scm::get($request->project); $commit = $match[2]; $branches = $scm->getBranches(); if ('commit' != $scm->testHash($commit)) { @@ -235,7 +235,7 @@ class IDF_Views_Source public $downloadDiff_precond = array('IDF_Precondition::accessSource'); public function downloadDiff($request, $match) { - $scm = IDF_Scm::get($request); + $scm = IDF_Scm::get($request->project); $commit = $match[2]; $branches = $scm->getBranches(); if ('commit' != $scm->testHash($commit)) { @@ -258,7 +258,7 @@ class IDF_Views_Source { $title = sprintf(__('%1$s %2$s Source Tree'), (string) $request->project, $this->getScmType($request)); - $scm = IDF_Scm::get($request); + $scm = IDF_Scm::get($request->project); $branches = $extra['branches']; $commit = $extra['commit']; $request_file = $extra['request_file']; @@ -302,7 +302,7 @@ class IDF_Views_Source public $getFile_precond = array('IDF_Precondition::accessSource'); public function getFile($request, $match) { - $scm = IDF_Scm::get($request); + $scm = IDF_Scm::get($request->project); $branches = $scm->getBranches(); $commit = $match[2]; $request_file = $match[3]; @@ -336,7 +336,7 @@ class IDF_Views_Source public function download($request, $match) { $commit = trim($match[2]); - $scm = IDF_Scm::get($request); + $scm = IDF_Scm::get($request->project); $branches = $scm->getBranches(); if ('commit' != $scm->testHash($commit)) { // Redirect to the first branch