Skip to content

Commit

Permalink
Merge branch 'master' into fix/lock-commit-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Apr 26, 2019
2 parents 6f45050 + 2dda6d6 commit 2901e03
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 93 deletions.
77 changes: 35 additions & 42 deletions src/CosyComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ public function run()
]);
$app->run($i, $this->output);
$raw_data = $this->output->fetch();
$data = null;
foreach ($raw_data as $delta => $item) {
if (empty($item) || empty($item[0])) {
continue;
Expand All @@ -571,6 +572,11 @@ public function run()
break;
}
}
if (!is_array($data)) {
$this->log('No updates found');
$this->cleanUp();
return;
}
// Remove blacklisted packages.
if (!empty($cdata->extra) && !empty($cdata->extra->violinist) && !empty($cdata->extra->violinist->blacklist)) {
if (!is_array($cdata->extra->violinist->blacklist)) {
Expand All @@ -586,6 +592,18 @@ public function run()
}
}
}
foreach ($data as $delta => $item) {
// Also unset those that are in an unexpected format. A new thing seen in the wild has been this:
// {
// "name": "symfony/css-selector",
// "version": "v2.8.49",
// "description": "Symfony CssSelector Component"
// }
// They should ideally include a latest version and latest status.
if (!isset($item->latest) || !isset($item->{'latest-status'})) {
unset($data[$delta]);
}
}
if (empty($data)) {
$this->log('No updates found');
$this->cleanUp();
Expand Down Expand Up @@ -926,6 +944,9 @@ public function run()
}
$this->log('Checking out default branch - ' . $default_branch);
$this->execCommand('git checkout ' . $default_branch, false);
// Re-do composer install to make output better, and to make the lock file actually be there for
// consecutive updates, if it is a project without it.
$this->doComposerInstall();
}
// Clean up.
$this->cleanUp();
Expand Down Expand Up @@ -957,52 +978,27 @@ public function setOutput(OutputInterface $output)
$this->output = $output;
}

/**
* Cleans up after the run.
*/
/**
* Cleans up after the run.
*/
private function cleanUp()
{
// Run composer install again, so we can get rid of newly installed updates for next run.
$this->execCommand('COMPOSER_DISCARD_CHANGES=true COMPOSER_ALLOW_SUPERUSER=1 composer install --no-ansi -n', false, 1200);
$this->chdir('/tmp');
$this->log('Cleaning up after update check.');
$this->log('Storing custom composer cache for later');
$this->execCommand(
sprintf(
'rsync -az --exclude "composer.*" %s/* %s',
$this->tmpDir,
$this->createCacheDir()
),
false,
300
);
$this->execCommand('rm -rf ' . $this->tmpDir, false, 300);
}

/**
* Returns the cache directory, and creates it if necessary.
*
* @return string
*/
public function createCacheDir()
{
$dir_name = md5($this->slug->getSlug());
$path = sprintf('%s/%s', $this->getCacheDir(), $dir_name);
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
return $path;
}

/**
* Creates a title for a PR.
*
* @param object $item
* The item in question.
*
* @return string
* A string ready to use.
*/
/**
* Creates a title for a PR.
*
* @param object $item
* The item in question.
*
* @return string
* A string ready to use.
*/
protected function createTitle($item, $post_update_data, $security_update = false)
{
$update = new ViolinistUpdate();
Expand Down Expand Up @@ -1081,11 +1077,6 @@ protected function log($message, $type = 'message', $context = [])
*/
protected function doComposerInstall()
{
// First copy the custom cache in here.
if (file_exists($this->createCacheDir())) {
$this->log('Found custom cache. using this for vendor folder.');
$this->execCommand(sprintf('rsync -a %s/* %s/', $this->createCacheDir(), $this->tmpDir), false, 300);
}
// @todo: Should probably use composer install command programatically.
$this->log('Running composer install');
if ($code = $this->execCommand('COMPOSER_DISCARD_CHANGES=true COMPOSER_ALLOW_SUPERUSER=1 composer install --no-ansi -n', false, 1200)) {
Expand Down Expand Up @@ -1147,6 +1138,7 @@ public function retrieveChangeLog($package_name, $lockdata, $version_from, $vers
$cosy_factory_wrapper = new ProcessFactoryWrapper();
$cosy_factory_wrapper->setExecutor($this->executer);
$retriever = new DependencyRepoRetriever($cosy_factory_wrapper);
$retriever->setAuthToken($this->userToken);
$fetcher = new ChangelogRetriever($retriever, $cosy_factory_wrapper);
$log = $fetcher->retrieveChangelog($package_name, $lockdata, $version_from, $version_to);
$changelog_string = '';
Expand All @@ -1170,6 +1162,7 @@ public function retrieveChangeLog($package_name, $lockdata, $version_from, $vers
$lock_data_obj->setData($lockdata);
$data = $lock_data_obj->getPackageData($package_name);
$git_url = preg_replace('/.git$/', '', $data->source->url);
$repo_parsed = parse_uri($git_url);
if (!empty($repo_parsed)) {
switch ($repo_parsed['_protocol']) {
case 'git@github.com':
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/composer-json-private.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"repositories": [
{
"type": "vcs",
"url": "git@github.com:eiriksm/private-pack.git"
}

],
"require": {
"psr/log": "^1.1",
"eirik/private-pack": "dev-master"
}
}
94 changes: 94 additions & 0 deletions test/fixtures/composer-lock-private.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "2adc3126cdbcbbbe617ba913ad48f73c",
"packages": [
{
"name": "eirik/private-pack",
"version": "dev-master",
"source": {
"type": "git",
"url": "git@github.com:eiriksm/private-pack.git",
"reference": "2adc3126cdbcbbbe617ba913ad48f73c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/eiriksm/private-pack/zipball/2adc3126cdbcbbbe617ba913ad48f73c",
"reference": "2adc3126cdbcbbbe617ba913ad48f73c",
"shasum": ""
},
"type": "library",
"authors": [
{
"name": "Eirik S. Morland",
"email": "eirik@morland.no"
}
],
"support": {
"source": "https://github.com/eiriksm/private-pack/tree/master",
"issues": "https://github.com/eiriksm/private-pack/issues"
},
"time": "2019-02-17T18:16:09+00:00"
},
{
"name": "psr/log",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Log\\": "Psr/Log/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
"homepage": "https://github.com/php-fig/log",
"keywords": [
"log",
"psr",
"psr-3"
],
"time": "2018-11-20T15:27:04+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"eirik/private-pack": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}
94 changes: 94 additions & 0 deletions test/fixtures/composer-lock-private.updated
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "2adc3126cdbcbbbe617ba913ad48f73c",
"packages": [
{
"name": "eirik/private-pack",
"version": "dev-master",
"source": {
"type": "git",
"url": "git@github.com:eiriksm/private-pack.git",
"reference": "1adc3126cdbcbbbe617ba913ad48f73c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/eiriksm/private-pack/zipball/2adc3126cdbcbbbe617ba913ad48f73c",
"reference": "1adc3126cdbcbbbe617ba913ad48f73c",
"shasum": ""
},
"type": "library",
"authors": [
{
"name": "Eirik S. Morland",
"email": "eirik@morland.no"
}
],
"support": {
"source": "https://github.com/eiriksm/private-pack/tree/master",
"issues": "https://github.com/eiriksm/private-pack/issues"
},
"time": "2019-02-17T18:16:09+00:00"
},
{
"name": "psr/log",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Log\\": "Psr/Log/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
"homepage": "https://github.com/php-fig/log",
"keywords": [
"log",
"psr",
"psr-3"
],
"time": "2018-11-20T15:27:04+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"eirik/private-pack": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}
16 changes: 12 additions & 4 deletions test/integration/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,24 @@ protected function assertOutputContainsMessage($message, $c)
{
/** @var CosyComposer $cosy */
$cosy = $c;
foreach ($cosy->getOutput() as $output_message) {
if ($this->findMessage($message, $cosy)) {
$this->assertTrue(true, "Message '$message' was found in the output");
return;
}
$this->fail("Message '$message' was not found in output");
}

protected function findMessage($message, CosyComposer $c)
{
foreach ($c->getOutput() as $output_message) {
try {
$this->assertEquals($message, $output_message->getMessage());
$this->assertTrue(true, "Message '$message' was found in the output");
return;
return $output_message;
} catch (\Exception $e) {
continue;
}
}
$this->fail("Message '$message' was not found in output");
return false;
}

protected function placeComposerLockContentsFromFixture($filename, $dir)
Expand Down
5 changes: 2 additions & 3 deletions test/integration/NoUpdatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ function ($cmd) use (&$called) {
$this->assertEquals(false, $called);
$c->run();
$this->assertEquals(true, $called);
$msgs = $c->getOutput();
$this->assertEquals('Skipping update of eiriksm/fake-package because it is blacklisted', $msgs[9]->getMessage());
$this->assertEquals('No updates found', $msgs[10]->getMessage());
$this->assertOutputContainsMessage('Skipping update of eiriksm/fake-package because it is blacklisted', $c);
$this->assertOutputContainsMessage('No updates found', $c);
}
}
Loading

0 comments on commit 2901e03

Please sign in to comment.