cakebot /vendors/shells/tasks/s_v_n_command.php

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