PageRenderTime 49ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/vendors/shells/tasks/s_v_n_command.php

https://bitbucket.org/cakephp/cakebot
PHP | 106 lines | 41 code | 0 blank | 65 comment | 7 complexity | 006b28443e4f630109971e3044bd09e9 MD5 | raw file
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * Short description for file.
  5. *
  6. * Long description for file
  7. *
  8. * PHP versions 4 and 5
  9. *
  10. * Copyright 2005-2008, Cake Software Foundation, Inc.
  11. * 1785 E. Sahara Avenue, Suite 490-204
  12. * Las Vegas, Nevada 89104
  13. *
  14. * Licensed under The MIT License
  15. * Redistributions of files must retain the above copyright notice.
  16. *
  17. * @filesource
  18. * @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
  19. * @link http://www.cakefoundation.org/projects/info/cakebot
  20. * @package cakebot
  21. * @subpackage cakebot
  22. * @since cakebot v (1.0)
  23. * @version $Revision$
  24. * @modifiedby $LastChangedBy$
  25. * @lastmodified $Date$
  26. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  27. */
  28. /**
  29. * CakeBot plugin so that you can call ~svn and get the latest svn revision's number and message
  30. *
  31. *
  32. * @package cakebot
  33. * @subpackage cakebot.vendors.shells.tasks
  34. */
  35. App::import('Core', 'HttpSocket');
  36. App::import('Core', 'xml');
  37. class SVNCommandTask extends Object {
  38. /**
  39. * Not implemented
  40. *
  41. * @return void
  42. * @access public
  43. */
  44. function startup() {}
  45. /**
  46. * Not implemented
  47. *
  48. * @return void
  49. * @access public
  50. */
  51. function initialize() {}
  52. /**
  53. * Not implemented
  54. *
  55. * @return void
  56. * @access public
  57. */
  58. function loadTasks() {}
  59. /**
  60. * Function called by Bot to get the listing from the svn server
  61. *
  62. * @return string message for the user/channel
  63. * @access public
  64. */
  65. function execute() {
  66. if (function_exists("svn_log")) {
  67. if (func_num_args() > 1) {
  68. $args = func_get_args();
  69. $log = $this->svn_log_limit ( "https://svn.cakephp.org/repo/branches/1.2.x.x/", $args[1] );
  70. if ($log) {
  71. $lastRevision = $log[0]['rev'];
  72. return "Revision {$log[0]['rev']} ({$log[0]['author']}): {$log[0]['msg']}";
  73. } else {
  74. return "Revision $args[1] is not a valid revision";
  75. }
  76. } else {
  77. $log = $this->svn_log_limit ( "https://svn.cakephp.org/repo/branches/1.2.x.x/" );
  78. $lastRevision = $log[0]['rev'];
  79. return "Revision {$log[0]['rev']} ({$log[0]['author']}): {$log[0]['msg']}";
  80. }
  81. } else {
  82. return "svn is https://svn.cakephp.org/repo/";
  83. }
  84. }
  85. /**
  86. * Ripped from http://php.oregonstate.edu/manual/en/function.svn-log.php get the limited log
  87. *
  88. * @param string SVN url to check
  89. * @return mixed array of svn_log variables
  90. * @access public
  91. */
  92. function svn_log_limit($repos_url, $rev = null) {
  93. $limit = 1;
  94. // -q flag used to prevent server from sending log messages
  95. $revision = ($rev == null ? "" : "-r $rev");
  96. $output = shell_exec("svn log -q {$revision} --limit $limit $repos_url");
  97. preg_match_all('/^r(\d+) /m', $output, $matches);
  98. $ret = array();
  99. foreach ($matches[1] as $rev) {
  100. $log = svn_log($repos_url, (int) $rev);
  101. $ret[] = $log[0]; // log is only one item long
  102. }
  103. return $ret;
  104. }
  105. }
  106. ?>