aboutsummaryrefslogtreecommitdiff
path: root/contrib/prepare_release/fetch_contributors.php
blob: 9659b800402c751df792510b21958109fe0c8494 (plain) (blame)
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
<?php
/* Generate the "Contributors" list for README.md automatically utilizing the GitHub API */

require __DIR__ . '/../../lib/rssbridge.php';

$url = 'https://api.github.com/repos/rss-bridge/rss-bridge/contributors';
$contributors = array();
$next = true;

while($next) { /* Collect all contributors */

	$headers = [
		'Accept: application/json',
		'Content-Type: application/json',
		'User-Agent: RSS-Bridge'
	];
	$result = _http_request($url, ['headers' => $headers]);

	foreach(json_decode($result['body']) as $contributor)
		$contributors[] = $contributor;

	// Extract links to "next", "last", etc...
	$links = explode(',', $result['headers']['link'][0]);
	$next = false;

	// Check if there is a link with 'rel="next"'
	foreach($links as $link) {
		list($url, $type) = explode(';', $link, 2);

		if(trim($type) === 'rel="next"') {
			$url = trim(preg_replace('/([<>])/', '', $url));
			$next = true;
			break;
		}
	}

}

/* Example JSON data: https://api.github.com/repos/rss-bridge/rss-bridge/contributors */

// We want contributors sorted by name
usort($contributors, function($a, $b){
	return strcasecmp($a->login, $b->login);
});

// Export as Markdown list
foreach($contributors as $contributor) {
	echo "  * [{$contributor->login}]({$contributor->html_url})\n";
}