added svn commit logging
- added a new post-commit script - updated repo.sh to install this script in a svn repository.
This commit is contained in:
		@ -1,7 +1,7 @@
 | 
			
		||||
 | 
			
		||||
cfgdir=$(CFGDIR)
 | 
			
		||||
cfg_DATA = codepot.ini codepot.sql codepot.a2ldap
 | 
			
		||||
cfg_SCRIPTS = repo.sh start-commit
 | 
			
		||||
cfg_SCRIPTS = repo.sh start-commit post-commit
 | 
			
		||||
 | 
			
		||||
EXTRA_DIST = $(cfg_DATA)  $(cfg_SCRIPTS)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -166,7 +166,7 @@ top_builddir = @top_builddir@
 | 
			
		||||
top_srcdir = @top_srcdir@
 | 
			
		||||
wwwdir = @wwwdir@
 | 
			
		||||
cfg_DATA = codepot.ini codepot.sql codepot.a2ldap
 | 
			
		||||
cfg_SCRIPTS = repo.sh start-commit
 | 
			
		||||
cfg_SCRIPTS = repo.sh start-commit post-commit
 | 
			
		||||
EXTRA_DIST = $(cfg_DATA)  $(cfg_SCRIPTS)
 | 
			
		||||
all: all-am
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -75,10 +75,16 @@ sysadmin_userid =
 | 
			
		||||
max_upload_size = "10000"
 | 
			
		||||
 | 
			
		||||
;------------------------------------------------------------------------------
 | 
			
		||||
; Maximum number of latest projects to show
 | 
			
		||||
; Maximum number of latest projects to show in the front page
 | 
			
		||||
;------------------------------------------------------------------------------
 | 
			
		||||
max_latest_projects = "10"
 | 
			
		||||
 | 
			
		||||
;------------------------------------------------------------------------------
 | 
			
		||||
; Maximum number of svn commits to show in the front page
 | 
			
		||||
;------------------------------------------------------------------------------
 | 
			
		||||
max_svn_commits = "10"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
;------------------------------------------------------------------------------
 | 
			
		||||
; directory to accomodate subversion repositories
 | 
			
		||||
;------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
@ -73,3 +73,10 @@ CREATE TABLE file (
 | 
			
		||||
		ON DELETE RESTRICT ON UPDATE CASCADE
 | 
			
		||||
) charset=utf8 engine=InnoDB;	
 | 
			
		||||
 | 
			
		||||
CREATE TABLE log  (
 | 
			
		||||
	id         BIGINT PRIMARY KEY AUTO_INCREMENT,
 | 
			
		||||
	type       VARCHAR(16)  NOT NULL,
 | 
			
		||||
	message    TEXT         NOT NULL,
 | 
			
		||||
	createdon  DATETIME     NOT NULL,
 | 
			
		||||
	INDEX timed_type (createdon, type)
 | 
			
		||||
) charset=utf8 engine=InnoDB;	
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										13
									
								
								codepot/etc/post-commit
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										13
									
								
								codepot/etc/post-commit
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,13 @@
 | 
			
		||||
#!/bin/sh
 | 
			
		||||
 | 
			
		||||
post_commit() {
 | 
			
		||||
	local repo_path="$1"
 | 
			
		||||
	local rev="$2"
 | 
			
		||||
	local repo="`basename "${repo_path}"`"
 | 
			
		||||
 | 
			
		||||
	ans="`wget -q -O- "%API%/logSvnCommit/${repo}/${rev}" 2>/dev/null`"
 | 
			
		||||
	return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
post_commit "$1" "$2"
 | 
			
		||||
exit $?
 | 
			
		||||
@ -29,10 +29,19 @@ make_repo() {
 | 
			
		||||
		chmod 0755 "${repodir}/start-commit"
 | 
			
		||||
	#}
 | 
			
		||||
 | 
			
		||||
	#[ -f "${repodir}/post-commit" ] || {
 | 
			
		||||
		sed "s|%API%|${api}|g" "${cfgdir}/post-commit" > "${repodir}/post-commit" || {
 | 
			
		||||
			echo "ERROR: cannot install post-commit to ${repodir}"
 | 
			
		||||
			return 1;
 | 
			
		||||
		}
 | 
			
		||||
		chmod 0755 "${repodir}/post-commit"
 | 
			
		||||
	#}
 | 
			
		||||
 | 
			
		||||
	svnadmin create "${repodir}/${reponame}" && {
 | 
			
		||||
		oldpwd="`pwd`"
 | 
			
		||||
		cd "${repodir}/${reponame}/hooks"
 | 
			
		||||
		ln -sf ../../start-commit start-commit
 | 
			
		||||
		ln -sf ../../post-commit post-commit
 | 
			
		||||
		cd "${oldpwd}"
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -9,14 +9,23 @@ class API extends Controller
 | 
			
		||||
 | 
			
		||||
	function projectHasMember ($projectid, $userid)
 | 
			
		||||
	{
 | 
			
		||||
		// TODO: access control - may allow localhost only
 | 
			
		||||
		$this->load->model ('ProjectModel', 'projects');
 | 
			
		||||
		print ($this->projects->projectHasMember ($projectid, $userid) === FALSE)? 'NO': 'YES';
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	function projectIsOwnedBy ($projectid, $userid)
 | 
			
		||||
	{
 | 
			
		||||
		// TODO: access control - may allow localhost only
 | 
			
		||||
		$this->load->model ('ProjectModel', 'projects');
 | 
			
		||||
		print ($this->projects->projectIsOwnedBy ($projectid, $userid) === FALSE)? 'NO': 'YES';
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	function logSvnCommit ($repo, $rev)
 | 
			
		||||
	{
 | 
			
		||||
		// TODO: access control - may allow localhost only
 | 
			
		||||
		$this->load->model ('LogModel', 'logs');
 | 
			
		||||
		$this->logs->writeSvnCommit ($repo, $rev);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -30,8 +30,9 @@ class User extends Controller
 | 
			
		||||
		if (CODEPOT_ALWAYS_REQUIRE_SIGNIN && $login['id'] == '')
 | 
			
		||||
			redirect ('main/signin');
 | 
			
		||||
 | 
			
		||||
		$this->load->model ('ProjectModel', 'projects');
 | 
			
		||||
		$this->load->model ('SiteModel', 'sites');
 | 
			
		||||
		$this->load->model ('ProjectModel', 'projects');
 | 
			
		||||
		$this->load->model ('LogModel', 'logs');
 | 
			
		||||
 | 
			
		||||
                $site = $this->sites->get (CODEPOT_DEFAULT_SITEID);
 | 
			
		||||
		if ($site === FALSE)
 | 
			
		||||
@ -39,28 +40,35 @@ class User extends Controller
 | 
			
		||||
			$data['login'] = $login;
 | 
			
		||||
			$data['message'] = 'DATABASE ERROR';
 | 
			
		||||
			$this->load->view ($this->VIEW_ERROR, $data);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		else 
 | 
			
		||||
		{
 | 
			
		||||
			$latest_projects = $this->projects->getLatestProjects ($login['id'], CODEPOT_MAX_LATEST_PROJECTS);
 | 
			
		||||
			if ($latest_projects === FALSE)
 | 
			
		||||
			{
 | 
			
		||||
				$data['login'] = $login;
 | 
			
		||||
				$data['message'] = 'DATABASE ERROR';
 | 
			
		||||
				$this->load->view ($this->VIEW_ERROR, $data);
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
			{
 | 
			
		||||
				if ($site === NULL) $site = $this->sites->getDefault ();
 | 
			
		||||
		if ($site === NULL) $site = $this->sites->getDefault ();
 | 
			
		||||
 | 
			
		||||
				$data['login'] = $login;
 | 
			
		||||
				$data['latest_projects'] = $latest_projects;
 | 
			
		||||
				$data['site'] = $site;
 | 
			
		||||
				//$data['user_name'] = '';
 | 
			
		||||
				//$data['user_pass'] = '';
 | 
			
		||||
				$this->load->view ($this->VIEW_HOME, $data);
 | 
			
		||||
			}
 | 
			
		||||
		$latest_projects = $this->projects->getLatestProjects ($login['id'], CODEPOT_MAX_LATEST_PROJECTS);
 | 
			
		||||
		if ($latest_projects === FALSE)
 | 
			
		||||
		{
 | 
			
		||||
			$data['login'] = $login;
 | 
			
		||||
			$data['message'] = 'DATABASE ERROR';
 | 
			
		||||
			$this->load->view ($this->VIEW_ERROR, $data);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$svn_commits = $this->logs->getSvnCommits (CODEPOT_MAX_SVN_COMMITS);
 | 
			
		||||
		if ($svn_commits === FALSE)
 | 
			
		||||
		{
 | 
			
		||||
			$data['login'] = $login;
 | 
			
		||||
			$data['message'] = 'DATABASE ERROR';
 | 
			
		||||
			$this->load->view ($this->VIEW_ERROR, $data);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$data['login'] = $login;
 | 
			
		||||
		$data['latest_projects'] = $latest_projects;
 | 
			
		||||
		$data['svn_commits'] = $svn_commits;
 | 
			
		||||
		$data['site'] = $site;
 | 
			
		||||
		//$data['user_name'] = '';
 | 
			
		||||
		//$data['user_pass'] = '';
 | 
			
		||||
		$this->load->view ($this->VIEW_HOME, $data);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	function projectlist ()
 | 
			
		||||
 | 
			
		||||
@ -43,6 +43,7 @@ $lang['Size'] = 'Size';
 | 
			
		||||
$lang['Source'] = 'Source';
 | 
			
		||||
$lang['Summary'] = 'Summary';
 | 
			
		||||
$lang['System'] = 'System';
 | 
			
		||||
$lang['SVN commits'] = 'SVN commits';
 | 
			
		||||
$lang['Tag'] = 'Tag';
 | 
			
		||||
$lang['Text'] = 'Text';
 | 
			
		||||
$lang['Time'] = 'Time';
 | 
			
		||||
 | 
			
		||||
@ -43,6 +43,7 @@ $lang['Size'] = 'Ukuran';
 | 
			
		||||
$lang['Source'] = 'Sumber';
 | 
			
		||||
$lang['Summary'] = 'Rangkuman';
 | 
			
		||||
$lang['System'] = 'Sistem';
 | 
			
		||||
$lang['SVN commits'] = 'SVN commits';
 | 
			
		||||
$lang['Tag'] = 'Label';
 | 
			
		||||
$lang['Text'] = 'Teks';
 | 
			
		||||
$lang['Time'] = 'Waktu';
 | 
			
		||||
 | 
			
		||||
@ -43,6 +43,7 @@ $lang['Size'] = '크기';
 | 
			
		||||
$lang['Source'] = '소스';
 | 
			
		||||
$lang['Summary'] = '요약';
 | 
			
		||||
$lang['System'] = '시스템';
 | 
			
		||||
$lang['SVN commits'] = 'SVN 커밋';
 | 
			
		||||
$lang['Tag'] = '태그';
 | 
			
		||||
$lang['Text'] = '본문';
 | 
			
		||||
$lang['Time'] = '시간';
 | 
			
		||||
 | 
			
		||||
@ -4,6 +4,7 @@ www_DATA =  \
 | 
			
		||||
	index.html \
 | 
			
		||||
	ldaploginmodel.php \
 | 
			
		||||
	loginmodel.php \
 | 
			
		||||
	logmodel.php \
 | 
			
		||||
	projectmodel.php \
 | 
			
		||||
	sitemodel.php \
 | 
			
		||||
	subversionmodel.php \
 | 
			
		||||
 | 
			
		||||
@ -167,6 +167,7 @@ www_DATA = \
 | 
			
		||||
	index.html \
 | 
			
		||||
	ldaploginmodel.php \
 | 
			
		||||
	loginmodel.php \
 | 
			
		||||
	logmodel.php \
 | 
			
		||||
	projectmodel.php \
 | 
			
		||||
	sitemodel.php \
 | 
			
		||||
	subversionmodel.php \
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										126
									
								
								codepot/src/codepot/models/logmodel.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										126
									
								
								codepot/src/codepot/models/logmodel.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,126 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
class LogModel extends Model
 | 
			
		||||
{
 | 
			
		||||
	function LogModel ()
 | 
			
		||||
	{
 | 
			
		||||
		parent::Model ();
 | 
			
		||||
		$this->load->database ();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/*
 | 
			
		||||
	function get ($id)
 | 
			
		||||
	{
 | 
			
		||||
		$this->db->trans_start ();
 | 
			
		||||
 | 
			
		||||
		$this->db->where ('id', (string)$id);
 | 
			
		||||
		$query = $this->db->get ('log');
 | 
			
		||||
 | 
			
		||||
		$result = $query->result ();
 | 
			
		||||
		if (empty($result))
 | 
			
		||||
		{
 | 
			
		||||
			$this->db->trans_complete ();
 | 
			
		||||
			if ($this->db->trans_status() === FALSE) return FALSE;
 | 
			
		||||
			return NULL;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$this->db->trans_complete ();
 | 
			
		||||
		if ($this->db->trans_status() === FALSE) return FALSE;
 | 
			
		||||
 | 
			
		||||
		return $result[0];
 | 
			
		||||
	}
 | 
			
		||||
	*/
 | 
			
		||||
 | 
			
		||||
	function getSvnCommits ($limit)
 | 
			
		||||
	{
 | 
			
		||||
		$this->db->trans_start ();
 | 
			
		||||
 | 
			
		||||
		$this->db->where ('type', 'svn-commit');
 | 
			
		||||
		$this->db->order_by ('createdon', 'desc');
 | 
			
		||||
		$query = $this->db->get ('log', $limit);
 | 
			
		||||
 | 
			
		||||
		$result = $query->result ();
 | 
			
		||||
		$this->db->trans_complete ();
 | 
			
		||||
		if ($this->db->trans_status() === FALSE) return FALSE;
 | 
			
		||||
 | 
			
		||||
		$count = 0;
 | 
			
		||||
		$commits = array ();
 | 
			
		||||
		foreach ($result as $row)
 | 
			
		||||
		{
 | 
			
		||||
			list($repo,$rev) = split('[,]', $row->message);
 | 
			
		||||
 | 
			
		||||
			$commits[$count]['repo'] = $repo;
 | 
			
		||||
			$commits[$count]['rev'] = $rev;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
			$log = @svn_log (
 | 
			
		||||
				'file:///'.CODEPOT_SVNREPO_DIR."/{$repo}",
 | 
			
		||||
				$rev, $rev, 1,SVN_DISCOVER_CHANGED_PATHS);
 | 
			
		||||
			if ($log === FALSE || count($log) < 1)
 | 
			
		||||
			{
 | 
			
		||||
				$commits[$count]['author'] = '';
 | 
			
		||||
				$commits[$count]['message'] = '';
 | 
			
		||||
				$commits[$count]['time'] = '';
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
			{
 | 
			
		||||
				$commits[$count]['author'] = $log[0]['author'];
 | 
			
		||||
				$commits[$count]['message'] = $log[0]['msg'];
 | 
			
		||||
				$commits[$count]['time'] = $log[0]['date'];
 | 
			
		||||
			}
 | 
			
		||||
	
 | 
			
		||||
			$count++;
 | 
			
		||||
		}	
 | 
			
		||||
	
 | 
			
		||||
		return $commits;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	function writeSvnCommit ($repo, $rev)
 | 
			
		||||
	{
 | 
			
		||||
		$log->type = 'svn-commit';
 | 
			
		||||
		$log->message = "{$repo},{$rev}";
 | 
			
		||||
		$this->write ($log);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	function write ($log)
 | 
			
		||||
	{
 | 
			
		||||
		$this->db->trans_begin ();
 | 
			
		||||
 | 
			
		||||
		$this->db->set ('type', $log->type);
 | 
			
		||||
		$this->db->set ('message', $log->message);
 | 
			
		||||
		$this->db->set ('createdon', date('Y-m-d H:i:s'));
 | 
			
		||||
		$this->db->insert ('log');
 | 
			
		||||
 | 
			
		||||
		if ($this->db->trans_status() === FALSE)
 | 
			
		||||
		{
 | 
			
		||||
			$this->db->trans_rollback ();
 | 
			
		||||
			return FALSE;
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			$this->db->trans_commit ();
 | 
			
		||||
			return TRUE;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	function delete ($log)
 | 
			
		||||
	{
 | 
			
		||||
		$this->db->trans_begin ();
 | 
			
		||||
 | 
			
		||||
		$this->db->where ('id', $log->id);
 | 
			
		||||
		$this->db->delete ('log');
 | 
			
		||||
 | 
			
		||||
		if ($this->db->trans_status() === FALSE)
 | 
			
		||||
		{
 | 
			
		||||
			$this->db->trans_rollback ();
 | 
			
		||||
			return FALSE;
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			$this->db->trans_commit ();
 | 
			
		||||
			return TRUE;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
@ -11,7 +11,7 @@ function render_wiki()
 | 
			
		||||
	creole_render_wiki (
 | 
			
		||||
		"user_home_mainarea_textpre",
 | 
			
		||||
		"user_home_mainarea_text",
 | 
			
		||||
		""
 | 
			
		||||
		"<?=dirname(dirname(current_url()))?>/user/home/"
 | 
			
		||||
	);
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
@ -78,6 +78,44 @@ foreach ($latest_projects as $project)
 | 
			
		||||
?>
 | 
			
		||||
</ul>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<div class="box">
 | 
			
		||||
<div class="boxtitle"><?=$this->lang->line('SVN commits')?></div>
 | 
			
		||||
<table id="user_home_mainarea_sidebar_svn_commits_table">
 | 
			
		||||
<?php 
 | 
			
		||||
	$xdot = $this->converter->AsciiToHex ('.');
 | 
			
		||||
	foreach ($svn_commits as $commit)
 | 
			
		||||
	{
 | 
			
		||||
		print '<tr class="odd">';
 | 
			
		||||
		print '<td>';
 | 
			
		||||
		print substr($commit['time'], 0, 10);
 | 
			
		||||
		print '</td>';
 | 
			
		||||
		print '<td>';
 | 
			
		||||
		print anchor (
 | 
			
		||||
			"/source/file/{$commit['repo']}/{$xdot}/{$commit['rev']}", 
 | 
			
		||||
			$commit['repo']);
 | 
			
		||||
		print '</td>';
 | 
			
		||||
		print '<td>';
 | 
			
		||||
		print anchor (	
 | 
			
		||||
			"/source/revision/{$commit['repo']}/{$xdot}/{$commit['rev']}", 
 | 
			
		||||
			$commit['rev']);
 | 
			
		||||
		print '</td>';
 | 
			
		||||
		print '<td>';
 | 
			
		||||
		print htmlspecialchars ($commit['author']);
 | 
			
		||||
		print '</td>';
 | 
			
		||||
		print '</tr>';
 | 
			
		||||
 | 
			
		||||
		print '<tr class="even">';
 | 
			
		||||
		print '<td colspan=4>';
 | 
			
		||||
		$sm = strtok (trim ($commit['message']), "\r\n");
 | 
			
		||||
		print htmlspecialchars ($sm);
 | 
			
		||||
		print '</td>';
 | 
			
		||||
		print '</tr>';
 | 
			
		||||
	}
 | 
			
		||||
?>
 | 
			
		||||
</table>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
</div> <!-- user_home_mainarea_sidebar -->
 | 
			
		||||
 | 
			
		||||
<div id="user_home_mainarea_text">
 | 
			
		||||
 | 
			
		||||
@ -25,6 +25,7 @@ function load_ini ($file)
 | 
			
		||||
		array ('login_model',                  'string',     'LdapLoginModel'),
 | 
			
		||||
		array ('sysadmin_userid',              'string',     ''),
 | 
			
		||||
		array ('max_upload_size',              'string',     '10000'), // kbytes
 | 
			
		||||
		array ('max_svn_commits',              'integer',    10),
 | 
			
		||||
		array ('max_latest_projects',          'integer',    10),
 | 
			
		||||
 | 
			
		||||
		array ('database_username',            'string',     ''),
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,27 @@
 | 
			
		||||
 * This file contains specific IDs for furthur customization.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/*----------------------------------------------- 
 | 
			
		||||
 * user home view 
 | 
			
		||||
 *-----------------------------------------------*/
 | 
			
		||||
#user_home_mainarea_sidebar {
 | 
			
		||||
	width: 25em;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#user_home_mainarea_sidebar_svn_commits_table {
 | 
			
		||||
	margin: 0;
 | 
			
		||||
	padding: 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#user_home_mainarea_sidebar_svn_commits_table tr.odd {
 | 
			
		||||
	background-color: #bbccef;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#user_home_mainarea_sidebar_svn_commits_table tr.even {
 | 
			
		||||
	background-color: inherit;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*----------------------------------------------- 
 | 
			
		||||
 * project file home view 
 | 
			
		||||
 *-----------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user