Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions src/Command/GenerateTopCompaniesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

class GenerateTopCompaniesCommand extends AbstractCommand
{
private const COMMUNITY_NAME = 'Open Source Community';

/**
* @var Company[]
*/
Expand Down Expand Up @@ -144,7 +146,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
// Clean PR Listing
$numPRRemoved = 0;
foreach ($this->companies as $company) {
if ($company->name === 'Open Source Community') {
if ($company->name === self::COMMUNITY_NAME) {
$community = $company;
break;
}
Expand Down Expand Up @@ -370,22 +372,31 @@ protected function extractCompany(array $datum): ?Company
}
if (!empty($matchCompany)) {
$company = $this->getCompanyByAlias($matchCompany);
if ($company) {

// A real sponsor company was declared: it takes precedence
if ($company && !$this->isCommunity($company)) {
return $company;
}
$this->output->writeln(
'Sponsor Company Not Found : '
. $datum['repository']['name']
. '#' . $datum['number']
. ' => ' . $datum['author']['login']
. '/' . $matchCompany
);
if (!isset($this->unknownSponsorCompanies[$matchCompany])) {
$this->unknownSponsorCompanies[$matchCompany] = 0;

// Unknown sponsor company: keep the existing behaviour
if (!$company) {
$this->output->writeln(
'Sponsor Company Not Found : '
. $datum['repository']['name']
. '#' . $datum['number']
. ' => ' . $authorLogin
. '/' . $matchCompany
);
if (!isset($this->unknownSponsorCompanies[$matchCompany])) {
$this->unknownSponsorCompanies[$matchCompany] = 0;
}
++$this->unknownSponsorCompanies[$matchCompany];

return null;
}
++$this->unknownSponsorCompanies[$matchCompany];

return null;
// The value is a template placeholder ("~", "-", "N/A"...) meaning
// no sponsor was declared: fall back to the author's company.
}

// Extract company from "Author"
Expand Down Expand Up @@ -413,6 +424,11 @@ protected function extractCompany(array $datum): ?Company
return null;
}

protected function isCommunity(Company $company): bool
{
return $company->name === self::COMMUNITY_NAME;
}

protected function extractCompanyFromAuthor(string $login, string $createdAt): ?Company
{
$createdAt = new DateTimeImmutable($createdAt);
Expand Down