Passed
Branch dev (c500dd)
by 世昌
03:56
created

create_name()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 12
rs 10
1
<?php
2
3
$content = shell_exec('git log --pretty=format:%s '.$argv[1].'..'.$argv[2]);
4
5
6
function match_array(string $content, array $in_array)
7
{
8
    foreach ($in_array as $key) {
9
        if (strpos($content, $key) !== false) {
10
            return true;
11
        }
12
    }
13
    return false;
14
}
15
16
function create_name(string $name, string $text)
17
{
18
    if (strpos($name, '修') !== false) {
19
        return '修正';
20
    }
21
    if (match_array($text, ['优化']) !== false) {
22
        return '优化';
23
    }
24
    if (match_array($text, ['删除']) !== false) {
25
        return '删除';
26
    }
27
    return $name;
28
}
29
30
31
$lines = explode("\n", $content);
32
33
foreach ($lines as $line) {
34
    $msg = trim($line);
35
    if (strpos($msg, ':')) {
36
        list($name, $text) = explode(':', $msg, 2);
37
        $name = create_name($name, $text);
38
        if (match_array($text, ['README', 'docs', '文档', '注释']) === false) {
39
            $info[$name][] = $text;
40
        }
41
    }
42
}
43
44
$textOutput = '';
45
46
foreach ($info as $name => $logs) {
47
    if (count($logs)) {
48
        $textOutput .= '- '. $name. PHP_EOL;
49
        $logs = array_unique($logs);
50
        foreach ($logs as $log) {
51
            $textOutput .= '    - '. $log. PHP_EOL;
52
        }
53
    }
54
}
55
56
57
file_put_contents($argv[3] ?? 'changelog', $textOutput);
58