-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetRepos.php
75 lines (57 loc) · 2.43 KB
/
getRepos.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
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
<?php
include('userAccountInfo.php'); //Include Vars Containg User Account Info
//$data_string = json_encode($data);
$url = 'https://api.github.com/users/'.$GitHubUserName.'/repos'; //API URL to get a users repos. This currently only returns public repos.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
//curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,1);
curl_setopt($ch, CURLOPT_USERPWD, $GitHubUserName.":".$GithubPassword);
curl_setopt( $ch, CURLOPT_USERAGENT, $GitHubUserName);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$content = curl_exec($ch);
curl_close($ch);
$result = json_decode($content,true); //Array Containing all public repos owned by the user.
$AllRepoInfo = array();
foreach($result as $SingleRepo){
$RepoInfo = array();
$RepoInfo['name'] = $SingleRepo['name'];
$RepoInfo['description'] = $SingleRepo['description'];
$RepoInfo['html_url'] = $SingleRepo['html_url'];
$RepoInfo['language'] = $SingleRepo['language'];
$RepoAPIURL = $SingleRepo['url'];
$ReadMeURL = $RepoAPIURL.'/readme';
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $ReadMeURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt( $ch, CURLOPT_USERAGENT, $GitHubUserName);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$data = curl_exec($ch);
curl_close($ch);
$DataArray = json_decode($data,true);
$ReadMeText = base64_decode($DataArray["content"]);
//print_r($ReadMeText);
//Extract The Data From Readme file between two tags. The user could have the data between multiple tags.
preg_match_all("/<GITHUBPARSER>(.*?)<\/GITHUBPARSER>/s", $ReadMeText, $output_array);
//If the user has multiple areas of options JSON decode each one.
$RepoOptions = array();
foreach($output_array[1] as $val){
//Decode the JSON into an assoctative array.
$Options = json_decode($val,true);
//Merge the array into one array containing all of the options.
$RepoOptions = array_merge($RepoOptions, $Options);
}
//Options Coming From the Github API
//Custom Options Coming From The Readme File
foreach($RepoOptions as $key => $JSONElemet){
$RepoInfo[$key] = $JSONElemet;
}
$AllRepoInfo[] = $RepoInfo;
unset($RepoInfo);
}
?>