-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathpull_requests.php
More file actions
237 lines (202 loc) · 7.1 KB
/
pull_requests.php
File metadata and controls
237 lines (202 loc) · 7.1 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?php
require_once(__DIR__.'/../common/code/bootstrap.php');
class PullRequestPage {
static $param_defaults = Array(
'page_view' => 'lib',
);
static $page_view_options = Array(
'lib' => 'By Library',
'date' => 'By Age',
);
var $params; // Normalised URL parameters
var $pull_requests;
var $last_updated;
var $page_url_path; // URL path for this page
var $page_view; // Grouped by library, or sorted by age.
function __construct($params) {
$json_data = json_decode(
file_get_contents(BOOST_DATA_DIR.'/pull-requests.json'));
$this->pull_requests = $json_data->pull_requests;
$this->last_updated = $json_data->last_updated;
$this->page_url_path = preg_replace('![#?].*!', '', $_SERVER['REQUEST_URI']);
$this->params = array();
foreach (self::$param_defaults as $key => $default) {
// Note: Using default for empty values as well as missing values.
$this->params[$key] = strtolower(trim(
BoostWebsite::array_get($params, $key))) ?: $default;
}
$this->page_view = $this->params['page_view'];
if (!array_key_exists($this->page_view, self::$page_view_options)) {
BoostWeb::throw_http_error(400, 'Invalid view type',
"Invalid view type: {$this->page_view}");
}
}
function display() {
echo '<div id="options">';
echo '<div id="view-options">';
echo '<ul class="menu">';
foreach (self::$page_view_options as $key => $description) {
echo '<li>';
$this->option_link($description, 'page_view', $key);
echo '</li> ';
}
echo '</ul>';
echo '</div>';
echo '</div>';
echo '<p>Last updated ',
$this->time_ago($this->last_updated),
"</p>\n";
switch ($this->page_view) {
case 'lib':
$this->by_library();
break;
case 'date':
$this->by_date();
break;
default:
echo "Invalid page_view.";
}
}
function by_library() {
foreach ($this->pull_requests as $name => $repo_requests) {
$repo_count = count($repo_requests);
echo "<h2>", html_encode($name), "</h2>\n",
"<p> {$repo_count} open request",
($repo_count != 1 ? 's' : ''),
":</p>\n";
foreach ($repo_requests as $pull) {
$this->pull_request_item($pull);
}
}
}
function by_date() {
$pull_requests = Array();
foreach ($this->pull_requests as $name => $repo_requests) {
foreach ($repo_requests as $pull) {
$pull->name = $name;
$pull_requests[] = $pull;
}
}
usort($pull_requests, function($x, $y) {
return strtotime($x->created_at) - strtotime($y->created_at);
});
echo '<ul>';
foreach ($pull_requests as $pull) {
$this->pull_request_item($pull, $pull->name);
}
echo "</ul>\n";
}
function pull_request_item($pull, $name = null) {
echo "<li>",
"<a href='" . html_encode($pull->html_url) . "'>",
($name ? html_encode(preg_replace('@^boostorg/@', '', $name)).": " : ''),
html_encode(rtrim($pull->title, '.')),
"</a>",
" (created: ",
html_encode(gmdate("j M Y", strtotime($pull->created_at))),
", updated: ",
html_encode(gmdate("j M Y", strtotime($pull->updated_at))),
")",
"</li>\n";
}
function option_link($description, $field, $value) {
$value = strtolower($value);
$current_value = $this->params[$field];
if ($current_value == $value) {
echo '<span>', html_encode($description), '</span>';
} else {
$params = $this->params;
$params[$field] = $value;
$url_params = '';
foreach ($params as $k => $v) {
if ($v && $v !== self::$param_defaults[$k]) {
$url_params .= $url_params ? '&' : '?';
$url_params .= urlencode($k) . '=' . urlencode($v);
}
}
echo '<a href="' . html_encode($this->page_url_path . $url_params) . '">',
html_encode($description), '</a>';
}
}
function time_ago($date, $now = null) {
$date = new DateTime($date);
$now = new DateTime($now ?: 'now');
if ($date >= $now) {
return ($date - $now <= 2) ? "just now" :
"<i>in the future??? (probably an error somewhere)</i>";
}
$diff = date_diff($date, $now);
$val = false;
foreach(
Array(
'y' => 'year',
'm' => 'month',
'd' => 'day',
'h' => 'hour',
'i' => 'minute',
's' => 'second',
) as $member => $unit)
{
if ($val = $diff->{$member}) {
return "{$val} {$unit}".($val != 1 ? 's' : '')." ago";
}
}
}
}
$page = new PullRequestPage($_GET);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Open Pull Requests - Boost C++ Libraries</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" href="/favicon.ico" type="image/ico" />
<link rel="stylesheet" type="text/css" href=
"/style-v2/section-development.css" />
<!--[if IE 7]> <style type="text/css"> body { behavior: url(/style-v2/csshover3.htc); } </style> <![endif]-->
<script defer data-domain="original.boost.org" src="https://plausible.io/js/script.js"></script></head><!--
Note: Editing website content is documented at:
https://www.boost.org/development/website_updating.html
-->
<body>
<div id="heading">
<?php virtual("/common/heading.html") ?>
</div>
<div id="body">
<div id="body-inner">
<div id="content">
<div class="section" id="intro">
<div class="section-0">
<div class="section-title">
<h1>Open Pull Requests</h1>
</div>
<div class="section-body">
<?php $page->display(); ?>
</div>
</div>
</div>
</div>
<div id="sidebar">
<?php virtual("/common/sidebar-common.html") ?>
<?php virtual("/common/sidebar-development.html") ?>
</div>
<div class="clear"></div>
</div>
</div>
<div id="footer">
<div id="footer-left">
<div id="revised">
<p>Revised $Date$</p>
</div>
<div id="copyright">
<p>Copyright Daniel James 2014.</p>
</div><?php virtual("/common/footer-license.html") ?>
</div>
<div id="footer-right">
<?php virtual("/common/footer-banners.html") ?>
</div>
<div class="clear"></div>
</div>
</body>
</html>