-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_github_projects.php
More file actions
44 lines (36 loc) · 1.26 KB
/
get_github_projects.php
File metadata and controls
44 lines (36 loc) · 1.26 KB
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
<?php
$token = 'TOKKEN_GITHUB';
$projectLinks = [
'https://api.github.com/repos/username/project1',
'https://api.github.com/repos/username/project2',
'https://api.github.com/repos/username/project3'
];
$headers = [
'Authorization: token ' . $token,
'User-Agent: MyPortfolioApp'
];
$projects = [];
foreach ($projectLinks as $link) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$data = json_decode($response, true);
if (isset($data['name'])) {
$languagesUrl = $link . '/languages';
curl_setopt($ch, CURLOPT_URL, $languagesUrl);
$languagesResponse = curl_exec($ch);
$languagesData = json_decode($languagesResponse, true);
$languages = array_keys($languagesData);
$projects[] = [
'name' => $data['name'],
'description' => $data['description'] ?? 'Pas de description disponible.',
'url' => $data['html_url'],
'languages' => implode(', ', $languages)
];
}
curl_close($ch);
}
header('Content-Type: application/json');
echo json_encode($projects);