Skip to content

Commit

Permalink
Import native functions, use PathUtils instead of custom functions, f…
Browse files Browse the repository at this point in the history
…ix escaped mutant
  • Loading branch information
maks-rafalko committed Oct 28, 2020
1 parent 521d92d commit 9b066a3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mt-annotations.yaml
@@ -1,7 +1,7 @@
# yamllint disable rule:line-length
# yamllint disable rule:braces

name: Infection
name: Autoreview

on:
pull_request:
Expand Down
2 changes: 2 additions & 0 deletions src/Logger/GitHub/GitDiffFileProvider.php
Expand Up @@ -35,7 +35,9 @@

namespace Infection\Logger\GitHub;

use function escapeshellarg;
use function Safe\sprintf;
use function shell_exec;

/**
* @final
Expand Down
17 changes: 7 additions & 10 deletions src/Logger/GitHubAnnotationsLogger.php
Expand Up @@ -37,6 +37,8 @@

use Infection\Metrics\MetricsCalculator;
use function Safe\getcwd;
use function str_replace;
use Webmozart\PathUtil\Path;

/**
* @internal
Expand All @@ -57,7 +59,7 @@ public function getLogLines(): array

foreach ($this->metricsCalculator->getEscapedExecutionResults() as $escapedExecutionResult) {
$error = [
'line' => (string) $escapedExecutionResult->getOriginalStartingLine(),
'line' => $escapedExecutionResult->getOriginalStartingLine(),
'message' => <<<"TEXT"
Escaped Mutant:

Expand All @@ -67,28 +69,23 @@ public function getLogLines(): array
];

$lines[] = $this->buildAnnotation(
$this->relativePath($currentWorkingDirectory, $escapedExecutionResult->getOriginalFilePath()),
$error
Path::makeRelative($escapedExecutionResult->getOriginalFilePath(), $currentWorkingDirectory),
$error,
);
}

return $lines;
}

/**
* @param array{line: string, message: string} $error
* @param array{line: int, message: string} $error
*/
private function buildAnnotation(string $filePath, array $error): string
{
// newlines need to be encoded
// new lines need to be encoded
// see https://github.com/actions/starter-workflows/issues/68#issuecomment-581479448
$message = str_replace("\n", '%0A', $error['message']);

return "::warning file={$filePath},line={$error['line']}::{$message}\n";
}

private function relativePath(string $currentWorkingDirectory, string $path): string
{
return str_replace($currentWorkingDirectory . '/', '', $path);
}
}

0 comments on commit 9b066a3

Please sign in to comment.