forked from virtuozzo/cloudscripting-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
issue_report.php
88 lines (75 loc) · 2.99 KB
/
issue_report.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
<?php
include_once('/var/www/webroot/config.php');
$selectedText = $_POST['selected'];
$userName = $_POST['userName'];
$context = $_POST['context'];
$comment = $_POST['comment'];
$labels = "cs-bug-report";
$page = $_POST['page'];
function checkRequiredParams($params) {
foreach ($params as $key => $value) {
if (empty($value)) {
exit("Parameter " . $key . " is required");
}
}
}
function wr_log($log_msg) {
$log_filepath = "log/";
if (!file_exists($log_filepath))
{
// create directory/folder uploads.
mkdir($log_filepath, 0777, true);
}
$log_file_data = $log_filepath.'/GitHub_issue_log_' . date('d-M-Y') . '.log';
file_put_contents($log_file_data, $log_msg . "\nEND\n\n", FILE_APPEND);
}
function sendRequest($URL, $BODY, $TOKEN) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $BODY);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'User-Agent: PHP',
'Authorization: token '.$TOKEN
));
$resp = curl_exec($ch);
curl_close ($ch);
return $resp;
}
checkRequiredParams(array('page' => $page, 'comment' => $comment));
if (isset($selectedText)) {
$firstWords = strtok($selectedText, ' ').' '.strtok(' ').' '.strtok(' ');
if (strlen($selectedText) != strlen(trim($firstWords))) {
$firstWords = substr($firstWords, 0, 30)."...";
}
}
if (isset($comment)) {
$tmpComment = strtok($comment, ' ').' '.strtok(' ').' '.strtok(' ');
if (strlen($comment) != strlen(trim($tmpComment))) {
$firstWords .= ' - '.substr(strtok($comment, ' ').' '.strtok(' ').' '.strtok(' '), 0, 30)."...";
} else {
$firstWords .= ' - '.$comment;
}
}
$title = "[${page}:${userName}]: ${firstWords}";
$title = str_replace("\n","\\n", $title);
$title = str_replace("\"","\\\"", $title);
$selectedText = trim($selectedText);
$text = "## Target page:\\r\\n" . "[http://".$_SERVER['HTTP_HOST'].$page."](http://" . $_SERVER['HTTP_HOST'] .$page.")\\n".
"## Reporter:\\r\\n" .$userName."\\n".
"## Comment:\\r\\n" .$comment."\\r\\n".
"## Selected text:\\r\\n" . $context."\\r\\n";
$text = str_replace("\n","\\n",$text);
$text = str_replace("\"","\\\"",$text);
$data = '{"title": "'. $title .'", "body": "'. $text .'", "assignee": "'. $assignee .'", "labels": ["'. $labels .'"]}';
$server_output = sendRequest($url, $data, $token);
$data=json_decode($server_output ,true);
wr_log($server_output);
if (!empty($data['id'])) {
print_r("The issue on GitHub successfully created with id - " . $data['id']);
} else {
print_r("Some error is occuer:" .$server_output);
}
exit();
?>