1
0
Fork 0

Merge pull request #8510 from glaubinix/t/abandon-archived

VcsRepositories: mark archived repositories as abandoned
pull/8538/head
Jordi Boggiano 2020-01-13 13:47:33 +01:00 committed by GitHub
commit 818e16238f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 84 additions and 1 deletions

View File

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

View File

@ -119,6 +119,42 @@ class GitLabDriver extends VcsDriver
$this->remoteFilesystem = $remoteFilesystem; $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} * {@inheritdoc}
*/ */

View File

@ -207,7 +207,49 @@ class GitHubDriverTest extends TestCase
$this->assertEquals($repoUrl, $source['url']); $this->assertEquals($repoUrl, $source['url']);
$this->assertEquals($sha, $source['reference']); $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() public function testPrivateRepositoryNoInteraction()