You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gen-coverage-badge.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * @author Thomas Müller <thomas.mueller@tmit.eu>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. if (!isset($argv[1])) {
  22. echo "Clover file is missing" . PHP_EOL;
  23. exit;
  24. }
  25. try {
  26. $cloverFile = $argv[1];
  27. $doc = simplexml_load_file($cloverFile);
  28. $metrics = [];
  29. foreach ($doc->project->metrics->attributes() as $k => $v) {
  30. $metrics[$k] = $v->__toString();
  31. }
  32. $c0 = $metrics['coveredmethods'] / $metrics['methods'];
  33. $c1 = $metrics['coveredelements'] / $metrics['elements'];
  34. $c2 = $metrics['coveredstatements'] / $metrics['statements'];
  35. echo $c0 . PHP_EOL;
  36. echo $c1 . PHP_EOL;
  37. echo $c2 . PHP_EOL;
  38. $percent = (int)($c2 * 100);
  39. $color = 'red';
  40. if ($percent >= 50) {
  41. $color = 'yellow';
  42. }
  43. if ($percent >= 75) {
  44. $color = 'green';
  45. }
  46. $content = file_get_contents("https://img.shields.io/badge/coverage-$percent%-$color.svg");
  47. file_put_contents('coverage.svg', $content);
  48. } catch (Exception $ex) {
  49. echo $ex->getMessage() . PHP_EOL;
  50. $content = file_get_contents("https://img.shields.io/badge/coverage-ERROR-red.svg");
  51. file_put_contents('coverage.svg', $content);
  52. }