-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReportSuccess.php
executable file
·106 lines (87 loc) · 3.72 KB
/
ReportSuccess.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
<?php
$build_php_version = $argv[1];
$linter_bot_token = getenv('LINTER_TOKEN');
$repo_slug = getenv('TRAVIS_REPO_SLUG');
$pull_request = getenv('TRAVIS_PULL_REQUEST');
$linter_github_id = getenv('LINTER_USER_ID');
print "\nGetting Comments...\n\n";
$auth = [
"Authorization: token $linter_bot_token",
"User-Agent: jhut89/Mailchimp-API-3.0-PHP (https://github.com/Jhut89/Mailchimp-API-3.0-PHP)"
];
$ch = curl_init("https://api.github.com/repos/" . $repo_slug . "/issues/" . $pull_request . "/comments");
curl_setopt($ch, CURLOPT_HTTPHEADER, $auth);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$serialized_comments = curl_exec($ch);
$comments = json_decode($serialized_comments);
if ($comments === false) {
print "\nCould Not Deserialize Comments\n";
}
$linter_comment_urls = [];
// if the response was not an empty array get linters comments from the array
if (!empty($comments)) {
foreach ($comments as $comment) {
if (!isset($comment->user->id)) {
continue;
}
if ($comment->user->id == $linter_github_id) {
$linter_comment_urls[] = $comment->url;
}
}
} else {
print "\nNo Comments Were Found\n";
}
if (!empty($linter_comment_urls)) {
print "\nDeleting Linter Comments...\n";
foreach ($linter_comment_urls as $comment_url) {
$handle = curl_init($comment_url);
print "$comment_url";
curl_setopt($handle, CURLOPT_HTTPHEADER, $auth);
curl_setopt($handle, CURLOPT_HEADER, true);
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handle);
$http_code = intval(curl_getinfo($handle, CURLINFO_HTTP_CODE));
if ($http_code == 204) {
print "\nDeleted Linter Comment\n";
} else {
print "\nUnable To Delete Comment\n";
}
}
} else {
print "\nCould Not Find Any Linter Comments\n";
}
$apology = "The **Lint Wizard** redacts anything he may have said before! :sparkles::sparkles::sparkles:";
$apology .= "\n\n`Lint Wizard Approved` :heavy_check_mark: ";
$serialized_apology = json_encode(["body" => $apology]);
$apology_handle = curl_init("https://api.github.com/repos/" . $repo_slug . "/issues/" . $pull_request . "/comments");
curl_setopt($apology_handle, CURLOPT_HTTPHEADER, $auth);
curl_setopt($apology_handle, CURLOPT_HEADER, true);
curl_setopt($apology_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($apology_handle, CURLOPT_POST, true);
curl_setopt($apology_handle, CURLOPT_POSTFIELDS, $serialized_apology);
$response = curl_exec($apology_handle);
$http_code = intval(curl_getinfo($apology_handle, CURLINFO_HTTP_CODE));
if ($http_code > 199 && $http_code < 300) {
print "\nLint Wizard Apologized...\n";
} else {
print "Github responded with a non 200 range status code when attempting to apologize.\n\n";
print var_dump($response);
print "\nUnable to Apologize\n";
}
$serialized_label = json_encode(["Linter Approved"]);
$label_handle = curl_init("https://api.github.com/repos/" . $repo_slug . "/issues/" . $pull_request . "/labels");
curl_setopt($label_handle, CURLOPT_HTTPHEADER, $auth);
curl_setopt($label_handle, CURLOPT_HEADER, true);
curl_setopt($label_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($label_handle, CURLOPT_POST, true);
curl_setopt($label_handle, CURLOPT_POSTFIELDS, $serialized_label);
$response = curl_exec($label_handle);
$http_code = intval(curl_getinfo($label_handle, CURLINFO_HTTP_CODE));
if ($http_code > 199 && $http_code < 300) {
print "\nApplied Linter Label...\n";
} else {
print "Github responded with a non 200 range status code when attempting to label.\n\n";
print var_dump($response);
print "\nUnable to Apply Linter Label\n";
}