Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor APIs to give dumper a reference to the builder #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/BuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace PackageGenerator;

use Gitonomy\Git\Reference;
use Gitonomy\Git\Repository;

interface BuilderInterface {

public function __construct(array $composerJson, array $composerLock, Reference $gitObject);
public function __construct(array $composerJson, array $composerLock, Reference $gitObject, array $config, Repository $metapackage_repository);

/**
* @return string
Expand Down
17 changes: 12 additions & 5 deletions src/Commands/RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
class RoboFile extends Tasks
{
protected $clonedList = [];

/**
* @return \Robo\Collection\CollectionBuilder
Expand All @@ -41,12 +42,18 @@ protected function buildPackage($config)
$source = 'tmp/' . hash('sha256', $config['source']);
$target = 'tmp/' . hash('sha256', $config['target']);

if (!file_exists($source)) {
$collection->progressMessage("Source is $source");

if (!file_exists($source) && !array_key_exists($source, $this->clonedList)) {
$this->clonedList[$source] = true;
$collection->taskGitStack()
->cloneRepo($config['source'], $source);
}

if (!file_exists($target)) {
$collection->progressMessage("Target is $target");

if (!file_exists($target) && !array_key_exists($target, $this->clonedList)) {
$this->clonedList[$target] = true;
$collection->taskGitStack()
->cloneRepo($config['target'], $target);
}
Expand Down Expand Up @@ -112,13 +119,13 @@ protected function buildPackage($config)
$metapackage_repository->run('config', ['user.email', $config['git']['author']['email']]);

/** @var BuilderInterface $builder */
$builder = new $config['builder']($composerJsonData, $composerLockData, $ref);
$dump = new Dumper($ref, $builder->getPackage(), $metapackage_repository, $builder->getCommitMessage());
$builder = new $config['builder']($composerJsonData, $composerLockData, $ref, $config, $metapackage_repository);
$dump = new Dumper($ref, $builder, $metapackage_repository);
$dump->write();
}
});

$collection->progressMessage($target);
$collection->progressMessage("Done with $target");

$collection->taskGitStack()
->dir($target)
Expand Down
15 changes: 9 additions & 6 deletions src/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class Dumper {
*/
protected $reference;

protected $package;

protected $repository;

/**
Expand All @@ -31,17 +29,20 @@ class Dumper {

protected $commitMessage;

public function __construct(\Gitonomy\Git\Reference $reference, array $package, Repository $repository, $commitMessage) {
protected $builder;

public function __construct(\Gitonomy\Git\Reference $reference, BuilderInterface $builder, Repository $repository) {

if ($reference instanceof Tag || $reference instanceof Branch) {
$this->reference = $reference;
}
else {
throw new \InvalidArgumentException('$ref is not a tag or branch.');
}

$this->package = $package;
$this->builder = $builder;
$this->repository = $repository;
$this->commitMessage = $commitMessage;
$this->commitMessage = $builder->getCommitMessage();
}

protected function getBranch(\Gitonomy\Git\Reference $reference) {
Expand Down Expand Up @@ -79,7 +80,9 @@ public function write() {
return;
}

file_put_contents($this->repository->getPath() . '/composer.json', json_encode($this->package, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
$package = $this->builder->getPackage();

file_put_contents($this->repository->getPath() . '/composer.json', json_encode($package, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
$this->repository->run('add', ['composer.json']);

if (isset($this->tag)) {
Expand Down