-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.php
More file actions
66 lines (52 loc) · 1.89 KB
/
Copy pathcreate.php
File metadata and controls
66 lines (52 loc) · 1.89 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
function callAPI($method,$url, $data)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data),
'User-Agent: tryout')
);
$result = curl_exec($curl);
if(!$result){
die("Connection Failure");
}
$result=json_decode($result,true);
return $result;
curl_close($curl);
}
function create_files($access_token,$user_name,$repo_name,$path_name,$email_id)
{
$url = "https://api.github.com/repos/".$user_name."/".$repo_name."/contents/".$path_name."?access_token=".$access_token;
echo $url."\n";
$data_array =array(
'message' => "New Reposiory",
'committer' => array(
"name" =>$user_name,
"email"=>$email_id,
),
"content" => '' );
$update_plan = callAPI("PUT", $url, json_encode($data_array));
//$response = json_decode($update_plan, true);
}
function create_repo($access_token,$repo_name,$description,$private)
{
$url = "https://api.github.com/user/repos?access_token=".$access_token;
$data_array = array(
"name"=> $repo_name,
"description"=> $description,
"private"=> $private);
$response = callAPI("POST", $url, json_encode($data_array));
//$response = json_decode($update_plan, false);
//echo $response;
$html_url = $response['html_url'];
return $html_url;
}
if(isset($_GET['create']))
{
create_files();
}
?>