Skip to content

Commit

Permalink
Warn for patches with no issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhedstrom committed Jan 17, 2017
1 parent 4115ff4 commit e3897d9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
6 changes: 6 additions & 0 deletions spec/Analyze/PatchesSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
use Phase2\ComposerAnalytics\Patch\GithubPatch;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\Console\Output\OutputInterface;

class PatchesSpec extends ObjectBehavior
{
function let(OutputInterface $output)
{
$this->beConstructedWith($output);
}

function it_is_initializable()
{
$this->shouldHaveType(Patches::class);
Expand Down
30 changes: 30 additions & 0 deletions src/Analyze/Patches.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
use Phase2\ComposerAnalytics\Patch\Exception\NoIssueFoundException;
use Phase2\ComposerAnalytics\Patch\HasIssueUriInterface;
use Phase2\ComposerAnalytics\Patch\PatchInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Patch analyzer.
*/
class Patches
{
/**
* The command output.
*
* @var OutputInterface
*/
protected $output;

/**
* Report header.
*/
Expand All @@ -30,6 +38,16 @@ class Patches
*/
protected $patches = [];

/**
* Patches constructor.
*
* @param OutputInterface $output
*/
public function __construct(OutputInterface $output)
{
$this->output = $output;
}

/**
* Set patches to analyze.
*
Expand Down Expand Up @@ -59,11 +77,13 @@ public function analyze()
{
$analysis = [static::$header];

$bad_patches = [];
foreach ($this->patches as $patch) {
if ($patch instanceof HasIssueUriInterface) {
try {
$issue_uri = $patch->getIssueUri();
} catch (NoIssueFoundException $e) {
$bad_patches[] = $patch->getPatchUri();
$issue_uri = static::NO_ISSUE_URI;
}
} else {
Expand All @@ -78,6 +98,16 @@ public function analyze()
];
}

if (!empty($bad_patches)) {
$this->output->writeln(
sprintf(
'<comment>Found %s remote patches with no issue number associated:</comment>',
count($bad_patches)
)
);
$this->output->write(sprintf("<comment>\n * %s</comment>\n\n", implode("\n * ", $bad_patches)));
}

// @todo Some sort of sorting, and potentially aggregation.
return $analysis;
}
Expand Down
2 changes: 1 addition & 1 deletion src/AnalyzeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 0;
}

$analyzer = new Patches();
$analyzer = new Patches($output);
$analyzer->setPatches($patches);
$analyzed = $analyzer->analyze();

Expand Down
5 changes: 4 additions & 1 deletion tests/Analyze/PatchesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Phase2\ComposerAnalytics\Tests\Analyze;
use Phase2\ComposerAnalytics\Analyze\Patches;
use Phase2\ComposerAnalytics\Tests\GeneratePatchesTrait;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Test the patch analyzer.
Expand All @@ -26,7 +27,9 @@ class PatchesTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
parent::setUp();
$this->patchAnalyzer = new Patches();

$output = $this->prophesize(OutputInterface::class)->reveal();
$this->patchAnalyzer = new Patches($output);
$this->patchAnalyzer->setPatches($this->generatePatches());
}

Expand Down

0 comments on commit e3897d9

Please sign in to comment.