3 * scmhook commitTracker Plugin Class
4 * Copyright 2004, Francisco Gimeno <kikov @nospam@ kikov.org>
5 * Copyright 2005, Guillaume Smet <guillaume-gforge@smet.org>
6 * Copyright 2011, Franck Villaume - Capgemini
7 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once $gfplugins.'scmhook/common/scmhook.class.php';
28 class commitTracker extends scmhook {
29 function commitTracker() {
30 $this->name = "Commit Tracker";
31 $this->description = _('Every commit is pushed into related tracker or task.');
32 $this->classname = "commitTracker";
33 $this->hooktype = "post-commit";
34 $this->label = "scmsvn";
35 $this->unixname = "committracker";
37 $this->command = '/usr/bin/php -d include_path='.ini_get('include_path').' '.forge_get_config('plugins_path').'/scmhook/library/'.
38 $this->label.'/hooks/'.$this->unixname.'/post.php "$1" "$2"';
41 function artifact_extra_detail($params) {
42 $DBResult = db_query_params('SELECT * FROM plugin_scmhook_scmsvn_committracker_data_master, plugin_scmhook_scmsvn_committracker_data_artifact
43 WHERE plugin_scmhook_scmsvn_committracker_data_artifact.group_artifact_id = $1
44 AND plugin_scmhook_scmsvn_committracker_data_master.holder_id = plugin_scmhook_scmsvn_committracker_data_artifact.id
46 array($params['artifact_id']));
48 echo '<p class="error_msg">'._('Unable to retrieve data').'</p>';
50 $this->getCommitEntries($DBResult, $params['group_id']);
54 function task_extra_detail($params) {
55 $DBResult = db_query_params ('SELECT * FROM plugin_scmhook_scmsvn_committracker_data_master, plugin_scmhook_scmsvn_committracker_data_artifact
56 WHERE plugin_scmhook_scmsvn_committracker_data_artifact.project_task_id=$1
57 AND plugin_scmhook_scmsvn_committracker_data_master.holder_id=plugin_scmhook_scmsvn_committracker_data_artifact.id
59 array($params['task_id']));
61 echo '<p class="error_msg">'._('Unable to retrieve data').'</p>';
63 $this->getCommitEntries($DBResult, $params['group_id']);
68 * It display a table with commit related to this tracker or task_extra_detail
70 * @param string $Query Query to be executed to get the commit entries.
71 * @param integer $group_id Group_id of the actual Group_id
74 function getCommitEntries($DBResult, $group_id) {
75 $group = group_get_object($group_id);
76 $Rows= db_numrows($DBResult);
80 echo '<h2>'._('Related SVN commits').'</h2>';
82 $title_arr = $this->getTitleArr();
83 echo $GLOBALS['HTML']->listTableTop($title_arr);
85 for ($i=0; $i<$Rows; $i++) {
86 $Row = db_fetch_array($DBResult);
87 echo '<tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'>'.
88 '<td>'. $this->getFileLink($group->getUnixName(),
89 $Row['file'],$Row['actual_version']). '</td>'.
90 '<td>'. date(_('Y-m-d'), $Row['svn_date']).'</td>'.
91 '<td>'. $this->getDiffLink($group->getUnixName(),
94 $Row['actual_version']).'</td>'.
95 '<td>'. $this->getActualVersionLink($group->getUnixName(),
96 $Row['file'], $Row['actual_version']).
98 <td>'. htmlspecialchars($Row['log_text']).'</td>
99 <td>'. util_make_link_u($Row['author'],
100 user_get_object_by_name($Row['author'])->getId(),
101 $Row['author']).'</td>
104 echo $GLOBALS['HTML']->listTableBottom();
110 * Return an array with titles of Box to display the entries
112 * @return Array The array containing the titles
115 function getTitleArr() {
117 $title_arr[]=_('Filename');
118 $title_arr[]=_('Date');
119 $title_arr[]=_('Previous Version');
120 $title_arr[]=_('Current Version');
121 $title_arr[]=_('Log Message');
122 $title_arr[]=_('Author');
127 * Return a link to the File in svnweb
129 * @param String $GroupName is the Name of the project
130 * @param String $FileName is the FileName ( with path )
131 * @param Int $LatestRevision is the last revision for the file
133 * @return String The string containing a link to the File in the svnweb
136 function getFileLink($GroupName, $FileName, $LatestRevision) {
137 return util_make_link ('/scm/viewvc.php'.$FileName .
138 '?root='.$GroupName.'&view=log&rev=' .
144 * Return a link to the File in viewcvs in the specified Version
146 * @param String $GroupName is the Name of the project
147 * @param String $FileName is the FileName ( with path )
148 * @param String $Version the version to retrieve
150 * @return String The string containing a link to the File in the viewcvs
153 function getActualVersionLink($GroupName, $FileName, $Version) {
154 return util_make_link ('/scm/viewvc.php'.$FileName .
155 '?root='.$GroupName.'&rev='.$Version,
160 * Return a link to the diff between two versions of a File in viewcvs
162 * @param String $GroupName is the Name of the project
163 * @param String $FileName is the FileName ( with path )
164 * @param String $PrevVersion First version to retrieve
165 * @param String $ActualVersion Second version to retrieve
167 * @return String The string containing a link to the File in the cvsweb
170 function getDiffLink($GroupName, $FileName, $PrevVersion, $ActualVersion) {
171 return util_make_link ('/scm/viewvc.php'.$FileName .
172 '?root='.$GroupName.'&r1='.$PrevVersion .
173 '&r2='.$ActualVersion,
174 _('Diff To').' '.$PrevVersion);