forked from verdigado/sunflower
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-changelog.php
58 lines (42 loc) · 1.17 KB
/
create-changelog.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
$output = '<!DOCTYPE html>
<html lang="de-DE">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Changelog Sunflower Theme</title>
</head>
<body>
<h1>Changelogs</h1>
';
exec( 'git tag', $tags );
$tags = array_reverse( $tags );
$output .= read_commits_between_tags( 'HEAD', $tags[0] );
for ( $i = 0; $i < count( $tags ); $i++ ) {
$output .= read_commits_between_tags( $tags[ $i ], $tags[ $i + 1 ] );
if ( $tags[ $i ] == 'v1.0.0' ) {
break;
}
}
$output .= '</body>
</html>
';
file_put_contents( 'changelog.html', $output );
echo '..done';
function read_commits_between_tags( $from, $to ) {
global $argv;
exec( sprintf( 'git log --pretty=format:"%%s" %s...%s', $from, $to ), $commits );
if ( $from === 'HEAD' ) {
$from = ( isset( $argv[1] ) ) ? $argv[1] : 'der neuesten Version';
}
return sprintf( "<h2>Neu in %s</h2>\n<ul>\n%s</ul>\n\n", $from, add_commit_messages( $commits ) );
}
function add_commit_messages( $commits ) {
$return = '';
foreach ( $commits as $commit ) {
if ( preg_match( '/^publishing|^Bump|^Merge /', $commit ) ) {
continue;
}
$return .= sprintf( "<li>%s</li>\n", $commit );
}
return $return;
}