From 907a9e0854299d1eab6b1cb9db65a350b8da7695 Mon Sep 17 00:00:00 2001 From: Krystian Podemski Date: Thu, 17 Sep 2026 18:13:26 +0200 Subject: [PATCH] Fix company attribution when the Sponsor company field contains a template placeholder --- src/Command/GenerateTopCompaniesCommand.php | 42 ++++++++++++++------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/Command/GenerateTopCompaniesCommand.php b/src/Command/GenerateTopCompaniesCommand.php index 7a282da..4d614e8 100644 --- a/src/Command/GenerateTopCompaniesCommand.php +++ b/src/Command/GenerateTopCompaniesCommand.php @@ -14,6 +14,8 @@ class GenerateTopCompaniesCommand extends AbstractCommand { + private const COMMUNITY_NAME = 'Open Source Community'; + /** * @var Company[] */ @@ -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; } @@ -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" @@ -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);