Skip to content

Commit d4c8710

Browse files
committed
Add the ability in the Api class to fetch timestamps for sub-directories.
1 parent 7f4a23d commit d4c8710

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/Api.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ private function normalizeTreeData($treeData)
417417
/* Add directory timestamp */
418418
$normalizedTreeData = array_map(function ($entry) use ($normalizedTreeData) {
419419
if ($entry[self::KEY_TYPE] === self::KEY_DIRECTORY) {
420-
$directoryTimestamp = $this->getDirectoryTimestamp($normalizedTreeData);
420+
$directoryTimestamp = $this->getDirectoryTimestamp($normalizedTreeData, $entry[self::KEY_PATH]);
421421
$entry[self::KEY_TIMESTAMP] = $directoryTimestamp;
422422
}
423423
return $entry;
@@ -548,20 +548,24 @@ private function hasKey(&$subject, $key)
548548

549549
/**
550550
* @param array $treeMetadata
551+
* @param $path
551552
*
552553
* @return int
553554
*
554555
* @throws \Github\Exception\InvalidArgumentException
555556
*/
556-
private function getDirectoryTimestamp(array $treeMetadata)
557+
private function getDirectoryTimestamp(array $treeMetadata, $path)
557558
{
558559
$directoryTimestamp = 0000000000;
559560

560-
array_walk($treeMetadata, function ($entry) use (&$directoryTimestamp) {
561-
if ($this->hasKey($entry, self::KEY_TIMESTAMP) === false
562-
|| $entry[self::KEY_TIMESTAMP] === false
561+
$filteredTreeData = $this->filterTreeData($treeMetadata, $path, self::RECURSIVE);
562+
563+
array_walk($filteredTreeData, function ($entry) use (&$directoryTimestamp, $path) {
564+
if ($entry[self::KEY_TYPE] !== self::KEY_DIRECTORY
565+
&& $entry[self::KEY_TIMESTAMP] !== false
566+
&& strpos($entry[self::KEY_PATH], $path) === 0
563567
) {
564-
$timestamp = $this->getCreatedTimestamp($entry[self::KEY_PATH])['timestamp'];
568+
$timestamp = $this->getCreatedTimestamp($entry[self::KEY_PATH])[self::KEY_TIMESTAMP];
565569

566570
if ($timestamp > $directoryTimestamp) {
567571
$directoryTimestamp = $timestamp;

0 commit comments

Comments
 (0)