Skip to content

Commit

Permalink
Merge identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 14, 2023
1 parent 38afd69 commit e2e0906
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 2 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/extract-identifiers.yml
Expand Up @@ -76,3 +76,51 @@ jobs:
with:
name: identifiers
path: identifier-extractor/${{ steps.repo-name.outputs.name }}.json

merge:
name: "Merge and commit identifiers"
needs: extract

runs-on: "ubuntu-latest"

steps:
- name: "Checkout"
uses: actions/checkout@v3

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "8.1"

- name: "Install extractor dependencies"
working-directory: "identifier-extractor"
run: "composer install --no-interaction --no-progress"

- uses: actions/download-artifact@v3
with:
name: identifiers
path: identifier-extractor/tmp

- name: "Merge"
working-directory: "identifier-extractor"
run: "php merge.php > ../website/src/errorsIdentifiers.json"

- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GPG_PHPSTANBOT_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PHPSTANBOT_KEY_PASSPHRASE }}
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true

- name: "Commit changes"
uses: "stefanzweifel/git-auto-commit-action@v4"
id: "commit"
with:
commit_message: "Update errors identifiers"
commit_user_name: "phpstan-bot"
commit_user_email: "ondrej+phpstanbot@mirtes.cz"
commit_author: "phpstan-bot <ondrej+phpstanbot@mirtes.cz>"
commit_options: "--gpg-sign"
3 changes: 2 additions & 1 deletion identifier-extractor/composer.json
@@ -1,7 +1,8 @@
{
"require": {
"php": "^8.1",
"nette/utils": "^4.0"
"nette/utils": "^4.0",
"symfony/finder": "^6.3"
},
"autoload": {
"psr-4": {
Expand Down
66 changes: 65 additions & 1 deletion identifier-extractor/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions identifier-extractor/merge.php
@@ -0,0 +1,62 @@
<?php declare(strict_types = 1);

require_once __DIR__ . '/vendor/autoload.php';

use Nette\Utils\Json;
use Symfony\Component\Finder\Finder;

$finder = new Finder();
$tmpResults = [];

$data = [];
foreach ($finder->files()->name('*.json')->in(__DIR__ . '/tmp') as $resultFile) {
$contents = file_get_contents($resultFile->getPathname());
if ($contents === false) {
throw new \LogicException();
}
$json = Json::decode($contents, true);
$repo = $json['repo'];
$branch = $json['branch'];

foreach ($json['data'] as $row) {
$data[] = [
'identifiers' => $row['identifiers'],
'class' => $row['class'],
'repo' => $repo,
'url' => sprintf('https://github.com/%s/blob/%s/%s#L%d', $repo, $branch, $row['file'], $row['line']),
];
}
}

$dataByIdentifier = [];
foreach ($data as $row) {
foreach ($row['identifiers'] as $identifier) {
if (!isset($dataByIdentifier[$identifier])) {
$dataByIdentifier[$identifier] = [
'classes' => [
$row['class'],
],
'repos' => [
$row['repo'],
],
'urls' => [
$row['url'],
],
];
continue;
}

$dataByIdentifier[$identifier]['classes'][] = $row['class'];
$dataByIdentifier[$identifier]['repos'][] = $row['repo'];
$dataByIdentifier[$identifier]['urls'][] = $row['url'];
}
}

foreach ($dataByIdentifier as $identifier => $row) {
foreach ($row as $k => $v) {
sort($v);
$dataByIdentifier[$identifier][$k] = array_values(array_unique($v));
}
}

echo Json::encode($dataByIdentifier, true);
1 change: 1 addition & 0 deletions identifier-extractor/phpstan.neon
Expand Up @@ -5,3 +5,4 @@ parameters:
level: 8
paths:
- src
- merge.php
2 changes: 2 additions & 0 deletions identifier-extractor/tmp/.gitignore
@@ -0,0 +1,2 @@
*
!.*

0 comments on commit e2e0906

Please sign in to comment.