<?php
function parseLog($log) {
$lines = explode("\n", $log);
$history = array();
foreach($lines as $key => $line) {
if(strpos($line, 'commit') === 0 || $key + 1 == count($lines)){
if(!empty($commit)){
$commit['message'] = substr($commit['message'], 4);
array_push($history, $commit);
unset($commit);
}
$commit['hash'] = substr($line, strlen('commit') + 1);
} else if(strpos($line, 'Author') === 0){
$commit['author'] = substr($line, strlen('Author:') + 1);
} else if(strpos($line, 'Date') === 0){
$commit['date'] = substr($line, strlen('Date:') + 3);
} elseif (strpos($line, 'Merge') === 0) {
$commit['merge'] = substr($line, strlen('Merge:') + 1);
$commit['merge'] = explode(' ', $commit['merge']);
} else {
if(isset($commit['message'])) {
$commit['message'] .= $line;
} else {
$commit['message'] = $line;
}
}
}
return $history;
}
$gLog = <<< 'EOD'
commit 56ed4ea370bd334580adb00d7c15f32e67b8164f (HEAD -> dev, origin/dev)
Author: Alexander Jank <alex@zeraton.de>
Date: Fri Feb 19 09:23:51 2021 +0100
chore(tools): configure eslint
commit 6fa00559d5e9f1d71efe1382bfc21200fdb79fb1
Author: Alexander Jank <alex@zeraton.de>
Date: Fri Feb 19 09:18:43 2021 +0100
feat(gql): add codegen
commit d07218637cc7315d9b27e6a726a0eb43f336278b
Author: Alexander Jank <alex@zeraton.de>
Date: Wed Feb 17 12:11:43 2021 +0100
chore(git): remove files
commit c12bb8e763cacc6ea2ef543462dc61d032c30ad4
Author: Alexander Jank <alex@zeraton.de>
Date: Wed Feb 17 12:10:33 2021 +0100
feat(backend): add schemas
commit 19a17d077c703ba5a1091272c1af1cb9a8e25865
Author: Alexander Jank <alex@zeraton.de>
Date: Wed Feb 17 10:24:14 2021 +0100
feat(backend): add
EOD;
var_dump(parseLog($gLog));
- Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- array(5) {
[0]=>
array(4) {
["hash"]=>
string(66) "56ed4ea370bd334580adb00d7c15f32e67b8164f (HEAD -> dev, origin/dev)"
["author"]=>
string(32) "Alexander Jank <alex@zeraton.de>"
["date"]=>
string(30) "Fri Feb 19 09:23:51 2021 +0100"
["message"]=>
string(30) "chore(tools): configure eslint"
}
[1]=>
array(4) {
["hash"]=>
string(40) "6fa00559d5e9f1d71efe1382bfc21200fdb79fb1"
["author"]=>
string(32) "Alexander Jank <alex@zeraton.de>"
["date"]=>
string(30) "Fri Feb 19 09:18:43 2021 +0100"
["message"]=>
string(22) "feat(gql): add codegen"
}
[2]=>
array(4) {
["hash"]=>
string(40) "d07218637cc7315d9b27e6a726a0eb43f336278b"
["author"]=>
string(32) "Alexander Jank <alex@zeraton.de>"
["date"]=>
string(30) "Wed Feb 17 12:11:43 2021 +0100"
["message"]=>
string(24) "chore(git): remove files"
}
[3]=>
array(4) {
["hash"]=>
string(40) "c12bb8e763cacc6ea2ef543462dc61d032c30ad4"
["author"]=>
string(32) "Alexander Jank <alex@zeraton.de>"
["date"]=>
string(30) "Wed Feb 17 12:10:33 2021 +0100"
["message"]=>
string(26) "feat(backend): add schemas"
}
[4]=>
array(4) {
["hash"]=>
string(40) "19a17d077c703ba5a1091272c1af1cb9a8e25865"
["author"]=>
string(32) "Alexander Jank <alex@zeraton.de>"
["date"]=>
string(30) "Wed Feb 17 10:24:14 2021 +0100"
["message"]=>
string(18) "feat(backend): add"
}
}
preferences:
151.53 ms | 411 KiB | 5 Q