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 log parser. |
18
|
|
|
* |
19
|
|
|
* @author Andrii Vasyliev <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class GitLogParser extends AbstractParser |
22
|
|
|
{ |
23
|
|
|
public function mergeTo($history) |
24
|
|
|
{ |
25
|
|
|
$this->setHistory($history); |
26
|
|
|
$this->mergeGitLog(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function mergeGitLog() |
30
|
|
|
{ |
31
|
|
|
$log = $this->fetchGitLog(); |
|
|
|
|
32
|
|
|
var_dump($log); |
|
|
|
|
33
|
|
|
die(); |
|
|
|
|
34
|
|
|
foreach ($log as $hash => $data) { |
|
|
|
|
35
|
|
|
$this->getHistory()->addCommit($data['tag'], null, $data['commit'], true); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function parseGitLog() |
40
|
|
|
{ |
41
|
|
|
exec("git log --date=short --pretty='format:%h %ad %s [%ae] %d'", $logs); |
42
|
|
|
|
43
|
|
|
return $this->parseLines($logs); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
public function parseLines(array $lines) |
47
|
|
|
{ |
48
|
1 |
|
$this->getHistory()->initTags(); |
49
|
|
|
|
50
|
1 |
|
foreach ($lines as $line) { |
51
|
1 |
|
if (!preg_match('/^(\w+) (([0-9-]+) (.*?) \[.*?\]) *\(?(.*?)\)?$/', $line, $m)) { |
52
|
|
|
throw new UnexpectedValueException('failed parse git line'); |
53
|
|
|
} |
54
|
1 |
|
$tag = $this->matchTag($m[5]); |
55
|
1 |
|
$note = $this->matchNote($m[4]); |
56
|
1 |
|
if ($tag) { |
|
|
|
|
57
|
1 |
|
$this->addTag($tag, $m[3]); |
58
|
1 |
|
} |
59
|
1 |
|
if (false && $note) { /// disabled adding notes |
60
|
|
|
$this->addNote($note); |
61
|
|
|
} |
62
|
1 |
|
$this->addCommit($m[1], $m[2]); |
63
|
1 |
|
} |
64
|
|
|
|
65
|
1 |
|
return $this->getHistory(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Finds first tag in given refs string. |
70
|
|
|
* @param string $str |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
1 |
|
public function matchTag($str) |
74
|
|
|
{ |
75
|
1 |
|
$refs = explode(', ', $str); |
76
|
1 |
|
foreach ($refs as $ref) { |
77
|
1 |
|
if (preg_match('/^tag: (.*)$/', $ref, $m)) { |
78
|
1 |
|
return $m[1]; |
79
|
|
|
} |
80
|
1 |
|
} |
81
|
|
|
|
82
|
1 |
|
return null; |
83
|
|
|
} |
84
|
|
|
|
85
|
1 |
|
public function matchNote($str) |
86
|
|
|
{ |
87
|
1 |
|
return strpos($str, ' ') ? $str : null; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
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.