1
0
Fork 0

VcsRepositories: mark archived repositories as abandoned

pull/8510/head
Stephan Vock 2020-01-04 17:01:27 +00:00
parent 6034c2af01
commit 731d94a2a3
3 changed files with 84 additions and 1 deletions

View File

@ -34,6 +34,7 @@ class GitHubDriver extends VcsDriver
protected $hasIssues;
protected $infoCache = array();
protected $isPrivate = false;
private $isArchived = false;
/**
* Git Driver
@ -162,6 +163,9 @@ class GitHubDriver extends VcsDriver
if (!isset($composer['support']['issues']) && $this->hasIssues) {
$composer['support']['issues'] = sprintf('https://%s/%s/%s/issues', $this->originUrl, $this->owner, $this->repository);
}
if (!isset($composer['abandoned']) && $this->isArchived) {
$composer['abandoned'] = true;
}
}
if ($this->shouldCache($identifier)) {
@ -425,6 +429,7 @@ class GitHubDriver extends VcsDriver
$this->rootIdentifier = 'master';
}
$this->hasIssues = !empty($this->repoData['has_issues']);
$this->isArchived = !empty($this->repoData['archived']);
}
protected function attemptCloneFallback()

View File

@ -119,6 +119,42 @@ class GitLabDriver extends VcsDriver
$this->remoteFilesystem = $remoteFilesystem;
}
/**
* {@inheritDoc}
*/
public function getComposerInformation($identifier)
{
if ($this->gitDriver) {
return $this->gitDriver->getComposerInformation($identifier);
}
if (!isset($this->infoCache[$identifier])) {
if ($this->shouldCache($identifier) && $res = $this->cache->read($identifier)) {
return $this->infoCache[$identifier] = JsonFile::parseJson($res);
}
$composer = $this->getBaseComposerInformation($identifier);
if ($composer) {
// specials for gitlab (this data is only available if authentication is provided)
if (!isset($composer['support']['issues']) && isset($this->project['_links']['issues'])) {
$composer['support']['issues'] = $this->project['_links']['issues'];
}
if (!isset($composer['abandoned']) && !empty($this->project['archived'])) {
$composer['abandoned'] = true;
}
}
if ($this->shouldCache($identifier)) {
$this->cache->write($identifier, json_encode($composer));
}
$this->infoCache[$identifier] = $composer;
}
return $this->infoCache[$identifier];
}
/**
* {@inheritdoc}
*/

View File

@ -207,7 +207,49 @@ class GitHubDriverTest extends TestCase
$this->assertEquals($repoUrl, $source['url']);
$this->assertEquals($sha, $source['reference']);
$gitHubDriver->getComposerInformation($identifier);
$data = $gitHubDriver->getComposerInformation($identifier);
$this->assertArrayNotHasKey('abandoned', $data);
}
public function testPublicRepositoryArchived()
{
$repoUrl = 'http://github.com/composer/packagist';
$repoApiUrl = 'https://api.github.com/repos/composer/packagist';
$identifier = 'v0.0.0';
$sha = 'SOMESHA';
$composerJsonUrl = 'https://api.github.com/repos/composer/packagist/contents/composer.json?ref=' . $sha;
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$io->expects($this->any())
->method('isInteractive')
->will($this->returnValue(true));
$remoteFilesystem = $this->getMockBuilder('Composer\Util\RemoteFilesystem')
->setConstructorArgs(array($io))
->getMock();
$remoteFilesystem->expects($this->at(0))
->method('getContents')
->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
->will($this->returnValue('{"master_branch": "test_master", "owner": {"login": "composer"}, "name": "packagist", "archived": true}'));
$remoteFilesystem->expects($this->at(1))
->method('getContents')
->with($this->equalTo('github.com'), $this->equalTo($composerJsonUrl), $this->equalTo(false))
->will($this->returnValue('{"encoding": "base64", "content": "' . base64_encode('{"name": "composer/packagist"}') . '"}'));
$repoConfig = array(
'url' => $repoUrl,
);
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, null, $remoteFilesystem);
$gitHubDriver->initialize();
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
$data = $gitHubDriver->getComposerInformation($sha);
$this->assertTrue($data['abandoned']);
}
public function testPrivateRepositoryNoInteraction()