]> BookStack Code Mirror - devops/blob - meta-scripts/bookstack-changelog
Added ny release changelog script, Updated translator script
[devops] / meta-scripts / bookstack-changelog
1 #!/usr/bin/php
2 <?php
3
4 function error($text) {
5         echo $text . "\n";
6         exit(1);
7 }
8
9 function output($text) {
10     echo $text . "\n";
11 }
12
13 function getJSON($url) {
14         $ch = curl_init();
15         curl_setopt_array($ch, [
16                 CURLOPT_URL => $url,
17                 CURLOPT_RETURNTRANSFER => 1,
18                 CURLOPT_HTTPHEADER => [
19                         'User-Agent: ssddanbrown',
20                 ]
21         ]);
22         $data = curl_exec($ch);
23
24         $err = curl_error($ch);
25         curl_close($ch);
26         if (!empty($err)) error($err);
27
28         return json_decode($data, true);
29 }
30
31 // Check a milestone is provided
32 if (count($argv) < 2) {
33         error("Milestone ID required");
34 }
35
36 // Get milestone info from GitHub
37 $milestoneID = intval($argv[1]);
38 $issueURL = 'https://api.github.com/repos/BookStackApp/BookStack/issues?milestone='. $milestoneID .'&state=all';
39 $issues = getJSON($issueURL);
40
41 // Get BookStack version and check if a feature or minor release
42 $milestone = $issues[0]['milestone'];
43 $versionMatch = [];
44 preg_match('/v[0-9.]{5,7}/', $milestone['title'], $versionMatch);
45 $version = $versionMatch[0];
46 $splitVersion = explode('.', $version);
47 $isFeature = intval(array_pop($splitVersion)) === 0;
48
49 // Output title
50 output("# BookStack Beta {$version}\n");
51
52 // Output header text and links
53 if ($isFeature) {
54     $urlVersion = implode('0', $splitVersion);
55     output("- [Update instructions](https://www.bookstackapp.com/docs/admin/updates)");
56     output("- [Update details on blog](https://www.bookstackapp.com/blog/beta-release-{$urlVersion}/)");
57     output("\n### Full List of Changes\n");
58 } else {
59     output("\nThis release contains the following fixes and changes:\n");
60 }
61
62 // Output issues
63 foreach ($issues as $issue) {
64         $output = '* ';
65         $output .= trim($issue['title'], '.') . '.';
66         if (isset($issue['pull_request']) && $issue['user']['login'] !== 'ssddanbrown') {
67         $output .= " Thanks to [@{$issue['user']['login']}]({$issue['html_url']}).";
68     }
69         $output .= " ([#{$issue['number']}]({$issue['html_url']}))";
70     output($output);
71 }