Merge branch 4.5 into master
[civicrm-core.git] / bin / givi
index da9f07da825bc39298338600fb5811f5ce87436b..727227b93e1a97fd5491b96aad46f80ae712b063 100755 (executable)
--- a/bin/givi
+++ b/bin/givi
 class DirStack {
   protected $dirs;
 
+  /**
+   * @param array $dirs
+   */
   function __construct($dirs = array()) {
     $this->dirs = $dirs;
   }
 
+  /**
+   * @param $dir
+   *
+   * @throws Exception
+   */
   function push($dir) {
     $this->dirs[] = getcwd();
     if (!chdir($dir)) {
@@ -43,7 +51,7 @@ class PullRequest {
    */
   public static function get($url, $repos) {
     foreach ($repos as $repo => $relPath) {
-      if (preg_match("/^https:\/\/github.com\/(.*)\/(civicrm-{$repo})\/pull\/([0-9]+)$/", $url, $matches)) {
+      if (preg_match("/^https:\/\/github.com\/(.*)\/(civicrm-{$repo})\/pull\/([0-9]+)(|\/commits|\/files)$/", $url, $matches)) {
         list ($full, $githubUser, $githubRepo, $githubPr) = $matches;
 
         $pr = new PullRequest();
@@ -66,6 +74,9 @@ class PullRequest {
 
   protected $data;
 
+  /**
+   * @return mixed
+   */
   public function getNumber() {
     return $this->data->number;
   }
@@ -85,6 +96,9 @@ class PullRequest {
   }
 }
 
+/**
+ * Class Givi
+ */
 class Givi {
 
   /**
@@ -167,6 +181,9 @@ class Givi {
    */
   protected $dirStack;
 
+  /**
+   *
+   */
   function __construct() {
     $this->dirStack = new DirStack();
     $this->repos = array(
@@ -178,6 +195,11 @@ class Givi {
     );
   }
 
+  /**
+   * @param $args
+   *
+   * @throws Exception
+   */
   function main($args) {
     if (!$this->parseOptions($args)) {
       printf("Error parsing arguments\n");
@@ -350,6 +372,11 @@ class Givi {
     echo "local branches.\n";
   }
 
+  /**
+   * @param null $baseBranch
+   *
+   * @return bool
+   */
   function doCheckoutAll($baseBranch = NULL) {
     if (!$baseBranch) {
       return $this->returnError("Missing <branch>\n");
@@ -366,6 +393,9 @@ class Givi {
     return TRUE;
   }
 
+  /**
+   * @return bool
+   */
   function doStatusAll() {
     foreach ($this->repos as $repo => $relPath) {
       $this->run($repo, $relPath, 'git', 'status');
@@ -373,6 +403,11 @@ class Givi {
     return TRUE;
   }
 
+  /**
+   * @param null $baseBranch
+   *
+   * @return bool
+   */
   function doBegin($baseBranch = NULL) {
     if (!$baseBranch) {
       return $this->returnError("Missing <base-branch>\n");
@@ -400,6 +435,12 @@ class Givi {
     return TRUE;
   }
 
+  /**
+   * @param null $baseBranch
+   *
+   * @return bool
+   * @throws Exception
+   */
   function doResume($baseBranch = NULL) {
     if (!$baseBranch) {
       return $this->returnError("Missing <base-branch>\n");
@@ -426,8 +467,13 @@ class Givi {
     return TRUE;
   }
 
+  /**
+   * @param null $baseBranch
+   *
+   * @return bool
+   */
   function doReview($baseBranch = NULL) {
-    if (! $this->doCheckoutAll($baseBranch)) {
+    if (!$this->doCheckoutAll($baseBranch)) {
       return FALSE;
     }
 
@@ -439,7 +485,8 @@ class Givi {
       $pullRequest = PullRequest::get($prUrl, $this->repos);
       if ($pullRequest) {
         $pullRequests[] = $pullRequest;
-      } else {
+      }
+      else {
         return $this->returnError("Invalid pull-request URL: $prUrl");
       }
     }
@@ -491,6 +538,12 @@ class Givi {
   }
   */
 
+  /**
+   * @param $newBranchRepo
+   * @param $newBranchNames
+   *
+   * @return bool
+   */
   function doPush($newBranchRepo, $newBranchNames) {
     if (!$newBranchRepo) {
       return $this->returnError("Missing <remote>\n");
@@ -499,14 +552,15 @@ class Givi {
       return $this->returnError("Missing <branch>[:<branch>]\n");
     }
     if (FALSE !== strpos($newBranchNames, ':')) {
-      list ($newBranchFromName,$newBranchToName) = explode(':', $newBranchNames);
+      list ($newBranchFromName, $newBranchToName) = explode(':', $newBranchNames);
       foreach ($this->repos as $repo => $relPath) {
         $filteredFromName = $this->filterBranchName($repo, $newBranchFromName);
         $filteredToName = $this->filterBranchName($repo, $newBranchToName);
 
         $this->run($repo, $relPath, 'git', 'push', $newBranchRepo, $filteredFromName . ':' . $filteredToName);
       }
-    } else {
+    }
+    else {
       foreach ($this->repos as $repo => $relPath) {
         $filteredName = $this->filterBranchName($repo, $newBranchNames);
         $this->run($repo, $relPath, 'git', 'push', $newBranchRepo, $filteredName);
@@ -534,6 +588,9 @@ class Givi {
    * FIXME: only supports $refs like "foo" (implicit origin) or "myremote/foo"
    *
    * @param $ref
+   * @param string $defaultRemote
+   *
+   * @throws Exception
    * @return array
    */
   function parseBranchRepo($ref, $defaultRemote = 'origin') {
@@ -554,8 +611,10 @@ class Givi {
    *
    * Any items after $command will be escaped and added to $command
    *
+   * @param $repoName
    * @param string $runDir
    * @param string $command
+   *
    * @return string
    */
   function run($repoName, $runDir, $command) {
@@ -573,7 +632,8 @@ class Givi {
     printf("\n\n\nRUN [%s]: %s\n", $repoName, $command);
     if ($this->dryRun) {
       $r = NULL;
-    } else {
+    }
+    else {
       $r = system($command);
     }
 
@@ -589,6 +649,8 @@ class Givi {
 
   /**
    * @param string $default branch to use by default
+   * @param $overrides
+   *
    * @return array ($repoName => $gitRef)
    */
   function resolveBranches($default, $overrides) {
@@ -601,6 +663,12 @@ class Givi {
     return $branches;
   }
 
+  /**
+   * @param $repoName
+   * @param $branchName
+   *
+   * @return string
+   */
   function filterBranchName($repoName, $branchName) {
     if ($branchName == '') {
       return '';
@@ -617,6 +685,8 @@ class Givi {
   /**
    * @param string $filter e.g. "all" or "repo1,repo2"
    * @param array $repos ($repoName => $repoDir)
+   *
+   * @throws Exception
    * @return array ($repoName => $repoDir)
    */
   function filterRepos($filter, $repos) {
@@ -636,6 +706,11 @@ class Givi {
     return $repos;
   }
 
+  /**
+   * @param $message
+   *
+   * @return bool
+   */
   function returnError($message) {
     echo "\nERROR: ", $message, "\n\n";
     $this->doHelp();
@@ -643,12 +718,22 @@ class Givi {
   }
 }
 
+/**
+ * Class HttpClient
+ */
 class HttpClient {
+  /**
+   * @param $url
+   * @param $file
+   *
+   * @return bool
+   */
   static function download($url, $file) {
     // PHP native client is unreliable PITA for HTTPS
     if (exec("which wget")) {
       self::run('wget', '-q', '-O', $file, $url);
-    } elseif (exec("which curl")) {
+    }
+    elseif (exec("which curl")) {
       self::run('curl', '-o', $file, $url);
     }
 
@@ -656,6 +741,11 @@ class HttpClient {
     return TRUE;
   }
 
+  /**
+   * @param $url
+   *
+   * @return mixed
+   */
   static function getJson($url) {
     $file = tempnam(sys_get_temp_dir(), 'givi-json-');
     HttpClient::download($url, $file);
@@ -669,8 +759,9 @@ class HttpClient {
    *
    * Any items after $command will be escaped and added to $command
    *
-   * @param string $runDir
    * @param string $command
+   *
+   * @internal param string $runDir
    * @return string
    */
   static function run($command) {