10 require_once
'phing/tasks/ext/git/GitBaseTask.php';
74 $this->heads = explode(
',', $str);
84 $this->tags = explode(
',', $str);
104 $this->subIndicatorFile = $str;
114 $this->dryRun = (bool) $bool;
124 $this->noHeads = (bool) $bool;
134 $this->noTags = (bool) $bool;
152 $repo = $this->getRepository();
154 throw new BuildException(
'"repository" is a required parameter');
159 throw new BuildException(
'"remote" is a required parameter');
163 $this->client = $this->getGitClient(
false, $repo);
166 if (!is_dir(
'.subsplit')) {
185 $this->log(
'DRY RUN ONLY FOR NOW');
188 $org = $this->getOwningTarget()->getProject()->getProperty(
'github.org');
193 foreach (
$heads as $head) {
194 foreach ($this->splits[$head] as $component => $meta) {
195 $splits[] =
$base . $component .
':git@github.com:'. $org.
'/'.$meta[
'repo'];
198 $cmd =
'git subsplit publish ';
199 $cmd .= escapeshellarg(implode(
' ',
$splits));
202 $cmd .=
' --no-heads';
204 $cmd .=
' --heads='.$head;
208 $cmd .=
' --no-tags';
211 $cmd .=
' --tags=' . escapeshellarg(implode(
' ', $this->
getTags()));
224 $repo = $this->getRepository();
225 $this->log(
'git-subsplit update...');
226 $cmd = $this->client->getCommand(
'subsplit');
227 $cmd->addArgument(
'update');
230 }
catch (Exception $e) {
231 throw new BuildException(
'git subsplit update failed'. $e);
233 chdir($repo .
'/.subsplit');
234 passthru(
'php ../composer.phar update --dev');
244 $cmd = $this->client->getCommand(
'subsplit');
245 $this->log(
'running git-subsplit init ' .
$remote);
247 $cmd->setArguments(array(
253 $output = $cmd->execute();
254 }
catch (Exception $e) {
255 throw new BuildException(
'git subsplit init failed'. $e);
257 $this->log(trim($output), Project::MSG_INFO);
258 $repo = $this->getRepository();
259 chdir($repo .
'/.subsplit');
260 passthru(
'php ../composer.phar install --dev');
271 $this->log(
"checking heads for subsplits");
272 $repo = $this->getRepository();
284 chdir($repo .
'/.subsplit');
285 foreach (
$heads as $head) {
289 passthru(
"git checkout '$head'");
290 $ds =
new DirectoryScanner();
291 $ds->setBasedir($repo .
'/.subsplit' .
$base);
292 $ds->setIncludes(array(
'**/'.$this->subIndicatorFile));
294 $files = $ds->getIncludedFiles();
297 foreach ($files as $file) {
298 $pkg = file_get_contents($repo .
'/.subsplit' .
$base .
'/'. $file);
299 $pkg_json = json_decode($pkg,
true);
300 $name = $pkg_json[
'name'];
301 $component = str_replace(
'/composer.json',
'', $file);
303 $tmpreponame = explode(
'/', $name);
304 $reponame = $tmpreponame[1];
305 $splits[$head][$component][
'repo'] = $reponame;
306 $nscomponent = str_replace(
'/',
'\\', $component);
307 $splits[$head][$component][
'desc'] =
"[READ ONLY] Subtree split of $nscomponent: " . $pkg_json[
'description'];
312 passthru(
"git checkout master");
324 $this->log(
'verifying GitHub target repos');
325 $github_org = $this->getOwningTarget()->getProject()->getProperty(
'github.org');
326 $github_creds = $this->getOwningTarget()->getProject()->getProperty(
'github.basicauth');
328 if ($github_creds ==
'username:password') {
329 $this->log(
'Skipping GitHub repo checks. Update github.basicauth in build.properties to verify repos.', 1);
333 $ch = curl_init(
'https://api.github.com/orgs/'.$github_org.
'/repos?type=all');
334 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
335 curl_setopt($ch, CURLOPT_USERPWD, $github_creds);
337 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
false);
338 $result = curl_exec($ch);
340 $repos = json_decode($result,
true);
341 $existing_repos = array();
344 foreach ($repos as $repo) {
345 $tmpreponame = explode(
'/', $repo[
'full_name']);
346 $reponame = $tmpreponame[1];
347 $existing_repos[$reponame] = $repo[
'description'];
351 foreach (
$heads as $head) {
352 foreach ($this->splits[$head] as $component => $meta) {
354 $reponame = $meta[
'repo'];
356 if (!isset($existing_repos[$reponame])) {
357 $this->log(
"Creating missing repo $reponame");
360 'description' => $meta[
'desc'],
361 'homepage' =>
'http://www.guzzlephp.org/',
363 'has_issues' =>
false,
365 'has_downloads' =>
true,
368 $ch = curl_init(
'https://api.github.com/orgs/'.$github_org.
'/repos');
369 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
370 curl_setopt($ch, CURLOPT_USERPWD, $github_creds);
371 curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'));
372 curl_setopt($ch, CURLOPT_POST, 1);
373 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
375 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
false);
376 $result = curl_exec($ch);
377 echo
"Response code: ".curl_getinfo($ch, CURLINFO_HTTP_CODE).
"\n";
380 $this->log(
"Repo $reponame exists", 2);