mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-01-17 06:08:27 +01:00
[contrib] Place script for fetching contributors from GitHub's gist to contrib directory
No need to depend on gist.github.com
This commit is contained in:
parent
3cef35a432
commit
e9d3d7ba67
@ -108,7 +108,7 @@ We are RSS-Bridge community, a group of developers continuing the project initia
|
||||
**Contributors** (sorted alphabetically):
|
||||
<!--
|
||||
Use this script to generate the list automatically (using the GitHub API):
|
||||
https://gist.github.com/LogMANOriginal/da00cd1e5f0ca31cef8e193509b17fd8
|
||||
./contrib/prepare_release/fetch_contributors.php
|
||||
-->
|
||||
|
||||
* [16mhz](https://github.com/16mhz)
|
||||
|
94
contrib/prepare_release/fetch_contributors.php
Normal file
94
contrib/prepare_release/fetch_contributors.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/* Generate the "Contributors" list for README.md automatically utilizing the GitHub API */
|
||||
|
||||
$url = 'https://api.github.com/repos/rss-bridge/rss-bridge/contributors';
|
||||
$contributors = array();
|
||||
$next = true;
|
||||
|
||||
while($next) { /* Collect all contributors */
|
||||
|
||||
$c = curl_init();
|
||||
|
||||
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($c, CURLOPT_HTTPHEADER, array(
|
||||
'Accept: application/json',
|
||||
'Content-Type: application/json',
|
||||
'User-Agent: RSS-Bridge'
|
||||
));
|
||||
curl_setopt($c, CURLOPT_URL, $url);
|
||||
curl_setopt($c, CURLOPT_HEADER, true);
|
||||
|
||||
$data = curl_exec($c);
|
||||
|
||||
$headerSize = curl_getinfo($c, CURLINFO_HEADER_SIZE);
|
||||
$header = substr($data, 0, $headerSize);
|
||||
$headers = parseResponseHeader($header);
|
||||
|
||||
curl_close($c);
|
||||
|
||||
foreach(json_decode(substr($data, $headerSize)) as $contributor)
|
||||
$contributors[] = $contributor;
|
||||
|
||||
// Extract links to "next", "last", etc...
|
||||
$links = explode(',', $headers[0]['link']);
|
||||
$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";
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the provided response header into an associative array
|
||||
*
|
||||
* Based on https://stackoverflow.com/a/18682872
|
||||
*/
|
||||
function parseResponseHeader($header) {
|
||||
|
||||
$headers = array();
|
||||
$requests = explode("\r\n\r\n", trim($header));
|
||||
|
||||
foreach ($requests as $request) {
|
||||
|
||||
$header = array();
|
||||
|
||||
foreach (explode("\r\n", $request) as $i => $line) {
|
||||
|
||||
if($i === 0) {
|
||||
$header['http_code'] = $line;
|
||||
} else {
|
||||
|
||||
list ($key, $value) = explode(': ', $line);
|
||||
$header[$key] = $value;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$headers[] = $header;
|
||||
|
||||
}
|
||||
|
||||
return $headers;
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user