-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.php
More file actions
52 lines (51 loc) · 1.35 KB
/
Copy pathgithub.php
File metadata and controls
52 lines (51 loc) · 1.35 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
45
46
47
48
49
50
51
52
<?php
$token = ''; // Github deactivates existing tokens
$url = 'https://api.github.com/graphql';
//GRAPHQL request
$query = <<<'JSON'
query{
repository(owner: "claaudius", name: "GithubApi") {
object(expression: "master") {
... on Commit {
history {
edges {
node {
author {
name
email
}
message
pushedDate
commitUrl
}
}
totalCount
}
}
}
}
}
JSON;
$json = json_encode(['query' => $query]);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, TRUE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"User-Agent: GitHub Api",
"Authorization: token $token"
));
$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
//check to see if we're ok
if ( $http_code == 200 ) {
$temp = explode(PHP_EOL,$response);
$count = count($temp);
$data = json_decode($temp[$count-1]);
$data = $data->data->repository->object->history->edges; //data for the front-end
} else {
die("Sorry, an error occurred.");
}