diff --git a/codepot/etc/Makefile.am b/codepot/etc/Makefile.am index 29fef889..adb537b3 100644 --- a/codepot/etc/Makefile.am +++ b/codepot/etc/Makefile.am @@ -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) diff --git a/codepot/etc/Makefile.in b/codepot/etc/Makefile.in index 4987d24d..53eca2ae 100644 --- a/codepot/etc/Makefile.in +++ b/codepot/etc/Makefile.in @@ -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 diff --git a/codepot/etc/codepot.ini.in b/codepot/etc/codepot.ini.in index 30da4f07..6e16127c 100644 --- a/codepot/etc/codepot.ini.in +++ b/codepot/etc/codepot.ini.in @@ -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 ;------------------------------------------------------------------------------ diff --git a/codepot/etc/codepot.sql b/codepot/etc/codepot.sql index 7c8b5c22..d555dd7d 100644 --- a/codepot/etc/codepot.sql +++ b/codepot/etc/codepot.sql @@ -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; diff --git a/codepot/etc/post-commit b/codepot/etc/post-commit new file mode 100755 index 00000000..3ec8523f --- /dev/null +++ b/codepot/etc/post-commit @@ -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 $? diff --git a/codepot/etc/repo.sh b/codepot/etc/repo.sh index 5671524c..0b031c22 100755 --- a/codepot/etc/repo.sh +++ b/codepot/etc/repo.sh @@ -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}" } diff --git a/codepot/src/codepot/controllers/api.php b/codepot/src/codepot/controllers/api.php index 4f3e132a..fc11f406 100644 --- a/codepot/src/codepot/controllers/api.php +++ b/codepot/src/codepot/controllers/api.php @@ -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); + } } diff --git a/codepot/src/codepot/controllers/user.php b/codepot/src/codepot/controllers/user.php index 0a8919d9..07714886 100644 --- a/codepot/src/codepot/controllers/user.php +++ b/codepot/src/codepot/controllers/user.php @@ -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 () diff --git a/codepot/src/codepot/language/english/common_lang.php b/codepot/src/codepot/language/english/common_lang.php index cca41579..7faada35 100644 --- a/codepot/src/codepot/language/english/common_lang.php +++ b/codepot/src/codepot/language/english/common_lang.php @@ -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'; diff --git a/codepot/src/codepot/language/indonesian/common_lang.php b/codepot/src/codepot/language/indonesian/common_lang.php index 737d5a03..b9c62dd9 100644 --- a/codepot/src/codepot/language/indonesian/common_lang.php +++ b/codepot/src/codepot/language/indonesian/common_lang.php @@ -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'; diff --git a/codepot/src/codepot/language/korean/common_lang.php b/codepot/src/codepot/language/korean/common_lang.php index f484ba5a..1c2cc4ae 100644 --- a/codepot/src/codepot/language/korean/common_lang.php +++ b/codepot/src/codepot/language/korean/common_lang.php @@ -43,6 +43,7 @@ $lang['Size'] = '크기'; $lang['Source'] = '소스'; $lang['Summary'] = '요약'; $lang['System'] = '시스템'; +$lang['SVN commits'] = 'SVN 커밋'; $lang['Tag'] = '태그'; $lang['Text'] = '본문'; $lang['Time'] = '시간'; diff --git a/codepot/src/codepot/models/Makefile.am b/codepot/src/codepot/models/Makefile.am index 13197164..8149ca80 100644 --- a/codepot/src/codepot/models/Makefile.am +++ b/codepot/src/codepot/models/Makefile.am @@ -4,6 +4,7 @@ www_DATA = \ index.html \ ldaploginmodel.php \ loginmodel.php \ + logmodel.php \ projectmodel.php \ sitemodel.php \ subversionmodel.php \ diff --git a/codepot/src/codepot/models/Makefile.in b/codepot/src/codepot/models/Makefile.in index c48c275a..99b73f1f 100644 --- a/codepot/src/codepot/models/Makefile.in +++ b/codepot/src/codepot/models/Makefile.in @@ -167,6 +167,7 @@ www_DATA = \ index.html \ ldaploginmodel.php \ loginmodel.php \ + logmodel.php \ projectmodel.php \ sitemodel.php \ subversionmodel.php \ diff --git a/codepot/src/codepot/models/logmodel.php b/codepot/src/codepot/models/logmodel.php new file mode 100644 index 00000000..8effbf33 --- /dev/null +++ b/codepot/src/codepot/models/logmodel.php @@ -0,0 +1,126 @@ +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; + } + } +} + +?> diff --git a/codepot/src/codepot/views/user_home.php b/codepot/src/codepot/views/user_home.php index 08447190..024cd97a 100644 --- a/codepot/src/codepot/views/user_home.php +++ b/codepot/src/codepot/views/user_home.php @@ -11,7 +11,7 @@ function render_wiki() creole_render_wiki ( "user_home_mainarea_textpre", "user_home_mainarea_text", - "" + "/user/home/" ); } @@ -78,6 +78,44 @@ foreach ($latest_projects as $project) ?> + +
+
lang->line('SVN commits')?>
+ +converter->AsciiToHex ('.'); + foreach ($svn_commits as $commit) + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + } +?> +
'; + print substr($commit['time'], 0, 10); + print ''; + print anchor ( + "/source/file/{$commit['repo']}/{$xdot}/{$commit['rev']}", + $commit['repo']); + print ''; + print anchor ( + "/source/revision/{$commit['repo']}/{$xdot}/{$commit['rev']}", + $commit['rev']); + print ''; + print htmlspecialchars ($commit['author']); + print '
'; + $sm = strtok (trim ($commit['message']), "\r\n"); + print htmlspecialchars ($sm); + print '
+
+
diff --git a/codepot/src/config.php.in b/codepot/src/config.php.in index 0747e4f0..58027f7b 100644 --- a/codepot/src/config.php.in +++ b/codepot/src/config.php.in @@ -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', ''), diff --git a/codepot/src/css/project.css b/codepot/src/css/project.css index 3b657e03..273d2c79 100644 --- a/codepot/src/css/project.css +++ b/codepot/src/css/project.css @@ -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 *-----------------------------------------------*/