Pull-request: #19458
Fixes: #19455
Ref: d8c97ad84a
Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
commit
704f673307
@ -4,11 +4,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Command;
|
||||
|
||||
use PhpMyAdmin\Git;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use function explode;
|
||||
use function file_put_contents;
|
||||
use function is_string;
|
||||
use function shell_exec;
|
||||
@ -34,9 +36,21 @@ declare(strict_types=1);
|
||||
*/
|
||||
return [
|
||||
'revision' => '%s',
|
||||
'revisionHash' => '%s',
|
||||
'revisionUrl' => '%s',
|
||||
'branch' => '%s',
|
||||
'branchUrl' => '%s',
|
||||
'message' => '%s',
|
||||
'author' => [
|
||||
'name' => '%s',
|
||||
'email' => '%s',
|
||||
'date' => '%s',
|
||||
],
|
||||
'committer' => [
|
||||
'name' => '%s',
|
||||
'email' => '%s',
|
||||
'date' => '%s',
|
||||
],
|
||||
];
|
||||
|
||||
PHP;
|
||||
@ -101,14 +115,31 @@ PHP;
|
||||
return null;
|
||||
}
|
||||
|
||||
$commitDetails = $this->gitCli(
|
||||
'show -s --pretty=\'tree %T%nparent %P%nauthor %an <%ae> %at%ncommitter %cn <%ce> %ct%n%B\''
|
||||
);
|
||||
if ($commitDetails === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$branchName = trim(str_replace('refs/heads/', '', $branchName));
|
||||
|
||||
[$author, $committer, $message] = Git::extractDataFormTextBody(explode("\n", $commitDetails));
|
||||
|
||||
return sprintf(
|
||||
self::$generatedClassTemplate,
|
||||
trim($revisionText),
|
||||
trim($commitHash),
|
||||
sprintf($commitUrlFormat, trim($commitHash)),
|
||||
trim($branchName),
|
||||
sprintf($branchUrlFormat, $branchName)
|
||||
sprintf($branchUrlFormat, $branchName),
|
||||
trim($message), // Commit message
|
||||
trim($author['name']), // Author name
|
||||
trim($author['email']), // Author email
|
||||
trim($author['date']), // Author date
|
||||
trim($committer['name']), // Committer name
|
||||
trim($committer['email']), // Committer email
|
||||
trim($committer['date']) // Committer date
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -27,6 +27,7 @@ use function gzuncompress;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
use function intval;
|
||||
use function is_array;
|
||||
use function is_bool;
|
||||
use function is_dir;
|
||||
use function is_file;
|
||||
@ -104,7 +105,9 @@ class Git
|
||||
// find out if there is a .git folder
|
||||
// or a .git file (--separate-git-dir)
|
||||
$git = $this->baseDir . '.git';
|
||||
if (is_dir($git)) {
|
||||
if (file_exists($this->baseDir . 'revision-info.php')) {
|
||||
$git_location = 'revision-info.php';
|
||||
} elseif (is_dir($git)) {
|
||||
if (! @is_file($git . '/config')) {
|
||||
$_SESSION['git_location'] = null;
|
||||
$_SESSION['is_git_revision'] = false;
|
||||
@ -367,11 +370,11 @@ class Git
|
||||
/**
|
||||
* Extract committer, author and message from commit body
|
||||
*
|
||||
* @param array $commit The commit body
|
||||
* @param string[] $commit The commit body
|
||||
*
|
||||
* @return array<int,array<string,string>|string>
|
||||
*/
|
||||
private function extractDataFormTextBody(array $commit): array
|
||||
public static function extractDataFormTextBody(array $commit): array
|
||||
{
|
||||
$author = [
|
||||
'name' => '',
|
||||
@ -557,6 +560,38 @@ class Git
|
||||
return null;
|
||||
}
|
||||
|
||||
// Special name to indicate the use of the config file
|
||||
if ($gitFolder === 'revision-info.php') {
|
||||
/** @psalm-suppress MissingFile,UnresolvableInclude */
|
||||
$info = include $this->baseDir . 'revision-info.php';
|
||||
|
||||
if (! is_array($info)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->hasGit = true;
|
||||
|
||||
return [
|
||||
'hash' => $info['revisionHash'],
|
||||
'branch' => $info['branch'],
|
||||
'message' => $info['message'],
|
||||
'author' => [
|
||||
'name' => $info['author']['name'],
|
||||
'email' => $info['author']['email'],
|
||||
'date' => $info['author']['date'],
|
||||
],
|
||||
'committer' => [
|
||||
'name' => $info['committer']['name'],
|
||||
'email' => $info['committer']['email'],
|
||||
'date' => $info['committer']['date'],
|
||||
],
|
||||
// Let's make the guess that the data is remote
|
||||
// The write script builds a remote commit url without checking that it exists
|
||||
'is_remote_commit' => true,
|
||||
'is_remote_branch' => true,
|
||||
];
|
||||
}
|
||||
|
||||
$ref_head = @file_get_contents($gitFolder . '/HEAD');
|
||||
|
||||
if (! $ref_head) {
|
||||
@ -616,7 +651,7 @@ class Git
|
||||
}
|
||||
|
||||
if ($commit !== false) {
|
||||
[$author, $committer, $message] = $this->extractDataFormTextBody($commit);
|
||||
[$author, $committer, $message] = self::extractDataFormTextBody($commit);
|
||||
} elseif (isset($commit_json->author, $commit_json->committer, $commit_json->message)) {
|
||||
$author = [
|
||||
'name' => $commit_json->author->name,
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
<arg name="extensions" value="php"/>
|
||||
|
||||
<file>.</file>
|
||||
<!-- Make sniff report relative -->
|
||||
<arg name="basepath" value="."/>
|
||||
|
||||
<exclude-pattern>*/build/*</exclude-pattern>
|
||||
<exclude-pattern>*/config.inc.php</exclude-pattern>
|
||||
@ -15,6 +17,7 @@
|
||||
<exclude-pattern>*/libraries/language_stats.inc.php</exclude-pattern>
|
||||
<exclude-pattern>*/node_modules/*</exclude-pattern>
|
||||
<exclude-pattern>*/test/doctum-config.php</exclude-pattern>
|
||||
<exclude-pattern>*/revision-info.php</exclude-pattern>
|
||||
<exclude-pattern>*/tmp/*</exclude-pattern>
|
||||
<exclude-pattern>*/twig-templates/*</exclude-pattern>
|
||||
<exclude-pattern>*/vendor/*</exclude-pattern>
|
||||
|
||||
@ -780,11 +780,31 @@ parameters:
|
||||
count: 1
|
||||
path: libraries/classes/Command/TwigLintCommand.php
|
||||
|
||||
-
|
||||
message: "#^Offset 'date' does not exist on array\\<string, string\\>\\|string\\.$#"
|
||||
count: 2
|
||||
path: libraries/classes/Command/WriteGitRevisionCommand.php
|
||||
|
||||
-
|
||||
message: "#^Offset 'email' does not exist on array\\<string, string\\>\\|string\\.$#"
|
||||
count: 2
|
||||
path: libraries/classes/Command/WriteGitRevisionCommand.php
|
||||
|
||||
-
|
||||
message: "#^Offset 'name' does not exist on array\\<string, string\\>\\|string\\.$#"
|
||||
count: 2
|
||||
path: libraries/classes/Command/WriteGitRevisionCommand.php
|
||||
|
||||
-
|
||||
message: "#^PHPDoc type string of property PhpMyAdmin\\\\Command\\\\WriteGitRevisionCommand\\:\\:\\$defaultName is not the same as PHPDoc type string\\|null of overridden property Symfony\\\\Component\\\\Console\\\\Command\\\\Command\\:\\:\\$defaultName\\.$#"
|
||||
count: 1
|
||||
path: libraries/classes/Command/WriteGitRevisionCommand.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$str of function trim expects string, array\\<string, string\\>\\|string given\\.$#"
|
||||
count: 1
|
||||
path: libraries/classes/Command/WriteGitRevisionCommand.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access offset 'Server' on mixed\\.$#"
|
||||
count: 1
|
||||
@ -15567,12 +15587,7 @@ parameters:
|
||||
|
||||
-
|
||||
message: "#^Method PhpMyAdmin\\\\Dbal\\\\MysqliResult\\:\\:fetchAllKeyPair\\(\\) should return array\\<string, string\\|null\\> but returns array\\.$#"
|
||||
count: 1
|
||||
path: libraries/classes/Dbal/MysqliResult.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpMyAdmin\\\\Dbal\\\\MysqliResult\\:\\:fetchAllKeyPair\\(\\) should return array\\<string, string\\|null\\> but returns array\\<int\\|string, mixed\\>\\.$#"
|
||||
count: 1
|
||||
count: 2
|
||||
path: libraries/classes/Dbal/MysqliResult.php
|
||||
|
||||
-
|
||||
@ -19455,6 +19470,21 @@ parameters:
|
||||
count: 1
|
||||
path: libraries/classes/Git.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access offset 'date' on mixed\\.$#"
|
||||
count: 2
|
||||
path: libraries/classes/Git.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access offset 'email' on mixed\\.$#"
|
||||
count: 2
|
||||
path: libraries/classes/Git.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access offset 'name' on mixed\\.$#"
|
||||
count: 2
|
||||
path: libraries/classes/Git.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access offset 1 on array\\|false\\.$#"
|
||||
count: 2
|
||||
@ -19495,11 +19525,6 @@ parameters:
|
||||
count: 1
|
||||
path: libraries/classes/Git.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpMyAdmin\\\\Git\\:\\:extractDataFormTextBody\\(\\) has parameter \\$commit with no value type specified in iterable type array\\.$#"
|
||||
count: 1
|
||||
path: libraries/classes/Git.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpMyAdmin\\\\Git\\:\\:getHashFromHeadRef\\(\\) return type has no value type specified in iterable type array\\.$#"
|
||||
count: 1
|
||||
@ -19551,7 +19576,7 @@ parameters:
|
||||
path: libraries/classes/Git.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$commit of method PhpMyAdmin\\\\Git\\:\\:extractDataFormTextBody\\(\\) expects array, mixed given\\.$#"
|
||||
message: "#^Parameter \\#1 \\$commit of static method PhpMyAdmin\\\\Git\\:\\:extractDataFormTextBody\\(\\) expects array\\<string\\>, mixed given\\.$#"
|
||||
count: 1
|
||||
path: libraries/classes/Git.php
|
||||
|
||||
@ -19616,7 +19641,7 @@ parameters:
|
||||
path: libraries/classes/Git.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$str of function explode expects string, mixed given\\.$#"
|
||||
message: "#^Parameter \\#2 \\$str of function explode expects string, string\\|null given\\.$#"
|
||||
count: 1
|
||||
path: libraries/classes/Git.php
|
||||
|
||||
@ -45090,6 +45115,16 @@ parameters:
|
||||
count: 1
|
||||
path: test/classes/Gis/GisPolygonTest.php
|
||||
|
||||
-
|
||||
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsArray\\(\\) with array will always evaluate to true\\.$#"
|
||||
count: 1
|
||||
path: test/classes/GitTest.php
|
||||
|
||||
-
|
||||
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotNull\\(\\) with array will always evaluate to true\\.$#"
|
||||
count: 1
|
||||
path: test/classes/GitTest.php
|
||||
|
||||
-
|
||||
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#"
|
||||
count: 2
|
||||
|
||||
@ -266,9 +266,28 @@
|
||||
</UnusedVariable>
|
||||
</file>
|
||||
<file src="libraries/classes/Command/WriteGitRevisionCommand.php">
|
||||
<MixedArgument occurrences="6">
|
||||
<code>$author['date']</code>
|
||||
<code>$author['email']</code>
|
||||
<code>$author['name']</code>
|
||||
<code>$committer['date']</code>
|
||||
<code>$committer['email']</code>
|
||||
<code>$committer['name']</code>
|
||||
</MixedArgument>
|
||||
<NonInvariantDocblockPropertyType occurrences="1">
|
||||
<code>$defaultName</code>
|
||||
</NonInvariantDocblockPropertyType>
|
||||
<PossiblyInvalidArgument occurrences="1">
|
||||
<code>$message</code>
|
||||
</PossiblyInvalidArgument>
|
||||
<PossiblyInvalidArrayOffset occurrences="6">
|
||||
<code>$author['date']</code>
|
||||
<code>$author['email']</code>
|
||||
<code>$author['name']</code>
|
||||
<code>$committer['date']</code>
|
||||
<code>$committer['email']</code>
|
||||
<code>$committer['name']</code>
|
||||
</PossiblyInvalidArrayOffset>
|
||||
</file>
|
||||
<file src="libraries/classes/Common.php">
|
||||
<MixedArgument occurrences="5">
|
||||
@ -6744,26 +6763,28 @@
|
||||
<InvalidArgument occurrences="1">
|
||||
<code>$params</code>
|
||||
</InvalidArgument>
|
||||
<InvalidReturnStatement occurrences="1">
|
||||
<code>is_array($info) ? $info : []</code>
|
||||
</InvalidReturnStatement>
|
||||
<InvalidReturnType occurrences="1">
|
||||
<code>array{revision: string, revisionUrl: string, branch: string, branchUrl: string}|[]</code>
|
||||
</InvalidReturnType>
|
||||
<MixedArgument occurrences="2">
|
||||
<code>$db</code>
|
||||
<code>$table</code>
|
||||
</MixedArgument>
|
||||
<MixedAssignment occurrences="4">
|
||||
<code>$info</code>
|
||||
<MixedAssignment occurrences="3">
|
||||
<code>$params['route']</code>
|
||||
<code>$params['server']</code>
|
||||
<code>$subObject</code>
|
||||
</MixedAssignment>
|
||||
<MixedReturnTypeCoercion occurrences="2">
|
||||
<code>array{revision: string, revisionUrl: string, branch: string, branchUrl: string}|[]</code>
|
||||
<code>is_array($info) ? $info : []</code>
|
||||
</MixedReturnTypeCoercion>
|
||||
<RedundantCast occurrences="3">
|
||||
<code>(string) $GLOBALS['db']</code>
|
||||
<code>(string) $GLOBALS['table']</code>
|
||||
<code>(string) $_REQUEST['no_history']</code>
|
||||
</RedundantCast>
|
||||
<RedundantCondition occurrences="4">
|
||||
<RedundantCondition occurrences="5">
|
||||
<code>is_array($info)</code>
|
||||
<code>is_scalar($GLOBALS['db'])</code>
|
||||
<code>is_scalar($GLOBALS['table'])</code>
|
||||
<code>isset($GLOBALS['db']) && is_scalar($GLOBALS['db'])</code>
|
||||
@ -6772,6 +6793,9 @@
|
||||
<TypeDoesNotContainNull occurrences="2">
|
||||
<code>! isset($dbi)</code>
|
||||
</TypeDoesNotContainNull>
|
||||
<TypeDoesNotContainType occurrences="1">
|
||||
<code>[]</code>
|
||||
</TypeDoesNotContainType>
|
||||
</file>
|
||||
<file src="libraries/classes/Gis/GisGeometry.php">
|
||||
<MixedArgument occurrences="7">
|
||||
@ -7542,22 +7566,25 @@
|
||||
</RedundantConditionGivenDocblockType>
|
||||
</file>
|
||||
<file src="libraries/classes/Git.php">
|
||||
<MixedArgument occurrences="8">
|
||||
<MixedArgument occurrences="7">
|
||||
<code>$commit</code>
|
||||
<code>$commit_json->message</code>
|
||||
<code>$dataline</code>
|
||||
<code>$hash</code>
|
||||
<code>$hash</code>
|
||||
<code>$hash</code>
|
||||
<code>$offset + ($position * 20)</code>
|
||||
<code>$offset + ($position * 4)</code>
|
||||
</MixedArgument>
|
||||
<MixedArgumentTypeCoercion occurrences="1">
|
||||
<MixedArrayAccess occurrences="6">
|
||||
<code>$info['author']['date']</code>
|
||||
<code>$info['author']['email']</code>
|
||||
<code>$info['author']['name']</code>
|
||||
<code>$info['committer']['date']</code>
|
||||
<code>$info['committer']['email']</code>
|
||||
<code>$info['committer']['name']</code>
|
||||
</MixedArrayAccess>
|
||||
<MixedAssignment occurrences="9">
|
||||
<code>$commit</code>
|
||||
</MixedArgumentTypeCoercion>
|
||||
<MixedAssignment occurrences="10">
|
||||
<code>$commit</code>
|
||||
<code>$dataline</code>
|
||||
<code>$end</code>
|
||||
<code>$git_location</code>
|
||||
<code>$isRemoteCommit</code>
|
||||
@ -15517,6 +15544,11 @@
|
||||
<code>$queryString</code>
|
||||
</MixedAssignment>
|
||||
</file>
|
||||
<file src="test/classes/GitTest.php">
|
||||
<RedundantConditionGivenDocblockType occurrences="1">
|
||||
<code>assertIsArray</code>
|
||||
</RedundantConditionGivenDocblockType>
|
||||
</file>
|
||||
<file src="test/classes/HeaderTest.php">
|
||||
<MixedInferredReturnType occurrences="1">
|
||||
<code>array</code>
|
||||
|
||||
@ -9,6 +9,7 @@ use PhpMyAdmin\Tests\AbstractTestCase;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
use function class_exists;
|
||||
use function implode;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
@ -32,17 +33,35 @@ class WriteGitRevisionCommandTest extends AbstractTestCase
|
||||
->onlyMethods(['gitCli'])
|
||||
->getMock();
|
||||
|
||||
$this->command->expects($this->exactly(3))
|
||||
$this->command->expects($this->exactly(4))
|
||||
->method('gitCli')
|
||||
->withConsecutive(
|
||||
['describe --always'],
|
||||
['log -1 --format="%H"'],
|
||||
['symbolic-ref -q HEAD']
|
||||
['symbolic-ref -q HEAD'],
|
||||
['show -s --pretty=\'tree %T%nparent %P%nauthor %an <%ae> %at%ncommitter %cn <%ce> %ct%n%B\'']
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
'RELEASE_5_1_0-638-g1c018e2a6c',
|
||||
'1c018e2a6c6d518c4a2dde059e49f33af67c4636',
|
||||
'refs/heads/cli-rev-info'
|
||||
'refs/heads/cli-rev-info',
|
||||
implode("\n", [
|
||||
'tree 6857f00bb50360825c7df2c40ad21006c30beca7',
|
||||
'parent 1634264816449dc42d17872174f3e8d73d4e36b2',
|
||||
'author John Doe <john.doe@example.org> 1734427284',
|
||||
'committer Hosted Weblate <hosted@weblate.org> 1734516032',
|
||||
'',
|
||||
'Translated using Weblate (Finnish)',
|
||||
'',
|
||||
'Currently translated at 61.4% (2105 of 3428 strings)',
|
||||
'',
|
||||
'[ci skip]',
|
||||
'',
|
||||
'Translation: phpMyAdmin/5.2',
|
||||
'Translate-URL: https://hosted.weblate.org/projects/phpmyadmin/5-2/fi/',
|
||||
'Signed-off-by: John Doe <john.doe@example.org>',
|
||||
'',
|
||||
])
|
||||
);
|
||||
|
||||
$output = $this->callFunction(
|
||||
@ -66,18 +85,42 @@ declare(strict_types=1);
|
||||
*/
|
||||
return [
|
||||
'revision' => '%s',
|
||||
'revisionHash' => '%s',
|
||||
'revisionUrl' => '%s',
|
||||
'branch' => '%s',
|
||||
'branchUrl' => '%s',
|
||||
'message' => '%s',
|
||||
'author' => [
|
||||
'name' => '%s',
|
||||
'email' => '%s',
|
||||
'date' => '%s',
|
||||
],
|
||||
'committer' => [
|
||||
'name' => '%s',
|
||||
'email' => '%s',
|
||||
'date' => '%s',
|
||||
],
|
||||
];
|
||||
|
||||
PHP;
|
||||
self::assertSame(sprintf(
|
||||
$template,
|
||||
'RELEASE_5_1_0-638-g1c018e2a6c',
|
||||
'1c018e2a6c6d518c4a2dde059e49f33af67c4636',
|
||||
'https://github.com/phpmyadmin/phpmyadmin/commit/1c018e2a6c6d518c4a2dde059e49f33af67c4636',
|
||||
'cli-rev-info',
|
||||
'https://github.com/phpmyadmin/phpmyadmin/tree/cli-rev-info'
|
||||
'https://github.com/phpmyadmin/phpmyadmin/tree/cli-rev-info',
|
||||
'Translated using Weblate (Finnish) '
|
||||
. ' Currently translated at 61.4% (2105 of 3428 strings) '
|
||||
. ' [ci skip] Translation: phpMyAdmin/5.2 '
|
||||
. 'Translate-URL: https://hosted.weblate.org/projects/phpmyadmin/5-2/fi/'
|
||||
. ' Signed-off-by: John Doe <john.doe@example.org>', // Commit message
|
||||
'John Doe', // Author name
|
||||
'john.doe@example.org', // Author email
|
||||
'2024-12-17 09:21:24 +0000', // Author date
|
||||
'Hosted Weblate', // Committer name
|
||||
'hosted@weblate.org', // Committer email
|
||||
'2024-12-18 10:00:32 +0000' // Committer date
|
||||
), $output);
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,6 +150,71 @@ class GitTest extends AbstractTestCase
|
||||
rmdir($this->testDir . '.customgitdir');
|
||||
}
|
||||
|
||||
private function getRevisionInfoTestData(): string
|
||||
{
|
||||
// phpcs:disable Generic.Files.LineLength.TooLong
|
||||
return <<<'PHP'
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is generated by scripts/console.
|
||||
*
|
||||
* @see \PhpMyAdmin\Command\WriteGitRevisionCommand
|
||||
*/
|
||||
return [
|
||||
'revision' => 'RELEASE_5_2_1-1086-g97b9895908',
|
||||
'revisionHash' => '97b9895908f281b62c985857798281a0b3e5d1e6',
|
||||
'revisionUrl' => 'https://github.com/phpmyadmin/phpmyadmin/commit/97b9895908f281b62c985857798281a0b3e5d1e6',
|
||||
'branch' => 'QA_5_2',
|
||||
'branchUrl' => 'https://github.com/phpmyadmin/phpmyadmin/tree/QA_5_2',
|
||||
'message' => 'Currently translated at 61.4% (2105 of 3428 strings) [ci skip] Translation: phpMyAdmin/5.2 Translate-URL: https://hosted.weblate.org/projects/phpmyadmin/5-2/fi/ Signed-off-by: John Doe <john.doe@example.org>',
|
||||
'author' => [
|
||||
'name' => 'John Doe',
|
||||
'email' => 'john.doe@example.org',
|
||||
'date' => '2024-12-17 09:21:24 +0000',
|
||||
],
|
||||
'committer' => [
|
||||
'name' => 'Hosted Weblate',
|
||||
'email' => 'hosted@weblate.org',
|
||||
'date' => '2024-12-18 10:00:32 +0000',
|
||||
],
|
||||
];
|
||||
|
||||
PHP;
|
||||
// phpcs:enable
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for isGitRevision
|
||||
*
|
||||
* @group git-revision
|
||||
*/
|
||||
public function testIsGitRevisionRevisionInfo(): void
|
||||
{
|
||||
$gitLocation = '';
|
||||
self::assertFalse($this->object->hasGitInformation());
|
||||
self::assertFalse($this->object->isGitRevision($gitLocation));
|
||||
self::assertFalse($this->object->hasGitInformation());
|
||||
self::assertSame('', $gitLocation);
|
||||
|
||||
unset($_SESSION['git_location']);
|
||||
unset($_SESSION['is_git_revision']);
|
||||
|
||||
file_put_contents(
|
||||
$this->testDir . 'revision-info.php',
|
||||
$this->getRevisionInfoTestData()
|
||||
);
|
||||
|
||||
self::assertTrue($this->object->isGitRevision($gitLocation));
|
||||
self::assertSame('revision-info.php', $gitLocation);
|
||||
self::assertNotNull($this->object->checkGitRevision());
|
||||
self::assertTrue($this->object->hasGitInformation());
|
||||
|
||||
unlink($this->testDir . 'revision-info.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for checkGitRevision packs folder
|
||||
*
|
||||
@ -359,6 +424,65 @@ class GitTest extends AbstractTestCase
|
||||
self::assertIsString($commit['committer']['date']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for checkGitRevision with a revision-info.php file
|
||||
*
|
||||
* @group git-revision
|
||||
*/
|
||||
public function testCheckGitRevisionRevisionInfo(): void
|
||||
{
|
||||
file_put_contents(
|
||||
$this->testDir . 'revision-info.php',
|
||||
$this->getRevisionInfoTestData()
|
||||
);
|
||||
|
||||
$gitLocation = '';
|
||||
self::assertFalse($this->object->hasGitInformation());
|
||||
self::assertNotNull($this->object->checkGitRevision());
|
||||
self::assertTrue($this->object->hasGitInformation());
|
||||
self::assertTrue($this->object->isGitRevision($gitLocation));
|
||||
self::assertSame('revision-info.php', $gitLocation);
|
||||
|
||||
$commit = $this->object->checkGitRevision();
|
||||
// Delete the dataset
|
||||
unlink($this->testDir . 'revision-info.php');
|
||||
|
||||
self::assertNotNull($commit);
|
||||
self::assertIsArray($commit);
|
||||
self::assertArrayHasKey('hash', $commit);
|
||||
self::assertSame('97b9895908f281b62c985857798281a0b3e5d1e6', $commit['hash']);
|
||||
|
||||
self::assertArrayHasKey('branch', $commit);
|
||||
self::assertSame('QA_5_2', $commit['branch']);
|
||||
|
||||
self::assertArrayHasKey('message', $commit);
|
||||
self::assertIsString($commit['message']);
|
||||
|
||||
self::assertArrayHasKey('is_remote_commit', $commit);
|
||||
self::assertIsBool($commit['is_remote_commit']);
|
||||
|
||||
self::assertArrayHasKey('is_remote_branch', $commit);
|
||||
self::assertIsBool($commit['is_remote_branch']);
|
||||
|
||||
self::assertArrayHasKey('author', $commit);
|
||||
self::assertIsArray($commit['author']);
|
||||
self::assertArrayHasKey('name', $commit['author']);
|
||||
self::assertArrayHasKey('email', $commit['author']);
|
||||
self::assertArrayHasKey('date', $commit['author']);
|
||||
self::assertIsString($commit['author']['name']);
|
||||
self::assertIsString($commit['author']['email']);
|
||||
self::assertIsString($commit['author']['date']);
|
||||
|
||||
self::assertArrayHasKey('committer', $commit);
|
||||
self::assertIsArray($commit['committer']);
|
||||
self::assertArrayHasKey('name', $commit['committer']);
|
||||
self::assertArrayHasKey('email', $commit['committer']);
|
||||
self::assertArrayHasKey('date', $commit['committer']);
|
||||
self::assertIsString($commit['committer']['name']);
|
||||
self::assertIsString($commit['committer']['email']);
|
||||
self::assertIsString($commit['committer']['date']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for checkGitRevision
|
||||
*/
|
||||
@ -418,38 +542,33 @@ class GitTest extends AbstractTestCase
|
||||
*/
|
||||
public function testExtractDataFormTextBody(): void
|
||||
{
|
||||
$extractedData = $this->callFunction(
|
||||
$this->object,
|
||||
Git::class,
|
||||
'extractDataFormTextBody',
|
||||
$extractedData = Git::extractDataFormTextBody(
|
||||
[
|
||||
[
|
||||
'tree ed7fec263e1813887001855ddca9293479289180',
|
||||
'parent 90543399991cdb294185f90e8ae1a45e059c31ab',
|
||||
'author William Desportes <williamdes@wdes.fr> 1657717000 +0200',
|
||||
'committer William Desportes <williamdes@wdes.fr> 1657717000 +0200',
|
||||
'gpgsig -----BEGIN PGP SIGNATURE-----',
|
||||
' ',
|
||||
' iQIzBAABCgAdFiEExNkf3872tKPGU\/14kKDvG4JRqIkFAmLOwQgACgkQkKDvG4JR',
|
||||
' qIn8Kg\/+Os5e3bFLEtd3q\/w3e4IfvR64rdadA4IUugd4pJvGqJHleJNBQ8PNqwjR',
|
||||
' 9W0S9PQXAsul0XW5YtuLmBMGFFQDOab2ieix9CVA1w0D7quVQR8uLNb1Gln28NuS',
|
||||
' 6b24Q4cAQlp5uOoKT3ohRBUtGmu8SXF8Q\/5BwPY1AuL1LqY6w6EwSsInPXK1Yq3r',
|
||||
' RShxRXDhonKx3NqoCdRkWmAKkQrztWGGBI7mBG\/\/X0F4hSjsuwdpHBsl6yyri9p2',
|
||||
' bJbyAI+xQ+rBHb0iFIoLbxj6G1EkEmpISl+4980uef24SwMVk9ZOfH8cAgBZ62Mf',
|
||||
' xJ3f99ujhD9dvwCQivOwcEav+fPObiLC0EzfoqZgB7rTQdxUIu7WRpShZGwfuiEv',
|
||||
' sBmvQcnZptYHi0Kk78fdzISCQcPBgCw0gGcv+yLOE3HuQ24B+ncCusYdxyJQqMSc',
|
||||
' pm9vVHpwioufy5c7aBa05K7f2b1AhiZeVpT2t\/rboIYlIhQGY9uRNGX44Qtt6Oeb',
|
||||
' G6aU8O7gS5+Wsj00K+uSvUE\/znxx7Ad0zVuFQGUAhd3cDp9T09+FIr4TOE+3Z4Pk',
|
||||
' PlssVGVBdbaNaI0\/eV6fTa6B0hMH9mhmZhtHLXdsTw5xVySz7by5DZqZldydSFtk',
|
||||
' tVuUPxykK6F0qY79IPBH8Unx8egIlSzKWfP0JpRd+otemBnTKWg=',
|
||||
' =BVHc',
|
||||
' -----END PGP SIGNATURE-----',
|
||||
'',
|
||||
'Remove ignore config.inc.php for psalm because it fails the CI',
|
||||
'',
|
||||
'Signed-off-by: William Desportes <williamdes@wdes.fr>',
|
||||
'',
|
||||
],
|
||||
'tree ed7fec263e1813887001855ddca9293479289180',
|
||||
'parent 90543399991cdb294185f90e8ae1a45e059c31ab',
|
||||
'author William Desportes <williamdes@wdes.fr> 1657717000 +0200',
|
||||
'committer William Desportes <williamdes@wdes.fr> 1657717000 +0200',
|
||||
'gpgsig -----BEGIN PGP SIGNATURE-----',
|
||||
' ',
|
||||
' iQIzBAABCgAdFiEExNkf3872tKPGU\/14kKDvG4JRqIkFAmLOwQgACgkQkKDvG4JR',
|
||||
' qIn8Kg\/+Os5e3bFLEtd3q\/w3e4IfvR64rdadA4IUugd4pJvGqJHleJNBQ8PNqwjR',
|
||||
' 9W0S9PQXAsul0XW5YtuLmBMGFFQDOab2ieix9CVA1w0D7quVQR8uLNb1Gln28NuS',
|
||||
' 6b24Q4cAQlp5uOoKT3ohRBUtGmu8SXF8Q\/5BwPY1AuL1LqY6w6EwSsInPXK1Yq3r',
|
||||
' RShxRXDhonKx3NqoCdRkWmAKkQrztWGGBI7mBG\/\/X0F4hSjsuwdpHBsl6yyri9p2',
|
||||
' bJbyAI+xQ+rBHb0iFIoLbxj6G1EkEmpISl+4980uef24SwMVk9ZOfH8cAgBZ62Mf',
|
||||
' xJ3f99ujhD9dvwCQivOwcEav+fPObiLC0EzfoqZgB7rTQdxUIu7WRpShZGwfuiEv',
|
||||
' sBmvQcnZptYHi0Kk78fdzISCQcPBgCw0gGcv+yLOE3HuQ24B+ncCusYdxyJQqMSc',
|
||||
' pm9vVHpwioufy5c7aBa05K7f2b1AhiZeVpT2t\/rboIYlIhQGY9uRNGX44Qtt6Oeb',
|
||||
' G6aU8O7gS5+Wsj00K+uSvUE\/znxx7Ad0zVuFQGUAhd3cDp9T09+FIr4TOE+3Z4Pk',
|
||||
' PlssVGVBdbaNaI0\/eV6fTa6B0hMH9mhmZhtHLXdsTw5xVySz7by5DZqZldydSFtk',
|
||||
' tVuUPxykK6F0qY79IPBH8Unx8egIlSzKWfP0JpRd+otemBnTKWg=',
|
||||
' =BVHc',
|
||||
' -----END PGP SIGNATURE-----',
|
||||
'',
|
||||
'Remove ignore config.inc.php for psalm because it fails the CI',
|
||||
'',
|
||||
'Signed-off-by: William Desportes <williamdes@wdes.fr>',
|
||||
'',
|
||||
]
|
||||
);
|
||||
|
||||
@ -468,4 +587,48 @@ class GitTest extends AbstractTestCase
|
||||
. 'it fails the CI Signed-off-by: William Desportes <williamdes@wdes.fr>',
|
||||
], $extractedData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we can extract values from Git CLI format
|
||||
*/
|
||||
public function testExtractDataFormTextBodySecondFormat(): void
|
||||
{
|
||||
$extractedData = Git::extractDataFormTextBody(
|
||||
[
|
||||
'tree 6857f00bb50360825c7df2c40ad21006c30beca7',
|
||||
'parent 1634264816449dc42d17872174f3e8d73d4e36b2',
|
||||
'author John Doe <john.doe@example.org> 1734427284',
|
||||
'committer Hosted Weblate <hosted@weblate.org> 1734516032',
|
||||
'',
|
||||
'Translated using Weblate (Finnish)',
|
||||
'',
|
||||
'Currently translated at 61.4% (2105 of 3428 strings)',
|
||||
'',
|
||||
'[ci skip]',
|
||||
'',
|
||||
'Translation: phpMyAdmin/5.2',
|
||||
'Translate-URL: https://hosted.weblate.org/projects/phpmyadmin/5-2/fi/',
|
||||
'Signed-off-by: John Doe <john.doe@example.org>',
|
||||
'',
|
||||
]
|
||||
);
|
||||
|
||||
self::assertSame([
|
||||
[
|
||||
'name' => 'John Doe',
|
||||
'email' => 'john.doe@example.org',
|
||||
'date' => '2024-12-17 09:21:24 +0000',
|
||||
],
|
||||
[
|
||||
'name' => 'Hosted Weblate',
|
||||
'email' => 'hosted@weblate.org',
|
||||
'date' => '2024-12-18 10:00:32 +0000',
|
||||
],
|
||||
'Translated using Weblate (Finnish) '
|
||||
. ' Currently translated at 61.4% (2105 of 3428 strings) '
|
||||
. ' [ci skip] Translation: phpMyAdmin/5.2 '
|
||||
. 'Translate-URL: https://hosted.weblate.org/projects/phpmyadmin/5-2/fi/'
|
||||
. ' Signed-off-by: John Doe <john.doe@example.org>',
|
||||
], $extractedData);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user