Added ticket 80, scm login integration with database login.
Based on the login for Subversion and the email address for git and Mercurial.
This commit is contained in:
parent
d6e3b8dca9
commit
a1eeb12516
@ -141,15 +141,16 @@ class IDF_Commit extends Pluf_Model
|
|||||||
$sql = new Pluf_SQL('project=%s AND scm_id=%s',
|
$sql = new Pluf_SQL('project=%s AND scm_id=%s',
|
||||||
array($project->id, $change->commit));
|
array($project->id, $change->commit));
|
||||||
$r = Pluf::factory('IDF_Commit')->getList(array('filter'=>$sql->gen()));
|
$r = Pluf::factory('IDF_Commit')->getList(array('filter'=>$sql->gen()));
|
||||||
if ($r->count()) {
|
if ($r->count() > 0) {
|
||||||
return $r[0];
|
return $r[0];
|
||||||
}
|
}
|
||||||
|
$scm = IDF_Scm::get($project);
|
||||||
$commit = new IDF_Commit();
|
$commit = new IDF_Commit();
|
||||||
$commit->project = $project;
|
$commit->project = $project;
|
||||||
$commit->scm_id = $change->commit;
|
$commit->scm_id = $change->commit;
|
||||||
$commit->summary = $change->title;
|
$commit->summary = $change->title;
|
||||||
$commit->fullmessage = $change->full_message;
|
$commit->fullmessage = $change->full_message;
|
||||||
$commit->author = null;
|
$commit->author = $scm->findAuthor($change->author);
|
||||||
$commit->origauthor = $change->author;
|
$commit->origauthor = $change->author;
|
||||||
$commit->creation_dtime = $change->date;
|
$commit->creation_dtime = $change->date;
|
||||||
$commit->create();
|
$commit->create();
|
||||||
|
@ -30,15 +30,16 @@ class IDF_Scm
|
|||||||
/**
|
/**
|
||||||
* Returns an instance of the correct scm backend object.
|
* Returns an instance of the correct scm backend object.
|
||||||
*
|
*
|
||||||
|
* @param IDF_Project
|
||||||
* @return Object
|
* @return Object
|
||||||
*/
|
*/
|
||||||
public static function get($request=null)
|
public static function get($project=null)
|
||||||
{
|
{
|
||||||
// Get scm type from project conf ; defaults to git
|
// 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');
|
$scms = Pluf::f('allowed_scm');
|
||||||
return call_user_func(array($scms[$scm], 'factory'),
|
return call_user_func(array($scms[$scm], 'factory'), $project);
|
||||||
$request->project);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -91,7 +92,7 @@ class IDF_Scm
|
|||||||
$cache = Pluf_Cache::factory();
|
$cache = Pluf_Cache::factory();
|
||||||
$key = 'IDF_Scm:'.$request->project->shortname.':lastsync';
|
$key = 'IDF_Scm:'.$request->project->shortname.':lastsync';
|
||||||
if (null === ($res=$cache->get($key))) {
|
if (null === ($res=$cache->get($key))) {
|
||||||
$scm = IDF_Scm::get($request);
|
$scm = IDF_Scm::get($request->project);
|
||||||
foreach ($scm->getBranches() as $branche) {
|
foreach ($scm->getBranches() as $branche) {
|
||||||
foreach ($scm->getChangeLog($branche, 25) as $change) {
|
foreach ($scm->getChangeLog($branche, 25) as $change) {
|
||||||
IDF_Commit::getOrAdd($change, $request->project);
|
IDF_Commit::getOrAdd($change, $request->project);
|
||||||
@ -100,6 +101,5 @@ class IDF_Scm
|
|||||||
$cache->set($key, true, (int)(Pluf::f('cache_timeout', 300)/2));
|
$cache->set($key, true, (int)(Pluf::f('cache_timeout', 300)/2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,26 @@ class IDF_Scm_Git
|
|||||||
$this->repo = $repo;
|
$this->repo = $repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Returns the URL of the git daemon.
|
||||||
*
|
*
|
||||||
|
@ -34,6 +34,25 @@ class IDF_Scm_Mercurial
|
|||||||
$this->repo = $repo;
|
$this->repo = $repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Returns the URL of the git daemon.
|
||||||
*
|
*
|
||||||
|
@ -41,6 +41,20 @@ class IDF_Scm_Svn
|
|||||||
$this->password = $password;
|
$this->password = $password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Returns the URL of the subversion repository.
|
||||||
*
|
*
|
||||||
|
@ -36,7 +36,7 @@ class IDF_Template_IssueComment extends Pluf_Template_Tag
|
|||||||
{
|
{
|
||||||
$this->project = $request->project;
|
$this->project = $request->project;
|
||||||
$this->request = $request;
|
$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 ($wordwrap) $text = wordwrap($text, 69, "\n", true);
|
||||||
if ($esc) $text = Pluf_esc($text);
|
if ($esc) $text = Pluf_esc($text);
|
||||||
if ($autolink) {
|
if ($autolink) {
|
||||||
|
@ -196,7 +196,7 @@ class IDF_Views_Review
|
|||||||
'user' => $request->user,
|
'user' => $request->user,
|
||||||
'patch' => $patch,));
|
'patch' => $patch,));
|
||||||
}
|
}
|
||||||
$scm = IDF_Scm::get($request);
|
$scm = IDF_Scm::get($request->project);
|
||||||
$files = array();
|
$files = array();
|
||||||
$reviewers = array();
|
$reviewers = array();
|
||||||
foreach ($diff->files as $filename => $def) {
|
foreach ($diff->files as $filename => $def) {
|
||||||
|
@ -42,7 +42,7 @@ class IDF_Views_Source
|
|||||||
{
|
{
|
||||||
$title = sprintf(__('%1$s %2$s Change Log'), (string) $request->project,
|
$title = sprintf(__('%1$s %2$s Change Log'), (string) $request->project,
|
||||||
$this->getScmType($request));
|
$this->getScmType($request));
|
||||||
$scm = IDF_Scm::get($request);
|
$scm = IDF_Scm::get($request->project);
|
||||||
$branches = $scm->getBranches();
|
$branches = $scm->getBranches();
|
||||||
$commit = $match[2];
|
$commit = $match[2];
|
||||||
if ('commit' != $scm->testHash($commit)) {
|
if ('commit' != $scm->testHash($commit)) {
|
||||||
@ -76,7 +76,7 @@ class IDF_Views_Source
|
|||||||
{
|
{
|
||||||
$title = sprintf(__('%1$s %2$s Source Tree'), (string) $request->project,
|
$title = sprintf(__('%1$s %2$s Source Tree'), (string) $request->project,
|
||||||
$this->getScmType($request));
|
$this->getScmType($request));
|
||||||
$scm = IDF_Scm::get($request);
|
$scm = IDF_Scm::get($request->project);
|
||||||
$commit = $match[2];
|
$commit = $match[2];
|
||||||
$branches = $scm->getBranches();
|
$branches = $scm->getBranches();
|
||||||
if ('commit' != $scm->testHash($commit)) {
|
if ('commit' != $scm->testHash($commit)) {
|
||||||
@ -114,7 +114,7 @@ class IDF_Views_Source
|
|||||||
{
|
{
|
||||||
$title = sprintf(__('%1$s %2$s Source Tree'), (string) $request->project,
|
$title = sprintf(__('%1$s %2$s Source Tree'), (string) $request->project,
|
||||||
$this->getScmType($request));
|
$this->getScmType($request));
|
||||||
$scm = IDF_Scm::get($request);
|
$scm = IDF_Scm::get($request->project);
|
||||||
$branches = $scm->getBranches();
|
$branches = $scm->getBranches();
|
||||||
$commit = $match[2];
|
$commit = $match[2];
|
||||||
$request_file = $match[3];
|
$request_file = $match[3];
|
||||||
@ -203,7 +203,7 @@ class IDF_Views_Source
|
|||||||
public $commit_precond = array('IDF_Precondition::accessSource');
|
public $commit_precond = array('IDF_Precondition::accessSource');
|
||||||
public function commit($request, $match)
|
public function commit($request, $match)
|
||||||
{
|
{
|
||||||
$scm = IDF_Scm::get($request);
|
$scm = IDF_Scm::get($request->project);
|
||||||
$commit = $match[2];
|
$commit = $match[2];
|
||||||
$branches = $scm->getBranches();
|
$branches = $scm->getBranches();
|
||||||
if ('commit' != $scm->testHash($commit)) {
|
if ('commit' != $scm->testHash($commit)) {
|
||||||
@ -235,7 +235,7 @@ class IDF_Views_Source
|
|||||||
public $downloadDiff_precond = array('IDF_Precondition::accessSource');
|
public $downloadDiff_precond = array('IDF_Precondition::accessSource');
|
||||||
public function downloadDiff($request, $match)
|
public function downloadDiff($request, $match)
|
||||||
{
|
{
|
||||||
$scm = IDF_Scm::get($request);
|
$scm = IDF_Scm::get($request->project);
|
||||||
$commit = $match[2];
|
$commit = $match[2];
|
||||||
$branches = $scm->getBranches();
|
$branches = $scm->getBranches();
|
||||||
if ('commit' != $scm->testHash($commit)) {
|
if ('commit' != $scm->testHash($commit)) {
|
||||||
@ -258,7 +258,7 @@ class IDF_Views_Source
|
|||||||
{
|
{
|
||||||
$title = sprintf(__('%1$s %2$s Source Tree'), (string) $request->project,
|
$title = sprintf(__('%1$s %2$s Source Tree'), (string) $request->project,
|
||||||
$this->getScmType($request));
|
$this->getScmType($request));
|
||||||
$scm = IDF_Scm::get($request);
|
$scm = IDF_Scm::get($request->project);
|
||||||
$branches = $extra['branches'];
|
$branches = $extra['branches'];
|
||||||
$commit = $extra['commit'];
|
$commit = $extra['commit'];
|
||||||
$request_file = $extra['request_file'];
|
$request_file = $extra['request_file'];
|
||||||
@ -302,7 +302,7 @@ class IDF_Views_Source
|
|||||||
public $getFile_precond = array('IDF_Precondition::accessSource');
|
public $getFile_precond = array('IDF_Precondition::accessSource');
|
||||||
public function getFile($request, $match)
|
public function getFile($request, $match)
|
||||||
{
|
{
|
||||||
$scm = IDF_Scm::get($request);
|
$scm = IDF_Scm::get($request->project);
|
||||||
$branches = $scm->getBranches();
|
$branches = $scm->getBranches();
|
||||||
$commit = $match[2];
|
$commit = $match[2];
|
||||||
$request_file = $match[3];
|
$request_file = $match[3];
|
||||||
@ -336,7 +336,7 @@ class IDF_Views_Source
|
|||||||
public function download($request, $match)
|
public function download($request, $match)
|
||||||
{
|
{
|
||||||
$commit = trim($match[2]);
|
$commit = trim($match[2]);
|
||||||
$scm = IDF_Scm::get($request);
|
$scm = IDF_Scm::get($request->project);
|
||||||
$branches = $scm->getBranches();
|
$branches = $scm->getBranches();
|
||||||
if ('commit' != $scm->testHash($commit)) {
|
if ('commit' != $scm->testHash($commit)) {
|
||||||
// Redirect to the first branch
|
// Redirect to the first branch
|
||||||
|
Loading…
Reference in New Issue
Block a user