-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcloneall.php
49 lines (39 loc) · 1.63 KB
/
cloneall.php
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
set_time_limit( 0 );
use Milo\Github\Api;
use Milo\Github\Paginator;
require __DIR__ . '/vendor/autoload.php';
$token = ( isset( $argv[1] ) ) ? trim( $argv[1], '/' ) : false;
$storage_dir = ( isset( $argv[2] ) ) ? trim( $argv[2], '/' ) : __DIR__;
if ( empty( $token ) ) {
echo PHP_EOL . '⛔ Github Token Not Provided' . PHP_EOL;
exit;
}
$gh_api = new Api();
$gh_api->setToken( new \Milo\Github\OAuth\Token( $token ) );
if ( file_exists( __DIR__ . '/repos.json' ) ) {
echo '✔️ Repo Local Cache Found' . PHP_EOL;
$data = json_decode( file_get_contents( __DIR__ . '/repos.json' ) );
}
if ( empty( $data ) ) {
echo 'Repo Local Cache Empty' . PHP_EOL;
$request = $gh_api->createRequest( 'GET', '/user/repos/' );
$final_data = array();
$paginator = new Paginator( $gh_api, $request );
echo '🔽 Fetching From github.com' . PHP_EOL;
foreach ( $paginator->limit( 100 ) as $page => $response ) {
$final_data = array_merge( $final_data, $gh_api->decode( $response ) );
}
file_put_contents( __DIR__ . '/repos.json', json_encode( $final_data ) );
$data = $final_data;
}
echo PHP_EOL . '✔️ Total Repo Found : ' . count( $data ) . PHP_EOL . PHP_EOL;
array_map( function ( $repo ) {
global $storage_dir;
if ( ! file_exists( $storage_dir . '/' . $repo->full_name ) ) {
echo '=====================================================================' . PHP_EOL;
exec( 'git clone ' . $repo->clone_url . ' ' . $storage_dir . '/' . $repo->full_name );
echo '=====================================================================' . PHP_EOL . PHP_EOL;
}
return $repo;
}, $data );