https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114639
Revision: 114639
Author: reedy
Date: 2012-03-31 01:04:58 +0000 (Sat, 31 Mar 2012)
Log Message:
-----------
Trim trailing whitespace and fix a few minor documentation bits
Modified Paths:
--------------
trunk/tools/gerrit-dippybird/dippy-bird.php
Modified: trunk/tools/gerrit-dippybird/dippy-bird.php
===================================================================
--- trunk/tools/gerrit-dippybird/dippy-bird.php 2012-03-30 23:12:28 UTC (rev
114638)
+++ trunk/tools/gerrit-dippybird/dippy-bird.php 2012-03-31 01:04:58 UTC (rev
114639)
@@ -39,7 +39,7 @@
'value' => false,
),
);
-
+
protected $validActions = array(
//'approve' => 'executeApprove',
//'verify' => 'executeVerify',
@@ -62,17 +62,17 @@
$msg = "There is something wrong in your arguments or
configuration.";
$this->bail( 1, $msg );
}
-
+
// determine the 'action' to take
$action = $this->getConfigOpt( 'action' );
$action_method = $this->getActionMethod( $action );
-
+
// fetch the results of the query
$results = $this->executeQuery();
-
+
// execute the action to take on the query results
$this->{$action_method}( $results );
-
+
echo "Thanks for playing!" . PHP_EOL;
echo "<3," . PHP_EOL;
echo "Dippy bird" . PHP_EOL;
@@ -99,22 +99,26 @@
$this->bail( $status, $msg );
}
}
-
+
+ /**
+ * @param array $results
+ * @return mixed
+ */
public function executeSubmit( $results ) {
// If there are less than two items in the array, there are no
changesets on which to operate
if ( count( $results ) < 2 ) {
// nothing to process
return;
}
-
+
// prepare to do... stuff
$submitted = 0;
$opts = array( 'port', 'server', 'username' );
$config_opts = $this->getConfigOptsByArray( $opts );
-
+
// get the patchset ids form the result set
$patchset_ids = self::extractPatchSetIds( $results );
-
+
// loop through patchsets and submit them one by one
foreach ( $patchset_ids as $patchset_id ) {
// prepare command to execute
@@ -123,7 +127,7 @@
if ( $this->getConfigOpt( 'verbose' ) ) {
echo "Executing: " . $cmd . PHP_EOL;
}
-
+
// should we do this for reals?!
if ( !$this->getConfigOpt( 'pretend' ) ) {
exec( escapeshellcmd( $cmd ), $cmd_results,
$status );
@@ -136,10 +140,10 @@
}
echo "$submitted changesets submitted." . PHP_EOL;
}
-
+
/**
* Extract patchset ids
- * @param array JSON representations of gerrit changesets
+ * @param array $results JSON representations of gerrit changesets
* @return array
*/
public static function extractPatchSetIds( $results ) {
@@ -153,9 +157,9 @@
return $patchset_ids;
}
- /**
+ /**
* Extract patchset id
- * @param string JSON representation of gerrit changeset
+ * @param string $result JSON representation of gerrit changeset
* @return mixed patchset id or null
*/
public static function extractPatchSetId( $result ) {
@@ -175,7 +179,7 @@
if ( empty( $config ) ) {
return;
}
-
+
// only set valid config opts
foreach ( $config as $key => $value ) {
if ( isset( $this->configOpts[ $key ] ) ) {
@@ -183,19 +187,19 @@
}
}
}
-
+
/**
* Load configuration options from an ini file
- * @param string Path to configuration file
+ * @param string $config_file Path to configuration file
*/
protected function loadConfiguration( $config_file ) {
$config = parse_ini_file( $config_file );
// do some option clean up....
-
+
$this->setConfigByArray( $config );
}
-
+
/**
* Handle runtime command line options
*/
@@ -208,7 +212,7 @@
}
$config = array();
-
+
foreach ( $user_opts as $key => $value ) {
switch ( $key ) {
case 'port':
@@ -249,10 +253,10 @@
break;
}
}
-
+
$this->setConfigByArray( $config );
}
-
+
/**
* Check sanity of configuration values
*
@@ -266,7 +270,7 @@
}
return true;
}
-
+
/**
* Get the 'long' options available
*/
@@ -275,7 +279,7 @@
"port:",
"server:",
"username:",
- "query:",
+ "query:",
"action:",
"pretend",
"help",
@@ -284,7 +288,7 @@
);
return $long_opts;
}
-
+
/**
* Get the 'short' options available
*/
@@ -300,7 +304,7 @@
$short_opts .= "d"; // debug
return $short_opts;
}
-
+
/**
* Fetch usage message
*/
@@ -316,14 +320,14 @@
Usage: php dippy-bird.php --username=<username> --server=<gerrit servername>
--port=<gerrit port> [--verbose] [--debug] [--help]
--action=<action> --query=<query>
-
+
Required parameters:
--username, -u Username you use to log in to Gerrit
--server, -s Hostname of the Gerrit server
--port, -P Port where Gerrit is running
--query, -q Gerrit query (See docs: http://bit.ly/H9bYiq)
--action, -a Action to take after running query
-
+
Optional options:
--pretend, -p Executes query but not action
--verbose, -v Run in 'verbose' mode
@@ -336,10 +340,11 @@
USAGE;
return $usage;
}
-
+
/**
* Print usage message and die
- * @param int Status code with which to exit
+ * @param int $status Status code with which to exit
+ * @param string $msg
*/
public function bail( $status = 0, $msg = null ) {
if ( !is_null( $msg ) ) {
@@ -349,14 +354,15 @@
echo PHP_EOL;
exit( intval( $status ) );
}
-
+
/**
* Fetch $this->configOpts
+ * @return array
*/
public function getConfigOpts() {
return $this->configOpts;
}
-
+
/**
* Fetch a specified configuration option
*
@@ -376,10 +382,10 @@
}
return null;
}
-
+
/**
* Fetch multiple config option values
- * @param array Config option names to fetch
+ * @param array $opts Config option names to fetch
* @return array Option name => value
*/
public function getConfigOptsByArray( array $opts ) {
@@ -389,7 +395,7 @@
}
return $config_opts;
}
-
+
/**
* Determine whether or not requested action is valid to take
*
@@ -403,10 +409,10 @@
}
return false;
}
-
- /**
+
+ /**
* Fetch the method name corresponding to a specific 'action'
- *
+ *
* If the action is not valid, fail and bail.
* @param string
* @return string
@@ -419,8 +425,8 @@
$msg .= "\t$action" . PHP_EOL;
}
$this->bail( 1, $msg );
- }
+ }
return $this->validActions[ $action ];
}
-
+
}
\ No newline at end of file
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs