-
Notifications
You must be signed in to change notification settings - Fork 0
/
github_list_repos.php
45 lines (39 loc) · 1.38 KB
/
github_list_repos.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
<?php
// GitHib Repo Lister - API demo code
// Author: Simon Prickett
// Hit the GitHub API and list the repos, will expect
// to be passed a GitHub token in GITHUB_TOKEN environment variable
function listGitHubRepos() {
global $gitHubToken;
$c = curl_init();
curl_setopt($c, CURLOPT_URL, "https://api.github.com/user/repos");
curl_setopt($c, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
"User-Agent: Modus PHP Script",
"Content-Type: application/json",
"Accept-Language: en-US",
"Authorization: token " . getenv("GITHUB_TOKEN"))
);
$output = curl_exec($c);
$gitHubReposJSON = json_decode($output, true);
curl_close($c);
$htmlStr = '<ul class="repolist">';
foreach($gitHubReposJSON as $gitHubRepo) {
$htmlStr = $htmlStr . '<li><a href="' . $gitHubRepo['url'] . '">' . $gitHubRepo['id'] . ' ' . $gitHubRepo['name'] . '</a></li>';
}
$htmlStr = $htmlStr . '</ul>';
print $htmlStr;
}
?>
<html>
<head>
<title>GitHub Repo Lister</title>
</head>
<body>
<h1>GitHub Repo Lister</h1>
<p>Here are your GitHub Repos:</p>
<?php listGitHubRepos(); ?>
</body>
</html>