forked from snipe/snipe-it
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gh-changelog.php
57 lines (47 loc) · 1.62 KB
/
gh-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
<?php
#!/usr/bin/php -q
/* PHP requires defined timezone; GitHub uses UTC */
ini_set( 'date.timezone', 'UTC' );
/*
* YOU MUST CHANGE THESE VARIABLES
*/
$gh_user = 'snipe';
$gh_repo = 'snipe-it';
$file = 'CHANGELOG.md';
$string = 'fix|resolve|closes|closed|#changelog';
$omit = '';
/*
* No need to change anything below here
*/
$url = 'https://api.github.com/repos/'.$gh_user.'/'.$gh_repo.'/releases';
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
curl_setopt($ch,CURLOPT_USERAGENT,$gh_user);
$data = curl_exec($ch);
curl_close($ch);
$releases = json_decode($data, TRUE);
while( $obj = array_shift( $releases ) )
{
/* Define the beginning of each release block in the changelog */
$changelog = "\n\n### ".$obj['name']." - Released ".date("M d, Y h:i:s",strtotime($obj['created_at']))."\n";
$changelog .= $obj['prerelease'] == 'true' ? '#### This is a pre-release '."\n": '';
file_put_contents($file,$changelog,FILE_APPEND);
/* Retrieve and format each commit entry */
$gitlog = 'git log '.escapeshellarg($obj['tag_name']);
/* Set commit limit based on next tag name */
if ( $next = current($releases) )
{
$gitlog .= '...'.escapeshellarg($next['tag_name']).' ';
}
else $gitlog .= ' ';
$gitlog .= '--pretty=format:\'* <a href="https://github.com/'.$gh_user.'/'.$gh_repo.'/commit/%H">view</a> •';
$gitlog .= ' %s \' --reverse | grep -i -E '.escapeshellarg($string).' ';
if ($omit!=''){
$gitlog .= ' | grep -i -E -v '.escapeshellarg($omit).'';
}
$gitlog .= '>> '.escapeshellarg($file);
exec($gitlog);
}