Skip to content

Commit

Permalink
Added symfonyVersions to track which bundle branch goes with which sy…
Browse files Browse the repository at this point in the history
…mfony version
  • Loading branch information
cordoval authored and stloyd committed Sep 6, 2012
1 parent bc9fd43 commit e104837
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
/app/config/parameters.*.yml
composer.phar
bin/*
!bin/update-all-bundles.sh
!bin/launch-rabit-consumers.sh
!bin/prepare-*.sh
!bin/behat-*.sh
build
behat.yml
behat.yml
2 changes: 2 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
* 2012-08-20
* BC: Bundle entity property symfonyVersion string turned into symfonyVersions array
* 2012-08-15
* BundleActivityTwigExtension renamed to BundleUtilsExtension
8 changes: 7 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@ Note that you will need a functional rabbitmq server − but that's damn easy to

php app/console kb:populate

This can take long time. GitHub API is limited to 60 calls per minute,
This can take a long time. GitHub API is limited to 60 calls per minute,
so the commands needs to wait.

### Update all bundles in database

php app/console kb:update:bundles

This can take a long time but should be run to trigger update on all bundles when this is needed.

### Search engine

We use [Solr](http://lucene.apache.org/solr/) and it's PHP client [Solarium](http://solarium-project.org) to search bundles.
Expand Down
3 changes: 3 additions & 0 deletions app/config/parameters.yml.test
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ parameters:
url: "http://knpbundles.com"

knp_bundles.finder.limit: 2000

monolog.swift.from_email: error@knpbundles.com
monolog.swift.to_email: error@knpbundles.com
39 changes: 38 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Knp/Bundle/KnpBundlesBundle/DataFixtures/ORM/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ class:
'tags' => ($i%2) ? array('1.0', '1.1') : array(),
'usesTravisCi' => ($i%2) ? false : true,
'composerName' => ($i%2) ? null : 'knplabs/knp-menu-bundle',
'symfonyVersions' => array(
'dev-master' => '2.1.*',
'1.2.0' => '2.0.*',
'1.1.0' => '2.*',
),
'state' => $states[mt_rand(0, 3)],
'travisCiBuildStatus' => ($i%2 == 0) ? $trilean[$i%3] : null,
'nbFollowers' => $i*10,
Expand Down
22 changes: 11 additions & 11 deletions src/Knp/Bundle/KnpBundlesBundle/Entity/Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@ class Bundle
protected $keywords;

/**
* Symfony version required
* Symfony versions required
*
* @ORM\Column(type="string", length=255, nullable=true)
* @ORM\Column(type="array", nullable=true)
*/
protected $symfonyVersion;
protected $symfonyVersions;

/**
* Last indexing time.
Expand Down Expand Up @@ -1060,23 +1060,23 @@ public function addKeyword(Keyword $keyword)
}

/**
* Get required version of Symfony
* Get required versions of Symfony
*
* @return string
* @return array
*/
public function getSymfonyVersion()
public function getSymfonyVersions()
{
return $this->symfonyVersion;
return $this->symfonyVersions;
}

/**
* Get required version of Symfony
* Get required versions of Symfony
*
* @param string
* @param array
*/
public function setSymfonyVersion($version)
public function setSymfonyVersions($versions)
{
$this->symfonyVersion = $version;
$this->symfonyVersions = $versions;
}

/**
Expand Down
37 changes: 35 additions & 2 deletions src/Knp/Bundle/KnpBundlesBundle/Github/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ public function updateFiles(Bundle $bundle)

foreach (array('README.markdown', 'README.md', 'README') as $readmeFilename) {
if ($gitRepo->hasFile($readmeFilename)) {
$bundle->setReadme($gitRepo->getFileContent($readmeFilename));
break;
$bundle->setReadme($gitRepo->getFileContent($readmeFilename));
break;
}
}

Expand All @@ -181,6 +181,8 @@ public function updateFiles(Bundle $bundle)

$this->updateCanonicalConfigFile($gitRepo, $bundle);

$this->updateSymfonyVersions($bundle);

return true;
}

Expand All @@ -205,6 +207,37 @@ private function updateComposerFile($gitRepo, Bundle $bundle)
}
}

public function updateSymfonyVersions(Bundle $bundle)
{
// no composer file
if (null === $bundle->getComposerName()) {
return false;
}

$symfonyVersions = array();

// query packagist json
$packagistArray = $this->github->getHttpClient()->get($bundle->getPackagistUrl().'.json');

// if json not encoded
if (!is_array($packagistArray)) {
return false;
}

// build array branch => version
$versionsArray = $packagistArray['package']['versions'];

foreach ($versionsArray as $version => $value) {
foreach (array('symfony/framework-bundle', 'symfony/symfony') as $requirement) {
if (isset($value['require'][$requirement])) {
$symfonyVersions[$version] = $value['require'][$requirement]; // array('master' => '>=2.0,<2.2-dev')
}
}
}

$bundle->setSymfonyVersions($symfonyVersions);
}

public function updateTags(Bundle $bundle)
{
$this->output->write(' tags');
Expand Down
12 changes: 12 additions & 0 deletions src/Knp/Bundle/KnpBundlesBundle/Resources/public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,15 @@ pre.code {
span.state {
border-bottom: 1px dotted #aaa;
}

table.versions-table {
margin: 5px 10px 0;
}

tr.table-bottom-line {
border-bottom: 1px solid #DDD;
}

th.table-middle-space {
width: 20px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@
</li>
{%- endif -%}
<li>{% trans %}bundles.show.infos.score{% endtrans %} <span><a href="#bundle-score-details">{{ bundle.score }}</a></span></li>
<li>{% trans %}bundles.show.infos.symfonyVersion{% endtrans %} {{ bundle.symfonyVersion ? bundle.symfonyVersion : "bundles.show.infos.unknown" | trans }}</li>
<li>{% trans %}bundles.show.infos.symfonyVersion{% endtrans %}
<table class="versions-table">
<tbody>
<tr class="table-bottom-line">
<th>Bundle</th><th class="table-middle-space"></th><th>Symfony</th>
</tr>
{% for key, version in bundle.symfonyVersions %}
<tr>
<td>{{ key }}</td><td></td><td>{{ version ? version : "bundles.show.infos.unknown" | trans }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</li>
<li>{% trans %}bundles.show.infos.created{% endtrans %} <span>{{ bundle.createdAt|date('date_format'|trans) }}</span></li>
<li>{% trans %}bundles.show.infos.contributors{% endtrans %} <span>{{ bundle.nbContributors }}</span></li>
<li>{% trans %}bundles.show.infos.followers{% endtrans %} <span>{{ bundle.nbFollowers }}</span></li>
Expand Down
58 changes: 56 additions & 2 deletions src/Knp/Bundle/KnpBundlesBundle/Tests/Github/RepoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Knp\Bundle\KnpBundlesBundle\Github\Repo;
use Knp\Bundle\KnpBundlesBundle\Entity\Bundle;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Github\HttpClient\HttpClient;

class RepoTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -127,9 +128,62 @@ public function shouldNotUpdateCanonicalConfig()
$this->assertEquals('', $githubRepo->getCanonicalConfiguration());
}

protected function getRepo()
/**
* @test
*/
public function shouldUpdateSymfonyVersions()
{
$json = array('package' => array('versions' => array(
0 => array('require' => array('symfony/framework-bundle' => 'dev-master', 'symfony/symfony' => 'dev-master')),
1 => array('require' => array('symfony/framework-bundle' => '>=2.0,<2.2-dev', 'symfony/symfony' => '>=2.0,<2.2-dev'))
)));

$bundle = new Bundle('knplabs/KnpMenuBundle');
$bundle->setComposerName('knplabs/knp-menu-bundle');

$httpClient = $this->getMockBuilder('Github\HttpClient\HttpClient')
->setMethods(array('get'))
->disableOriginalConstructor()
->getMock();

$httpClient->expects($this->once())
->method('get')
->will($this->returnValue($json));

$githubRepo = $this->getRepo($httpClient);

$githubRepo->updateSymfonyVersions($bundle);

$this->assertCount(2, $bundle->getSymfonyVersions());
}

/**
* @test
*/
public function shoudNotUpdateSymfonyVersionsWithWrongData()
{
$json = 'I am wrong json';

$bundle = new Bundle('knplabs/KnpMenuBundle');
$bundle->setComposerName('knplabs/knp-menu-bundle');

$httpClient = $this->getMockBuilder('Github\HttpClient\HttpClient')
->setMethods(array('get'))
->disableOriginalConstructor()
->getMock();

$httpClient->expects($this->once())
->method('get')
->will($this->returnValue($json));

$githubRepo = $this->getRepo($httpClient);

$githubRepo->updateSymfonyVersions($bundle);
}

protected function getRepo($httpClient = null)
{
$github = new \Github\Client;
$github = new \Github\Client($httpClient ? $httpClient : null);
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$repoManager = $this->getMockBuilder('Knp\Bundle\KnpBundlesBundle\Git\RepoManager')
->disableOriginalConstructor()
Expand Down

0 comments on commit e104837

Please sign in to comment.