├── .gitignore ├── .travis.yml ├── DataCollector └── GitDataCollector.php ├── DependencyInjection ├── Configuration.php └── SymfonyDebugToolbarGitExtension.php ├── LICENCE ├── README.md ├── Resources ├── config │ └── container.yml └── views │ ├── Collector │ └── git.html.twig │ └── Icons │ └── git.svg.twig ├── SymfonyDebugToolbarGit.php ├── SymfonyDebugToolbarGit.png ├── composer.json ├── phpunit.xml.dist ├── symfony_toolbar_2-8.png └── tests └── GitDataCollectorTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | composer.phar 2 | composer.lock 3 | vendor/ 4 | phpunit.phar 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.3 5 | - 5.4 6 | - 5.5 7 | - 5.6 8 | - 7 9 | - hhvm 10 | 11 | env: 12 | - FRAMEWORK_BUNDLE="~2.3" TWIG_BUNDLE_VERSION="~2.0" TWIG_VERSION="~1.6" 13 | 14 | before_script: 15 | - composer self-update 16 | - composer require symfony/framework-bundle:${FRAMEWORK_BUNDLE} 17 | - composer require symfony/twig-bundle:${TWIG_BUNDLE_VERSION} 18 | - composer require twig/twig:${TWIG_VERSION} 19 | -------------------------------------------------------------------------------- /DataCollector/GitDataCollector.php: -------------------------------------------------------------------------------- 1 | data['repositoryCommitUrl'] = $repositoryCommitUrl; 22 | } 23 | 24 | /** 25 | * {@inheritdoc} 26 | */ 27 | public function reset() 28 | { 29 | $this->data = []; 30 | } 31 | 32 | /** 33 | * Collect Git data for DebugBar (branch,commit,author,email,merge,date,message) 34 | * 35 | * @param Request $request 36 | * @param Response $response 37 | * @param \Exception $exception 38 | */ 39 | public function collect(Request $request, Response $response, \Exception $exception = null) 40 | { 41 | 42 | $fs = new Filesystem(); 43 | 44 | // is there a web directory ? 45 | 46 | if ($fs->exists('../web') || $fs->exists('../public_html') || $fs->exists('../public')) { 47 | $gitPath = '../.git'; 48 | } else { 49 | // unit tests 50 | $gitPath = '.git'; 51 | } 52 | 53 | // if there is no .git directory 54 | if (!$fs->exists($gitPath)) { 55 | $this->data['gitData'] = false; 56 | return; 57 | } 58 | 59 | // get latest commit information 60 | exec("git log -1", $data); 61 | 62 | if (isset($data) && !empty($data)) { 63 | 64 | // there is some information 65 | $this->data['gitData'] = true; 66 | 67 | foreach ($data as $d) { 68 | 69 | if (strpos($d, 'commit') === 0) { 70 | 71 | // commit Id 72 | 73 | $this->data['commit'] = substr($d, 7); 74 | 75 | } elseif (strpos($d, 'Author') === 0) { 76 | 77 | // author and email 78 | 79 | preg_match('$Author: ([^<]+)<(.+)>$', $d, $author); 80 | 81 | if (isset($author[1])) { 82 | $this->data['author'] = trim($author[1]); 83 | } 84 | if (isset($author[2])) { 85 | $this->data['email'] = $author[2]; 86 | } 87 | 88 | } elseif (strpos($d, 'Date') === 0) { 89 | 90 | $date = trim(substr($d, 5)); // ddd mmm n hh:mm:ss yyyy +gmt 91 | 92 | // date of commit 93 | $dateCommit = date_create($date); 94 | 95 | // actual date at runtime 96 | $dateRuntime = new \DateTime(); 97 | $dateNow = date_create($dateRuntime->format('Y-m-d H:i:s')); 98 | 99 | // difference 100 | $time = date_diff($dateCommit, $dateNow); 101 | 102 | // static time difference : minutes and seconds 103 | $this->data['timeCommitIntervalMinutes'] = $time->format('%y')*365*24*60+$time->format('%m')*30*24*60+$time->format('%d')*24*60+$time->format('%h')*60+$time->format('%i'); 104 | $this->data['timeCommitIntervalSeconds'] = $time->format('%s'); 105 | 106 | // full readable date 107 | $this->data['date'] = $date; 108 | 109 | } elseif (strpos($d, 'Merge') === 0) { 110 | 111 | // merge information 112 | 113 | $this->data['merge'] = trim(substr($d, 6)); 114 | 115 | } else { 116 | 117 | // commit message 118 | 119 | $this->data['message'] = trim($d); 120 | 121 | } 122 | 123 | } 124 | 125 | unset($data); 126 | 127 | exec("git status", $data); 128 | 129 | if (isset($data[0])) { 130 | 131 | if (strstr($data[0], 'On branch')) { 132 | 133 | // branch name 134 | 135 | $this->data['branch'] = trim(substr($data[0], strpos($data[0], 'On branch')+9)); 136 | 137 | } 138 | } 139 | 140 | } else { 141 | 142 | // no git data 143 | 144 | $this->data['gitData'] = false; 145 | 146 | } 147 | 148 | 149 | } 150 | 151 | /** 152 | * true if there is some data : used by the view 153 | * 154 | * @return string 155 | */ 156 | public function getGitData() 157 | { 158 | 159 | return $this->getData('gitData'); 160 | 161 | } 162 | 163 | /** 164 | * Actual branch name 165 | * 166 | * @return string 167 | */ 168 | public function getBranch() 169 | { 170 | 171 | return $this->getData('branch'); 172 | 173 | } 174 | 175 | /** 176 | * Commit ID 177 | * 178 | * @return string 179 | */ 180 | public function getCommit() 181 | { 182 | 183 | return $this->getData('commit'); 184 | 185 | } 186 | 187 | /** 188 | * Merge information 189 | * 190 | * @return string 191 | */ 192 | public function getMerge() 193 | { 194 | 195 | return $this->getData('merge'); 196 | 197 | } 198 | 199 | /** 200 | * Author 201 | * 202 | * @return string 203 | */ 204 | public function getAuthor() 205 | { 206 | 207 | return $this->getData('author'); 208 | 209 | } 210 | 211 | /** 212 | * Author's email 213 | * 214 | * @return string 215 | */ 216 | public function getEmail() 217 | { 218 | 219 | return $this->getData('email'); 220 | 221 | } 222 | 223 | /** 224 | * Commit date 225 | * 226 | * @return string 227 | */ 228 | public function getDate() 229 | { 230 | 231 | return $this->getData('date'); 232 | 233 | } 234 | 235 | /** 236 | * Minutes since last commit 237 | * 238 | * @return string 239 | */ 240 | public function getTimeCommitIntervalMinutes() 241 | { 242 | 243 | return $this->getData('timeCommitIntervalMinutes'); 244 | 245 | } 246 | 247 | /** 248 | * Seconds since latest commit 249 | * 250 | * @return string 251 | */ 252 | public function getTimeCommitIntervalSeconds() 253 | { 254 | 255 | return $this->getData('timeCommitIntervalSeconds'); 256 | 257 | } 258 | 259 | /** 260 | * Commit message 261 | * 262 | * @return string 263 | */ 264 | public function getMessage() 265 | { 266 | 267 | return $this->getData('message'); 268 | 269 | } 270 | 271 | /** 272 | * Commit URL 273 | * 274 | * @return string 275 | */ 276 | public function getCommitUrl() 277 | { 278 | 279 | return $this->data['repositoryCommitUrl']; 280 | 281 | } 282 | 283 | /** 284 | * Checks and returns the data 285 | * 286 | * @param string $data 287 | * @return string 288 | */ 289 | private function getData($data) 290 | { 291 | 292 | return (isset($this->data[$data])) ? $this->data[$data] : ''; 293 | 294 | } 295 | 296 | /** 297 | * DataCollector name : used by service declaration into container.yml 298 | * 299 | * @return string 300 | */ 301 | public function getName() 302 | { 303 | 304 | return 'data-collector_git'; 305 | 306 | } 307 | 308 | /** 309 | * change the icon color depending on the kernel version 310 | * 311 | * #3f3f3f < 2.8 312 | * #AAAAAA >= 2.8 313 | * 314 | * @return string 315 | */ 316 | final public function getIconColor() 317 | { 318 | if ((float) $this->getSymfonyVersion() >= 2.8) { 319 | return $this->data['iconColor'] = '#AAAAAA'; 320 | } 321 | return $this->data['iconColor'] = '#3F3F3F'; 322 | } 323 | 324 | /** 325 | * @return string 326 | */ 327 | private function getSymfonyVersion() 328 | { 329 | $symfonyVersion = \Symfony\Component\HttpKernel\Kernel::VERSION; 330 | $symfonyVersion = explode('.', $symfonyVersion, -1); 331 | $symfonyMajorMinorVersion = implode('.', $symfonyVersion); 332 | return $symfonyMajorMinorVersion; 333 | } 334 | 335 | } 336 | -------------------------------------------------------------------------------- /DependencyInjection/Configuration.php: -------------------------------------------------------------------------------- 1 | root('symfony_debug_toolbar_git'); 21 | 22 | $rootNode 23 | ->children() 24 | ->scalarNode('repository_commit_url') 25 | ->end() 26 | ; 27 | 28 | return $treeBuilder; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /DependencyInjection/SymfonyDebugToolbarGitExtension.php: -------------------------------------------------------------------------------- 1 | processConfiguration($configuration, $configs); 23 | 24 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 25 | $loader->load('container.yml'); 26 | 27 | $container->setParameter('symfony_debug_toolbar_git.repository_commit_url', $config['repository_commit_url']); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Kendrick 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Symfony Debug Toolbar Git 2 | ========================= 3 | 4 | [](https://insight.sensiolabs.com/projects/08698266-b800-4ca4-bb20-8ceb65b3f31b) 5 | 6 | [](https://packagist.org/packages/kendrick/symfony-debug-toolbar-git) [](https://packagist.org/packages/kendrick/symfony-debug-toolbar-git) [](https://packagist.org/packages/kendrick/symfony-debug-toolbar-git) [](https://packagist.org/packages/kendrick/symfony-debug-toolbar-git) 7 | 8 | [](https://packagist.org/packages/kendrick/symfony-debug-toolbar-git) [](https://packagist.org/packages/kendrick/symfony-debug-toolbar-git) 9 | 10 | [](https://travis-ci.org/kendrick-k/symfony-debug-toolbar-git) [](https://scrutinizer-ci.com/g/kendrick-k/symfony-debug-toolbar-git/) [](https://scrutinizer-ci.com/g/kendrick-k/symfony-debug-toolbar-git/) 11 | [](https://www.versioneye.com/user/projects/57e3991379806f00398308e9) 12 | 13 | ## Symfony toolbar add-on 14 | 15 | ### Get the latest git commit into Symfony debug toolbar 16 | 17 | And visualize quickly the latest commit into your repository by clicking on the **Commit ID**. 18 | 19 |  20 | 21 |  22 | 23 | Information displayed : 24 | 25 | + **Branch** : active branch 26 | + **Time since last commit** : time since last commit at page generation 27 | 28 | 1. less than one hour : minutes + seconds | colored in green, then in red : 29 | 2. more than one hour : hour(s) 30 | 3. more than 24h : count in days 31 | 4. more than 1 month : count in months 32 | 33 | Useful for local development but also for a continuous integration (CI) process on a development server. 34 | 35 | If no git repository have been initiated, there will be no display into the toolbar. 36 | 37 | ### Status information : mouse over 38 | 39 | Information displayed : 40 | 41 | + **Commit ID** : links to the commit URL on your repository (Github, Bitbucket..), base url is to set into repository_commit_url parameter 42 | + **Merge** : merge IDs if there is 43 | + **Author** 44 | + **Email** : email with active link 45 | + **Date** : full date of latest commit 46 | + **Commit message** 47 | 48 | ## Installation 49 | 50 | ### Composer 51 | 52 | composer require kendrick/symfony-debug-toolbar-git 53 | 54 | ### Register into AppKernel 55 | 56 | app/AppKernel.php : 57 | 58 | if (in_array($this->getEnvironment(), array('dev', 'test'))) { 59 | [...] 60 | $bundles[] = new Kendrick\SymfonyDebugToolbarGit\SymfonyDebugToolbarGit(); 61 | 62 | ### Parameters 63 | 64 | app/config/config_dev.yml : 65 | 66 | symfony_debug_toolbar_git: 67 | repository_commit_url: "" 68 | 69 | repository_commit_url, ex : *https://bitbucket.org/team/project/commits/* or *https://github.com/user/project/commit/* 70 | 71 | ## More tools 72 | 73 | Google Analytics API v4 Symfony bundle : https://github.com/mediafigaro/google-analytics-api-symfony 74 | -------------------------------------------------------------------------------- /Resources/config/container.yml: -------------------------------------------------------------------------------- 1 | parameters: 2 | symfony_debug_toolbar_git.data_collector.template: "SymfonyDebugToolbarGit:Collector:git" 3 | 4 | services: 5 | data_collector.datacollector_git: 6 | class: Kendrick\SymfonyDebugToolbarGit\DataCollector\GitDataCollector 7 | arguments: ["%symfony_debug_toolbar_git.repository_commit_url%"] 8 | tags: 9 | - { name: data_collector, template: "%symfony_debug_toolbar_git.data_collector.template%", id: "datacollector_git" } 10 | -------------------------------------------------------------------------------- /Resources/views/Collector/git.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'WebProfilerBundle:Profiler:layout.html.twig' %} 2 | 3 | {% block toolbar %} 4 | 5 | {% if collector.gitData %} 6 |
71 | {% endif %} 72 | 73 | {% endblock %} 74 | 75 | {% block head %} 76 | 77 | {% endblock %} 78 | 79 | {% block menu %} 80 | 81 | {% endblock %} 82 | 83 | {% block panel %} 84 | 85 | {% endblock %} 86 | -------------------------------------------------------------------------------- /Resources/views/Icons/git.svg.twig: -------------------------------------------------------------------------------- 1 | 13 | -------------------------------------------------------------------------------- /SymfonyDebugToolbarGit.php: -------------------------------------------------------------------------------- 1 | =2.3", 15 | "symfony/twig-bundle": ">=2.0", 16 | "twig/twig": ">=1.6" 17 | }, 18 | "require-dev": { 19 | "phpunit/phpunit": "6.*" 20 | }, 21 | "autoload": { 22 | "psr-4": { 23 | "Kendrick\\SymfonyDebugToolbarGit\\": "." 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 |