Skip to content

Commit

Permalink
Make CI green (#1)
Browse files Browse the repository at this point in the history
* CI fix

* Generate baseline

* minor
  • Loading branch information
Nyholm committed Nov 8, 2020
1 parent 35e84a9 commit 2a8426a
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 74 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
39 changes: 7 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
name: Tests
on: [push, pull_request]

on:
pull_request: ~
push:
branches:
- master

jobs:

build:
name: Build
runs-on: ubuntu-latest
strategy:
max-parallel: 10
matrix:
php: ['7.3', '7.4']
sf_version: ['4.4.*', '5.0.*']

steps:
- name: Set up PHP
Expand All @@ -24,35 +27,7 @@ jobs:
uses: actions/checkout@v2

- name: Download dependencies
env:
SYMFONY_REQUIRE: ${{ matrix.sf_version }}
run: |
composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable
run: composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable

- name: Run tests
run: ./vendor/bin/simple-phpunit

lowest:
name: Lowest deps
runs-on: ubuntu-latest
steps:
- name: Set up PHP
uses: shivammathur/setup-php@2.1.0
with:
php-version: 7.3
coverage: pcov

- name: Checkout code
uses: actions/checkout@v2

- name: Download dependencies
run: |
composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable --prefer-lowest
- name: Run tests
env:
SYMFONY_DEPRECATIONS_HELPER: "max[self]=0"
run: |
./vendor/bin/simple-phpunit -v --coverage-text --coverage-clover=coverage.xml
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.xml
41 changes: 35 additions & 6 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,56 @@
on: [push, pull_request]
name: Static analysis

on:
pull_request: ~
push:
branches:
- master

jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest

steps:
- name: Set up PHP
uses: shivammathur/setup-php@2.7.0
with:
php-version: '7.4'
coverage: none

- name: Checkout code
uses: actions/checkout@v2

- name: Download dependencies
run: composer install --no-interaction --optimize-autoloader

- name: PHPStan
uses: docker://oskarstark/phpstan-ga
env:
REQUIRE_DEV: true
uses: docker://oskarstark/phpstan-ga:0.12.48
with:
entrypoint: /composer/vendor/bin/phpstan
args: analyze --no-progress

php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v2

- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga
uses: docker://oskarstark/php-cs-fixer-ga:2.16.4
with:
args: --dry-run --diff-format udiff

psalm:
name: Psalm
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Psalm
uses: docker://vimeo/psalm-github-actions:3.17.2
with:
args: --no-progress --show-info=false --stats
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Find reviewers

```
./git-reviewer.php --env=dev find 106 /Users/tobias/Workspace/PHPStorm/carsonbot --ignore-path "config/*" --ignore-path .env --pretty-print
./git-reviewer.php find 106 /Users/tobias/Workspace/PHPStorm/carsonbot --ignore-path "config/*" --ignore-path .env --pretty-print
```

```json
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
"psr-4": {
"Tests\\Nyholm\\GitReviewer\\": "tests/"
}
},
"require-dev": {
"symfony/phpunit-bridge": "^5.1"
}
}
2 changes: 1 addition & 1 deletion config/packages/cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ services:
arguments:
- 'git-reviewer'
- 0
- '%kernel.cache_dir%'
- '%kernel.cache_dir%/cache'

11 changes: 11 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
parameters:
ignoreErrors:
-
message: "#^Instantiated class CachedContainer not found\\.$#"
count: 1
path: src/Kernel.php

-
message: "#^Property Nyholm\\\\GitReviewer\\\\Kernel\\:\\:\\$container \\(Symfony\\\\Component\\\\DependencyInjection\\\\Container\\) does not accept CachedContainer\\.$#"
count: 1
path: src/Kernel.php

8 changes: 8 additions & 0 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.18.2@19aa905f7c3c7350569999a93c40ae91ae4e1626">
<file src="src/Kernel.php">
<InvalidPropertyAssignmentValue occurrences="1">
<code>new \CachedContainer()</code>
</InvalidPropertyAssignmentValue>
</file>
</files>
16 changes: 16 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm.baseline.xml"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
1 change: 0 additions & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public function __construct(Kernel $kernel)

$inputDefinition = $this->getDefinition();
$inputDefinition->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'prod'));

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Command/CacheClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ protected function execute(InputInterface $input, OutputInterface $output)

return 0;
}
}
}
8 changes: 3 additions & 5 deletions src/Command/FindCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;

class FindCommand extends Command
{
Expand All @@ -23,7 +22,6 @@ class FindCommand extends Command
private $contributorProvider;
private $usernameProvider;


public function __construct(RepositoryProvider $repositoryProvider, ChangeSetProvider $changeSetProvider, ContributorProvider $contributorProvider, GithubUsernameProvider $usernameProvider)
{
parent::__construct();
Expand Down Expand Up @@ -55,7 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// run git blame on paths in workspace
$after = $input->getOption('after');
if ($after === null) {
if (null === $after) {
$after = '2010-01-01';
}

Expand All @@ -67,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$contributors[$key]['username'] = $this->usernameProvider->findUsername($c['email'], $c['name']);
}
}
$x =2;
$x = 2;

if ($input->getOption('pretty-print')) {
$output->writeln(json_encode($contributors, JSON_PRETTY_PRINT));
Expand All @@ -77,4 +75,4 @@ protected function execute(InputInterface $input, OutputInterface $output)

return 0;
}
}
}
5 changes: 1 addition & 4 deletions src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
Expand All @@ -35,7 +34,7 @@ class Kernel

public function __construct(string $env)
{
$this->debug = $env !== 'prod';
$this->debug = 'prod' !== $env;
$this->env = $env;
}

Expand Down Expand Up @@ -117,6 +116,4 @@ public function getEnvironment(): string
{
return $this->env;
}


}
7 changes: 0 additions & 7 deletions src/Service/ChangeSetProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

declare(strict_types=1);


namespace Nyholm\GitReviewer\Service;


use Github\Client;
use Nyholm\GitReviewer\Model\Repository;
use Symfony\Component\Process\Process;
Expand All @@ -17,15 +15,11 @@ class ChangeSetProvider
*/
private $github;

/**
* @param Client $github
*/
public function __construct(Client $github)
{
$this->github = $github;
}


public function getChangedFiles(Repository $repository, int $number, array $ignoredPaths): array
{
$pr = $this->github->pullRequest()->show($repository->getUser(), $repository->getName(), $number);
Expand Down Expand Up @@ -88,7 +82,6 @@ private function validFile(string $path, array $ignoredFiles, $ignoredPatterns):
return false;
}


foreach ($ignoredPatterns as $pattern) {
if (preg_match($pattern, $path)) {
return false;
Expand Down
8 changes: 3 additions & 5 deletions src/Service/ContributorProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

declare(strict_types=1);


namespace Nyholm\GitReviewer\Service;


use Nyholm\GitReviewer\Model\Repository;
use Symfony\Component\Process\Process;

Expand All @@ -23,7 +21,7 @@ public function getContributors(Repository $repository, array $files, \DateTimeI

$authors = array_values($authors);
usort($authors, function ($a, $b) {
return $b['contributions'] - $a['contributions'];
return $b['contributions'] - $a['contributions'];
});

return $authors;
Expand Down Expand Up @@ -54,8 +52,8 @@ private function parseAuthors(array &$authors, string $output, int $after)
'contributions' => 1,
];
} else {
$authors[$matches[2][$i]]['contributions']++;
++$authors[$matches[2][$i]]['contributions'];
}
}
}
}
}
14 changes: 6 additions & 8 deletions src/Service/GithubUsernameProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

declare(strict_types=1);


namespace Nyholm\GitReviewer\Service;


use Github\Client;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
Expand All @@ -18,9 +16,6 @@ class GithubUsernameProvider
private $github;
private $cache;

/**
* @param Client $github
*/
public function __construct(Client $github, CacheInterface $cache)
{
$this->github = $github;
Expand All @@ -30,16 +25,19 @@ public function __construct(Client $github, CacheInterface $cache)
public function findUsername(string $email, string $name): ?string
{
$key = 'user_'.sha1($email.$name);

return $this->cache->get($key, function (ItemInterface $item) use ($email, $name) {
$byEmail = $this->github->search()->users($email.' in:email type:users ');
if ($byEmail['total_count'] === 1) {
if (1 === $byEmail['total_count']) {
$item->expiresAfter(31536000);

return $byEmail['items'][0]['login'];
}

$byName = $this->github->search()->users('type:users fullname:'.sprintf('"%s"', $name));
if ($byName['total_count'] === 1) {
if (1 === $byName['total_count']) {
$item->expiresAfter(31536000);

return $byName['items'][0]['login'];
}

Expand All @@ -48,4 +46,4 @@ public function findUsername(string $email, string $name): ?string
return null;
});
}
}
}

0 comments on commit 2a8426a

Please sign in to comment.