|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Changelog keeper |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://github.com/hiqdev/chkipper |
|
7
|
|
|
* @package chkipper |
|
8
|
|
|
* @license BSD-3-Clause |
|
9
|
|
|
* @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace hiqdev\chkipper\history; |
|
13
|
|
|
|
|
14
|
|
|
use UnexpectedValueException; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Git merger. |
|
18
|
|
|
* Merges git log into History. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Andrii Vasyliev <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class GitMerger extends Builder |
|
23
|
|
|
{ |
|
24
|
|
|
public function mergeTo($history) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->setHistory($history); |
|
|
|
|
|
|
27
|
|
|
$this->mergeGitLog(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function mergeGitLog() |
|
31
|
|
|
{ |
|
32
|
|
|
$log = $this->fetchGitLog(); |
|
33
|
|
|
foreach ($log as $hash => $data) { |
|
34
|
|
|
$this->getHistory()->prependCommit($data['tag'], null, $data['commit']); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function fetchGitLog($reverse = false) |
|
39
|
|
|
{ |
|
40
|
|
|
$reverse = $reverse ? '--reverse' : ''; |
|
41
|
|
|
exec("git log $reverse --date=short --pretty='format:%h %ad %s [%ae] %d'", $logs); |
|
42
|
|
|
$res = []; |
|
43
|
|
|
foreach ($logs as $log) { |
|
|
|
|
|
|
44
|
|
|
if (!preg_match('/^(\w+) ([0-9-]+ .*? \[.*?\]) \(?(.*?)\)?$/', $log, $m)) { |
|
45
|
|
|
throw new UnexpectedValueException('failed parse git log'); |
|
46
|
|
|
} |
|
47
|
|
|
var_dump($m); |
|
|
|
|
|
|
48
|
|
|
$res[$m[1]] = [ |
|
49
|
|
|
'tag' => isset($m[3]) ? $this->matchTag($m[3]) : null, |
|
50
|
|
|
'commit' => new Commit($m[1], $m2[2]), |
|
|
|
|
|
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return $res; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Finds first tag in given refs string. |
|
59
|
|
|
* @param string $str |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
|
public function matchTag($str) |
|
63
|
|
|
{ |
|
64
|
|
|
$refs = explode(', ', $str); |
|
65
|
|
|
foreach ($refs as $ref) { |
|
66
|
|
|
if (preg_match('/^tag: (.*)$/', $ref, $m)) { |
|
67
|
|
|
return $m[1]; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return null; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.