Skip to content

Instantly share code, notes, and snippets.

@scrummitch
Last active June 15, 2017 04:39
Show Gist options
  • Save scrummitch/647e090b95ac3fa5250244ba301d41a3 to your computer and use it in GitHub Desktop.
Save scrummitch/647e090b95ac3fa5250244ba301d41a3 to your computer and use it in GitHub Desktop.
<?php
function page($page = 1) {
$request = (new \GuzzleHttp\Client())
->get('https://api.github.com/repos/user/repo/pulls', [
'auth' => ['username', 'password'],
'headers' => [
'User-Agent' => 'CSV export',
'Accept' => 'application/vnd.github.v3+json',
],
'query' => [
'since' => '2016-06-01T00:00:00Z',
'state' => 'all',
'per_page' => 100,
'page' => $page
],
]);
return json_decode($request->getBody()->getContents());
}
Route::get('csv', function() {
$pages = 2;
header('Content-Type: application/excel');
header('Content-Disposition: attachment; filename=github-isuses.csv');
$fp = fopen('php://output', 'w');
fputcsv($fp, [
'ID',
'Title',
'Created Date',
'Updated Date',
'Closed Date',
'Merged Date',
]);
for ($i = 1; $i <= ($pages+1); $i++) {
$new = page($i);
foreach($new AS $item) {
fputcsv($fp, [
$item->number,
$item->title,
$item->created_at,
$item->updated_at,
$item->closed_at,
$item->merged_at,
]);
}
}
fclose($fp);
});
@zer0pants
Copy link

Typo: filename=github-isuses.csv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment