Ref #19455 - Move all the code for revision-info.php to the Git class
Pull-request: #19458 Ref: #19455 And add one more new line Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
parent
1497a1693e
commit
18f8ae0da1
@ -117,7 +117,7 @@ PHP;
|
||||
}
|
||||
|
||||
$commitDetails = $this->gitCli(
|
||||
'show -s --pretty=\'tree %T%nparent %P%nauthor %an <%ae> %at%ncommitter %cn <%ce> %ct%n%B\''
|
||||
'show -s --pretty=\'tree %T%nparent %P%nauthor %an <%ae> %at%ncommitter %cn <%ce> %ct%n%n%B\''
|
||||
);
|
||||
if ($commitDetails === null) {
|
||||
return null;
|
||||
|
||||
@ -11,7 +11,6 @@ use PhpMyAdmin\ConfigStorage\Relation;
|
||||
use Traversable;
|
||||
|
||||
use function basename;
|
||||
use function file_exists;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function is_object;
|
||||
@ -71,22 +70,6 @@ class Footer
|
||||
$this->relation = new Relation($dbi);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
* @psalm-return array{revision: string, revisionUrl: string, branch: string, branchUrl: string}|[]
|
||||
*/
|
||||
private function getGitRevisionInfo(): array
|
||||
{
|
||||
$info = [];
|
||||
|
||||
if (@file_exists(ROOT_PATH . 'revision-info.php')) {
|
||||
/** @psalm-suppress MissingFile,UnresolvableInclude */
|
||||
$info = include ROOT_PATH . 'revision-info.php';
|
||||
}
|
||||
|
||||
return is_array($info) ? $info : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove recursions and iterator objects from an object
|
||||
*
|
||||
@ -288,7 +271,8 @@ class Footer
|
||||
$scripts = $this->scripts->getDisplay();
|
||||
|
||||
if ($GLOBALS['cfg']['DBG']['demo']) {
|
||||
$gitRevisionInfo = $this->getGitRevisionInfo();
|
||||
$git = new Git(true, ROOT_PATH);
|
||||
$gitRevisionInfo = $git->getGitRevisionInfo();
|
||||
}
|
||||
|
||||
$footer = Config::renderFooter();
|
||||
|
||||
@ -547,6 +547,44 @@ class Git
|
||||
return trim($commonDirContents);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string|array<string, string>>|null
|
||||
* @psalm-return array{
|
||||
* revision: string,
|
||||
* revisionHash: string,
|
||||
* revisionUrl: string,
|
||||
* branch: string,
|
||||
* branchUrl: string,
|
||||
* message: string,
|
||||
* author: array{
|
||||
* name: string,
|
||||
* email: string,
|
||||
* date: string
|
||||
* },
|
||||
* committer: array{
|
||||
* name: string,
|
||||
* email: string,
|
||||
* date: string
|
||||
* }
|
||||
* }|null
|
||||
*/
|
||||
public function getGitRevisionInfo(): ?array
|
||||
{
|
||||
if (@file_exists($this->baseDir . 'revision-info.php')) {
|
||||
/** @var array{ revision: string, revisionHash: string, revisionUrl: string, branch: string, branchUrl: string, message: string, author: array{ name: string, email: string, date: string }, committer: array{ name: string, email: string, date: string }}|null $info */
|
||||
/** @psalm-suppress MissingFile,UnresolvableInclude */
|
||||
$info = include $this->baseDir . 'revision-info.php';
|
||||
|
||||
if (! is_array($info)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* detects Git revision, if running inside repo
|
||||
*/
|
||||
@ -562,10 +600,9 @@ class Git
|
||||
|
||||
// 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';
|
||||
$info = $this->getGitRevisionInfo();
|
||||
|
||||
if (! is_array($info)) {
|
||||
if ($info === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -17950,11 +17950,6 @@ parameters:
|
||||
count: 4
|
||||
path: libraries/classes/Footer.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpMyAdmin\\\\Footer\\:\\:getGitRevisionInfo\\(\\) should return array\\<string, string\\> but returns array\\.$#"
|
||||
count: 1
|
||||
path: libraries/classes/Footer.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpMyAdmin\\\\Footer\\:\\:removeRecursion\\(\\) has parameter \\$stack with no value type specified in iterable type array\\.$#"
|
||||
count: 1
|
||||
@ -19470,21 +19465,6 @@ 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
|
||||
|
||||
@ -6763,12 +6763,6 @@
|
||||
<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>
|
||||
@ -6783,8 +6777,7 @@
|
||||
<code>(string) $GLOBALS['table']</code>
|
||||
<code>(string) $_REQUEST['no_history']</code>
|
||||
</RedundantCast>
|
||||
<RedundantCondition occurrences="5">
|
||||
<code>is_array($info)</code>
|
||||
<RedundantCondition occurrences="4">
|
||||
<code>is_scalar($GLOBALS['db'])</code>
|
||||
<code>is_scalar($GLOBALS['table'])</code>
|
||||
<code>isset($GLOBALS['db']) && is_scalar($GLOBALS['db'])</code>
|
||||
@ -6793,9 +6786,6 @@
|
||||
<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">
|
||||
@ -7575,14 +7565,6 @@
|
||||
<code>$offset + ($position * 20)</code>
|
||||
<code>$offset + ($position * 4)</code>
|
||||
</MixedArgument>
|
||||
<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>
|
||||
<code>$end</code>
|
||||
@ -7621,6 +7603,9 @@
|
||||
<code>$packOffsets[1]</code>
|
||||
<code>json_decode((string) $is_found)</code>
|
||||
</MixedReturnStatement>
|
||||
<MixedReturnTypeCoercion occurrences="2">
|
||||
<code>$info</code>
|
||||
</MixedReturnTypeCoercion>
|
||||
<PossiblyInvalidArrayOffset occurrences="1">
|
||||
<code>$_SESSION['PMA_VERSION_COMMITDATA_' . $hash]</code>
|
||||
</PossiblyInvalidArrayOffset>
|
||||
|
||||
@ -39,7 +39,7 @@ class WriteGitRevisionCommandTest extends AbstractTestCase
|
||||
['describe --always'],
|
||||
['log -1 --format="%H"'],
|
||||
['symbolic-ref -q HEAD'],
|
||||
['show -s --pretty=\'tree %T%nparent %P%nauthor %an <%ae> %at%ncommitter %cn <%ce> %ct%n%B\'']
|
||||
['show -s --pretty=\'tree %T%nparent %P%nauthor %an <%ae> %at%ncommitter %cn <%ce> %ct%n%n%B\'']
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
'RELEASE_5_1_0-638-g1c018e2a6c',
|
||||
|
||||
@ -483,6 +483,48 @@ PHP;
|
||||
self::assertIsString($commit['committer']['date']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getGitRevisionInfo with a revision-info.php file
|
||||
*
|
||||
* @group git-revision
|
||||
*/
|
||||
public function testGetGitRevisionInfo(): void
|
||||
{
|
||||
self::assertNull($this->object->getGitRevisionInfo());
|
||||
|
||||
file_put_contents(
|
||||
$this->testDir . 'revision-info.php',
|
||||
$this->getRevisionInfoTestData()
|
||||
);
|
||||
|
||||
self::assertSame([
|
||||
'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',
|
||||
],
|
||||
|
||||
], $this->object->getGitRevisionInfo());
|
||||
|
||||
// Delete the dataset
|
||||
unlink($this->testDir . 'revision-info.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for checkGitRevision
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user