3 * scmhook GitCommitTracker 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
9 * Copyright 2014,2016-2017, Franck Villaume - TrivialDev
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 require_once $gfplugins.'scmhook/common/scmhook.class.php';
30 class GitCommitTracker extends scmhook {
34 function __construct() {
35 $this->group = $GLOBALS['group'];
36 $this->name = "Commit Tracker";
37 $this->description = _('Every commit is pushed into related tracker or task.');
38 $this->classname = "commitTracker";
39 $this->hooktype = "post-receive";
40 $this->label = "scmgit";
41 $this->unixname = "committracker";
43 $this->command = '/usr/bin/php -d include_path='.ini_get('include_path').' '.forge_get_config('plugins_path').'/scmhook/library/'.
44 $this->label.'/hooks/'.$this->unixname.'/post.php $PARAMS $SCRIPTPATH';
47 function isAvailable() {
48 if (!$this->group->usesTracker()) {
49 $this->disabledMessage = _('Hook not available due to missing dependency')._(': ')._('Project not using tracker.');
55 function getDisabledMessage() {
56 return $this->disabledMessage;
59 function artifact_extra_detail(&$params) {
61 $DBResult = db_query_params('SELECT * FROM plugin_scmhook_scmgit_committracker_data_master, plugin_scmhook_scmgit_committracker_data_artifact
62 WHERE plugin_scmhook_scmgit_committracker_data_artifact.group_artifact_id = $1
63 AND plugin_scmhook_scmgit_committracker_data_master.holder_id = plugin_scmhook_scmgit_committracker_data_artifact.id
65 array($params['artifact_id']));
67 $return = $HTML->error_msg(_('Unable to retrieve data'));
69 $return = $this->getCommitEntries($DBResult, $params['group_id']);
71 if (isset($params['content'])) {
72 $params['content'] .= $return;
78 function task_extra_detail($params) {
80 $DBResult = db_query_params ('SELECT * FROM plugin_scmhook_scmgit_committracker_data_master, plugin_scmhook_scmgit_committracker_data_artifact
81 WHERE plugin_scmhook_scmgit_committracker_data_artifact.project_task_id = $1
82 AND plugin_scmhook_scmgit_committracker_data_master.holder_id = plugin_scmhook_scmgit_committracker_data_artifact.id
84 array($params['task_id']));
86 $return = $HTML->error_msg(_('Unable to retrieve data'));
88 $return = $this->getCommitEntries($DBResult, $params['group_id']);
90 if (isset($params['content'])) {
91 $params['content'] = $return;
98 * getCommitEntries - It display a table with commit related to this tracker or task_extra_detail
100 * @param string $DBResult Result of the commit entries.
101 * @param integer $group_id Group_id of the actual Group_id
104 function getCommitEntries($DBResult, $group_id) {
106 $groupObj = group_get_object($group_id);
107 $Rows = db_numrows($DBResult);
111 $return .= '<tr><td>';
112 $return .= html_e('h2', array(), _('Related Git commits'), false);
114 $title_arr = $this->getTitleArr($group_id);
115 $return .= $HTML->listTableTop($title_arr);
117 while ($Row = db_fetch_array($DBResult)) {
119 $cells[][] = $this->getFileLink($groupObj->getUnixName(), $Row['file'], $Row['actual_version']);
120 $cells[][] = date(_('Y-m-d'), $Row['git_date']);
121 $cells[][] = $this->getDiffLink($groupObj->getUnixName(), $Row['file'], $Row['prev_version'], $Row['actual_version']);
122 $cells[][] = $this->getActualVersionLink($groupObj->getUnixName(), $Row['file'], $Row['actual_version']);
123 $cells[][] = htmlspecialchars($Row['log_text']);
124 $commituser = user_get_object_by_name($Row['author']);
125 $cells[][] = util_display_user($commituser->getUnixName(), $commituser->getId(), $commituser->getRealname());
126 $return .= $HTML->multiTableRow(array(), $cells);
128 $return .= $HTML->listTableBottom();
129 $return .= '</td></tr>';
135 * getTitleArr - Return an array with titles of Box to display the entries
137 * @param integer $group_id Group_id of the actual Group_id
139 * @return Array $title_arr The array containing the titles
142 function getTitleArr($group_id) {
143 $title_arr = array();
144 $title_arr[] = _('File Name');
145 $title_arr[] = _('Date');
146 $title_arr[] = _('Previous Version');
147 $title_arr[] = _('Current Version');
148 $title_arr[] = _('Log Message');
149 $title_arr[] = _('Author');
154 * getFileLink - Return a link to the Filename
156 * @param String $GroupName is the Name of the project
157 * @param String $FileName is the FileName ( with path )
158 * @param Int $LatestRevision is the last revision for the file
160 * @return String $FileName The string containing a link to the File in the gitwe
163 function getFileLink($GroupName, $FileName, $LatestRevision) {
168 * getActualVersionLink - Return a link to the actual version File
170 * @param String $GroupName is the Name of the project
171 * @param String $FileName is the FileName (with path)
172 * @param String $Version the version to retrieve
174 * @return String $Version The string containing a link to the actual version File
177 function getActualVersionLink($GroupName, $FileName, $Version) {
182 * getDiffLink - Return a link to the old versions of a File
184 * @param String $GroupName is the Name of the project
185 * @param String $FileName is the FileName ( with path )
186 * @param String $PrevVersion First version to retrieve
187 * @param String $ActualVersion Second version to retrieve
189 * @return String $PrevVersion The string containing the old version File
192 function getDiffLink($GroupName, $FileName, $PrevVersion, $ActualVersion) {