Skip to content
This repository
Newer
Older
100755 217 lines (179 sloc) 4.613 kb
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
1 #!/usr/bin/php
2 <?php
3 /**
4 * @package Joomla.Build
5 *
6 * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 // We are a valid Joomla entry point.
11 define('_JEXEC', 1);
12
13 // Setup the path related constants.
14 define('JPATH_BASE', dirname(__FILE__));
15
16 // Bootstrap the application.
17 require '../libraries/import.php';
18
19 jimport('joomla.application.cli');
20
21 /**
22 * The command line application.
23 *
24 * @package NewLifeInIT
25 * @subpackage cron
26 */
27 class Changelog extends JCli
28 {
29 /**
30 * Execute the application.
31 *
32 * @return void
33 *
34 * @since 11.3
35 */
36 public function execute()
37 {
38 // Import dependancies.
39 jimport('joomla.client.http');
40
41 try
42 {
5e33a190 »
2011-08-15 Performance improvement.
43 // Get a list of the merged pull requests.
44 $merged = $this->getMergedPulls();
45
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
46 $doc = new XMLWriter;
47 $doc->openMemory();
48 $doc->setIndent(true);
49 $doc->setIndentString("\t");
50 $doc->startDocument('1.0', 'utf-8');
102546dc »
2011-08-23 Improved docbook validation.
51
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
52 $doc->startElement('appendix');
a7c8efd7 »
2011-08-18 Added xmlns to changelog.
53 $doc->writeAttribute('version', '5.0');
54 $doc->writeAttribute('xmlns', 'http://docbook.org/ns/docbook');
55 $doc->writeAttribute('xml:id', 'preface');
102546dc »
2011-08-23 Improved docbook validation.
56 $doc->writeAttribute('xmlns:ns', 'http://docbook.org/ns/docbook');
57 $doc->writeAttribute('xmlns:ns2', 'http://www.w3.org/1999/xlink');
58 $doc->writeAttribute('xmlns:ns3', 'http://www.w3.org/1998/Math/MathML');
59 $doc->writeAttribute('xmlns:ns4', 'http://www.w3.org/2000/svg');
60 $doc->writeAttribute('xmlns:ns5', 'http://www.w3.org/1999/xhtml');
61
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
62 $doc->startElement('section');
63
64 $cutoff = 10;
65 $page = 1;
66
67 while ($cutoff--)
68 {
5e33a190 »
2011-08-15 Performance improvement.
69 // Get a page of issues.
70 $issues = $this->getIssues($page++);
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
71
72 // Check if we've gone past the last page.
5e33a190 »
2011-08-15 Performance improvement.
73 if (empty($issues))
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
74 {
75 break;
76 }
77
6aa3854f »
2011-08-23 Updated changelog
78 $doc->startElement('itemizedlist');
79
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
80 // Loop through each pull.
5e33a190 »
2011-08-15 Performance improvement.
81 foreach ($issues as $issue)
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
82 {
5e33a190 »
2011-08-15 Performance improvement.
83 // Check if the issue has been merged.
84 if (empty($issue->pull_request->html_url))
85 {
86 continue;
87 }
88
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
89 // Check if the pull has been merged.
5e33a190 »
2011-08-15 Performance improvement.
90 if (!in_array($issue->number, $merged))
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
91 {
92 continue;
93 }
94
95 $doc->startElement('listitem');
96
97 $doc->startElement('para');
98
99 // Prepare the link to the pull.
100 $doc->text('[');
102546dc »
2011-08-23 Improved docbook validation.
101 $doc->startElement('link');
102 $doc->writeAttribute('ns2:href', $issue->url);
103 $doc->writeAttribute('ns2:title', 'Closed '.$issue->closed_at);
5e33a190 »
2011-08-15 Performance improvement.
104 $doc->text('#'.$issue->number);
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
105 $doc->endElement(); // ulink
5e33a190 »
2011-08-15 Performance improvement.
106 $doc->text('] '.$issue->title.' (');
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
107
108 // Prepare the link to the author.
6aa3854f »
2011-08-23 Updated changelog
109 $doc->startElement('link');
110 $doc->writeAttribute('ns2:href', $issue->user->url);
5e33a190 »
2011-08-15 Performance improvement.
111 $doc->text($issue->user->login);
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
112 $doc->endElement(); // ulink
113 $doc->text(')');
114
115 $doc->endElement(); // para
116
5e33a190 »
2011-08-15 Performance improvement.
117 if (trim($issue->body))
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
118 {
119 $doc->startElement('para');
5e33a190 »
2011-08-15 Performance improvement.
120 $doc->text($issue->body);
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
121 $doc->endElement(); // para
122 }
123
124 $doc->endElement(); // listitem
125 }
6aa3854f »
2011-08-23 Updated changelog
126
127 $doc->endElement(); // itemizedlist
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
128 }
129
130 $doc->endElement(); // section
131 $doc->endElement(); // appendix
132
133 // Write the file.
134 if (!is_dir('./docs'))
135 {
136 mkdir('./docs');
137 }
138
139 file_put_contents('./docs/changelog.xml', $doc->outputMemory());
140 }
141 catch (Exception $e)
142 {
143 $this->out($e->getMessage());
144 $this->close($e->getCode());
145 }
146
147 // Close normally.
148 $this->close();
149 }
150
151 /**
5e33a190 »
2011-08-15 Performance improvement.
152 * Get a page of issue data.
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
153 *
154 * @param integer The page number.
155 *
156 * @return array
157 *
158 * @since 11.3
159 */
5e33a190 »
2011-08-15 Performance improvement.
160 protected function getIssues($page)
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
161 {
162 $http = new JHttp;
163 $r = $http->get(
164 'https://api.github.com/repos/joomla/joomla-platform/issues?state=closed&sort=updated&direction=desc&page='.$page.'&per_page=100'
165 );
166
167 return json_decode($r->body);
168 }
5e33a190 »
2011-08-15 Performance improvement.
169
170 /**
171 * Gets a list of the merged pull numbers.
172 *
173 * @param integer The pull/issue number.
174 *
175 * @return array
176 *
177 * @since 11.3
178 */
179 protected function getMergedPulls()
180 {
181 $cutoff = 10;
182 $page = 1;
183 $merged = array();
184
185 while ($cutoff--)
186 {
187 $http = new JHttp;
188
189 $r = $http->get(
190 'https://api.github.com/repos/joomla/joomla-platform/pulls?state=closed&page='.$page++.'&per_page=100'
191 );
192
193 $pulls = json_decode($r->body);
194
195 // Check if we've gone past the last page.
196 if (empty($pulls))
197 {
198 break;
199 }
200
201 // Loop through each of the pull requests.
202 foreach ($pulls as $pull)
203 {
204 // If merged, add to the white list.
205 if ($pull->merged_at)
206 {
207 $merged[] = $pull->number;
208 }
209 }
210 }
211
212 return $merged;
213 }
1a471686 »
2011-08-15 Added command line application to automatically generate the changelo…
214 }
215
216 JCli::getInstance('Changelog')->execute();
Something went wrong with that request. Please try again.