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
8 * Copyright 2013, Benoit Debaenst - TrivialDev
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 require_once $gfplugins.'scmhook/common/scmhook.class.php';
29 class commitTracker extends scmhook {
33 function __construct() {
34 $this->group = $GLOBALS['group'];
35 $this->name = "Commit Tracker";
36 $this->description = _('Every commit is pushed into related tracker or task.');
37 $this->classname = "commitTracker";
38 $this->hooktype = "post-receive";
39 $this->label = "scmgit";
40 $this->unixname = "committracker";
42 $this->command = '/usr/bin/php -d include_path='.ini_get('include_path').' '.forge_get_config('plugins_path').'/scmhook/library/'.
43 $this->label.'/hooks/'.$this->unixname.'/post.php "$1" "$2"';
46 function isAvailable() {
47 if ($this->group->usesTracker()) {
50 $this->disabledMessage = _('Hook not available due to missing dependency : Project not using tracker.');
54 function getDisabledMessage() {
55 return $this->disabledMessage;
58 function artifact_extra_detail($params) {
59 $DBResult = db_query_params('SELECT * FROM plugin_scmhook_scmgit_committracker_data_master, plugin_scmhook_scmgit_committracker_data_artifact
60 WHERE plugin_scmhook_scmgit_committracker_data_artifact.group_artifact_id = $1
61 AND plugin_scmhook_scmgit_committracker_data_master.holder_id = plugin_scmhook_scmgit_committracker_data_artifact.id
63 array($params['artifact_id']));
65 echo '<p class="error_msg">'._('Unable to retrieve data').'</p>';
67 $this->getCommitEntries($DBResult, $params['group_id']);
71 function task_extra_detail($params) {
72 $DBResult = db_query_params ('SELECT * FROM plugin_scmhook_scmgit_committracker_data_master, plugin_scmhook_scmgit_committracker_data_artifact
73 WHERE plugin_scmhook_scmgit_committracker_data_artifact.project_task_id=$1
74 AND plugin_scmhook_scmgit_committracker_data_master.holder_id=plugin_scmhook_scmgit_committracker_data_artifact.id
76 array($params['task_id']));
78 echo '<p class="error_msg">'._('Unable to retrieve data').'</p>';
80 $this->getCommitEntries($DBResult, $params['group_id']);
85 * It display a table with commit related to this tracker or task_extra_detail
87 * @param string $Query Query to be executed to get the commit entries.
88 * @param integer $group_id Group_id of the actual Group_id
91 function getCommitEntries($DBResult, $group_id) {
92 $group = group_get_object($group_id);
93 $Rows= db_numrows($DBResult);
97 echo '<h2>'._('Related GIT commits').'</h2>';
99 $title_arr = $this->getTitleArr();
100 echo $GLOBALS['HTML']->listTableTop($title_arr);
102 for ($i=0; $i<$Rows; $i++) {
103 $Row = db_fetch_array($DBResult);
104 echo '<tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'>'.
105 '<td>'. $this->getFileLink($group->getUnixName(),
106 $Row['file'],$Row['actual_version']). '</td>'.
107 '<td>'. date(_('Y-m-d'), $Row['git_date']).'</td>'.
108 '<td>'. $this->getDiffLink($group->getUnixName(),
110 $Row['prev_version'],
111 $Row['actual_version']).'</td>'.
112 '<td>'. $this->getActualVersionLink($group->getUnixName(),
113 $Row['file'], $Row['actual_version']).
115 <td>'. htmlspecialchars($Row['log_text']).'</td>
116 <td>'. util_make_link_u($Row['author'],
117 user_get_object_by_name($Row['author'])->getId(),
118 $Row['author']).'</td>
121 echo $GLOBALS['HTML']->listTableBottom();
127 * Return an array with titles of Box to display the entries
129 * @return Array The array containing the titles
132 function getTitleArr() {
134 $title_arr[]=_('Filename');
135 $title_arr[]=_('Date');
136 $title_arr[]=_('Previous Version');
137 $title_arr[]=_('Current Version');
138 $title_arr[]=_('Log Message');
139 $title_arr[]=_('Author');
144 * Return a link to the File in gitweb
146 * @param String $GroupName is the Name of the project
147 * @param String $FileName is the FileName ( with path )
148 * @param Int $LatestRevision is the last revision for the file
150 * @return String The string containing a link to the File in the gitweb
153 function getFileLink($GroupName, $FileName, $LatestRevision) {
154 return util_make_link ('/scm/viewvc.php'.$FileName .
155 '?root='.$GroupName.'&view=log&rev=' .
161 * Return a link to the File in viewcvs in the specified Version
163 * @param String $GroupName is the Name of the project
164 * @param String $FileName is the FileName ( with path )
165 * @param String $Version the version to retrieve
167 * @return String The string containing a link to the File in the viewcvs
170 function getActualVersionLink($GroupName, $FileName, $Version) {
171 return util_make_link ('/scm/viewvc.php'.$FileName .
172 '?root='.$GroupName.'&rev='.$Version,
177 * Return a link to the diff between two versions of a File in viewcvs
179 * @param String $GroupName is the Name of the project
180 * @param String $FileName is the FileName ( with path )
181 * @param String $PrevVersion First version to retrieve
182 * @param String $ActualVersion Second version to retrieve
184 * @return String The string containing a link to the File in the cvsweb
187 function getDiffLink($GroupName, $FileName, $PrevVersion, $ActualVersion) {
188 return util_make_link ('/scm/viewvc.php'.$FileName .
189 '?root='.$GroupName.'&r1='.$PrevVersion .
190 '&r2='.$ActualVersion,
191 _('Diff To').' '.$PrevVersion);