-
Notifications
You must be signed in to change notification settings - Fork 0
/
createissue.php
111 lines (96 loc) · 2.98 KB
/
createissue.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/* php createissue.php do <username> <password> <repo> <title> <content>
* e.g. php createissue.php do shaangola <password> https://github.com/shaangola/demorep "test bug" "test bug description"
* same for bitbucket php createissue.php do shaangola <password> https://bitbucket.org/shaangola/demorep "test bug" "test bug description"
* here shaangola is my username, password not specify here for security concern.
* GitHub/BitBucket Issue Creator
* Test for Xerox assigned by Ashish
* (c) Shaan Gola <[email protected]>
* For demo purpose only
*/
require_once 'gitvendor/autoload.php';
require_once 'bitvendor/autoload.php';
error_reporting(E_ALL);
function error_send_usage() {
exit("Usage: createissue.php do <username> <password> <repo> <title> <content>\r\n");
}
if(!function_exists("curl_init")) {
exit("No curl found!");
}
if(!function_exists("json_decode")) {
exit("No JSON found!");
}
if(!$argc > 0) {
error_send_usage();
}
function is_json($str)
{
return is_array(json_decode($str,true));
}
// work out where the arguments are sitting
if($argv[0] == "do") {
$i = 1;
} elseif($argv[1] == "do") {
$i = 2;
} elseif($argv[3] == "do") {
$i = 4;
} else {
error_send_usage();
}
// get the position of the arguments
$username = $argv[$i];
$password = $argv[$i+1];
$repo = $argv[$i+2];
$title = $argv[$i+3];
$content = $argv[$i+4];
if(strstr($repo, "github.com/")) {
$client = new \Github\Client();
try{
$data = array("title" => $title, "body" => $content );
$repo_data = str_replace("https://github.com/", "", $repo);
$repo_split = explode("/", $repo_data);
$http = new \Github\HttpClient\HttpClient();
$client = new \Github\Client($http);
$client->authenticate($username, $password, \Github\Client::AUTH_HTTP_PASSWORD);
$issue=$client->api('issue')->create($username,$repo_split[1], $data);;
echo("======================================".PHP_EOL);
echo("post successfully".PHP_EOL);
echo("======================================");
}
catch(Exception $e)
{
echo (PHP_EOL);
echo (PHP_EOL);
echo ('Message: '.$e->getMessage());
echo (PHP_EOL);
echo (PHP_EOL);
}
}
else{
// login
try{
$data = array("title" => $title, "content" => $content );
$repo_data = str_replace("https://bitbucket.org/", "", $repo);
$repo_split = explode("/", $repo_data);
$issue = new Bitbucket\API\Repositories\Issues;
$issue->setCredentials( new Bitbucket\API\Authentication\Basic($username, $password) );
$issueResult= $issue->create($username,$repo_split[1],$data);
if(is_json($issueResult->getContent()))
{
echo("======================================".PHP_EOL);
echo("post successfully".PHP_EOL);
echo("======================================");
}
else
{
echo("======================================".PHP_EOL);
echo("Resource not Found".PHP_EOL);
echo("======================================");
}
}
catch(Exception $e)
{
echo ('Message: '.$e->getMessage());
}
}
?>