forked from php-censor/php-censor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGithub.php
More file actions
84 lines (72 loc) · 2.18 KB
/
Copy pathGithub.php
File metadata and controls
84 lines (72 loc) · 2.18 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace PHPCensor\Helper;
use PHPCensor\Config;
use GuzzleHttp\Client;
/**
* The Github Helper class provides some Github API call functionality.
*/
class Github
{
/**
* Create a comment on a specific file (and commit) in a Github Pull Request.
* @param $repo
* @param $pullId
* @param $commitId
* @param $file
* @param $line
* @param $comment
* @return null
*/
public function createPullRequestComment($repo, $pullId, $commitId, $file, $line, $comment)
{
$token = Config::getInstance()->get('php-censor.github.token');
if (!$token) {
return null;
}
$url = '/repos/' . strtolower($repo) . '/pulls/' . $pullId . '/comments';
$params = [
'body' => $comment,
'commit_id' => $commitId,
'path' => $file,
'position' => $line,
];
$client = new Client();
$client->post(('https://api.github.com' . $url), [
'headers' => [
'Authorization' => 'Basic ' . base64_encode($token . ':x-oauth-basic'),
'Content-Type' => 'application/x-www-form-urlencoded'
],
'json' => $params,
]);
}
/**
* Create a comment on a Github commit.
* @param $repo
* @param $commitId
* @param $file
* @param $line
* @param $comment
* @return null
*/
public function createCommitComment($repo, $commitId, $file, $line, $comment)
{
$token = Config::getInstance()->get('php-censor.github.token');
if (!$token) {
return null;
}
$url = '/repos/' . strtolower($repo) . '/commits/' . $commitId . '/comments';
$params = [
'body' => $comment,
'path' => $file,
'position' => $line,
];
$client = new Client();
$client->post(('https://api.github.com' . $url), [
'headers' => [
'Authorization' => 'Basic ' . base64_encode($token . ':x-oauth-basic'),
'Content-Type' => 'application/x-www-form-urlencoded'
],
'json' => $params,
]);
}
}