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)) {
*/
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();
protected $data;
+ /**
+ * @return mixed
+ */
public function getNumber() {
return $this->data->number;
}
}
}
+/**
+ * Class Givi
+ */
class Givi {
/**
*/
protected $dirStack;
+ /**
+ *
+ */
function __construct() {
$this->dirStack = new DirStack();
$this->repos = array(
);
}
+ /**
+ * @param $args
+ *
+ * @throws Exception
+ */
function main($args) {
if (!$this->parseOptions($args)) {
printf("Error parsing arguments\n");
echo "local branches.\n";
}
+ /**
+ * @param null $baseBranch
+ *
+ * @return bool
+ */
function doCheckoutAll($baseBranch = NULL) {
if (!$baseBranch) {
return $this->returnError("Missing <branch>\n");
return TRUE;
}
+ /**
+ * @return bool
+ */
function doStatusAll() {
foreach ($this->repos as $repo => $relPath) {
$this->run($repo, $relPath, 'git', 'status');
return TRUE;
}
+ /**
+ * @param null $baseBranch
+ *
+ * @return bool
+ */
function doBegin($baseBranch = NULL) {
if (!$baseBranch) {
return $this->returnError("Missing <base-branch>\n");
return TRUE;
}
+ /**
+ * @param null $baseBranch
+ *
+ * @return bool
+ * @throws Exception
+ */
function doResume($baseBranch = NULL) {
if (!$baseBranch) {
return $this->returnError("Missing <base-branch>\n");
return TRUE;
}
+ /**
+ * @param null $baseBranch
+ *
+ * @return bool
+ */
function doReview($baseBranch = NULL) {
if (! $this->doCheckoutAll($baseBranch)) {
return FALSE;
}
*/
+ /**
+ * @param $newBranchRepo
+ * @param $newBranchNames
+ *
+ * @return bool
+ */
function doPush($newBranchRepo, $newBranchNames) {
if (!$newBranchRepo) {
return $this->returnError("Missing <remote>\n");
* 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') {
*
* 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) {
/**
* @param string $default branch to use by default
+ * @param $overrides
+ *
* @return array ($repoName => $gitRef)
*/
function resolveBranches($default, $overrides) {
return $branches;
}
+ /**
+ * @param $repoName
+ * @param $branchName
+ *
+ * @return string
+ */
function filterBranchName($repoName, $branchName) {
if ($branchName == '') {
return '';
/**
* @param string $filter e.g. "all" or "repo1,repo2"
* @param array $repos ($repoName => $repoDir)
+ *
+ * @throws Exception
* @return array ($repoName => $repoDir)
*/
function filterRepos($filter, $repos) {
return $repos;
}
+ /**
+ * @param $message
+ *
+ * @return bool
+ */
function returnError($message) {
echo "\nERROR: ", $message, "\n\n";
$this->doHelp();
}
}
+/**
+ * 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")) {
return TRUE;
}
+ /**
+ * @param $url
+ *
+ * @return mixed
+ */
static function getJson($url) {
$file = tempnam(sys_get_temp_dir(), 'givi-json-');
HttpClient::download($url, $file);
*
* 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) {