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-2014, 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 $PARAMS $SCRIPTPATH';
46 function isAvailable() {
47 if (!$this->group->usesTracker()) {
48 $this->disabledMessage = _('Hook not available due to missing dependency: Project not using tracker.');
50 } elseif (!forge_get_config('use_ssh','scmgit')) {
51 $this->disabledMessage = _('Hook not available due to missing dependency: Forge not using SSH for Git.');
57 function getDisabledMessage() {
58 return $this->disabledMessage;
61 function artifact_extra_detail($params) {
62 $DBResult = db_query_params('SELECT * FROM plugin_scmhook_scmgit_committracker_data_master, plugin_scmhook_scmgit_committracker_data_artifact
63 WHERE plugin_scmhook_scmgit_committracker_data_artifact.group_artifact_id = $1
64 AND plugin_scmhook_scmgit_committracker_data_master.holder_id = plugin_scmhook_scmgit_committracker_data_artifact.id
66 array($params['artifact_id']));
68 echo '<p class="error_msg">'._('Unable to retrieve data').'</p>';
70 $this->getCommitEntries($DBResult, $params['group_id']);
74 function task_extra_detail($params) {
75 $DBResult = db_query_params ('SELECT * FROM plugin_scmhook_scmgit_committracker_data_master, plugin_scmhook_scmgit_committracker_data_artifact
76 WHERE plugin_scmhook_scmgit_committracker_data_artifact.project_task_id=$1
77 AND plugin_scmhook_scmgit_committracker_data_master.holder_id=plugin_scmhook_scmgit_committracker_data_artifact.id
79 array($params['task_id']));
81 echo '<p class="error_msg">'._('Unable to retrieve data').'</p>';
83 $this->getCommitEntries($DBResult, $params['group_id']);
88 * getCommitEntries - It display a table with commit related to this tracker or task_extra_detail
90 * @param string $DBResult Result of the commit entries.
91 * @param integer $group_id Group_id of the actual Group_id
94 function getCommitEntries($DBResult, $group_id) {
95 $group = group_get_object($group_id);
96 $Rows= db_numrows($DBResult);
100 echo '<h2>'._('Related Git commits').'</h2>';
102 $title_arr = $this->getTitleArr($group_id);
103 echo $GLOBALS['HTML']->listTableTop($title_arr);
105 for ($i=0; $i<$Rows; $i++) {
106 $Row = db_fetch_array($DBResult);
107 echo '<tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'>'.
108 '<td>'. $this->getFileLink($group->getUnixName(),
109 $Row['file'],$Row['actual_version']). '</td>'.
110 '<td>'. date(_('Y-m-d'), $Row['git_date']).'</td>'.
111 '<td>'. $this->getDiffLink($group->getUnixName(),
113 $Row['prev_version'],
114 $Row['actual_version']).'</td>'.
115 '<td>'. $this->getActualVersionLink($group->getUnixName(),
116 $Row['file'], $Row['actual_version']).
118 <td>'. htmlspecialchars($Row['log_text']).'</td>
119 <td>'. util_make_link_u($Row['author'],
120 user_get_object_by_name($Row['author'])->getId(),
121 $Row['author']).'</td>
124 echo $GLOBALS['HTML']->listTableBottom();
130 * getTitleArr - Return an array with titles of Box to display the entries
132 * @param integer $group_id Group_id of the actual Group_id
134 * @return Array $title_arr The array containing the titles
137 function getTitleArr($group_id) {
139 $title_arr[]=_('Filename (<a href="/scm/browser.php?group_id='.$group_id.'">Broswe</a>)');
140 $title_arr[]=_('Date');
141 $title_arr[]=_('Previous Version');
142 $title_arr[]=_('Current Version');
143 $title_arr[]=_('Log Message');
144 $title_arr[]=_('Author');
149 * getFileLink - Return a link to the Filename
151 * @param String $GroupName is the Name of the project
152 * @param String $FileName is the FileName ( with path )
153 * @param Int $LatestRevision is the last revision for the file
155 * @return String $FileName The string containing a link to the File in the gitwe
158 function getFileLink($GroupName, $FileName, $LatestRevision) {
163 * getActualVersionLink - Return a link to the actual version File
165 * @param String $GroupName is the Name of the project
166 * @param String $FileName is the FileName ( with path )
167 * @param String $Version the version to retrieve
169 * @return String $Version The string containing a link to the actual version File
172 function getActualVersionLink($GroupName, $FileName, $Version) {
177 * getDiffLink - Return a link to the old versions of a File
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 $PrevVersion The string containing the old version File
187 function getDiffLink($GroupName, $FileName, $PrevVersion, $ActualVersion) {