|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace M1guelpf; |
|
4
|
|
|
|
|
5
|
|
|
use Github\Client as GitHub; |
|
6
|
|
|
use M1guelpf\Integration\CreatesJwtTokens; |
|
7
|
|
|
use M1guelpf\Integration\AuthenticatesApplications; |
|
8
|
|
|
use Illuminate\Support\Traits\Macroable; |
|
9
|
|
|
|
|
10
|
|
|
class Integration |
|
11
|
|
|
{ |
|
12
|
|
|
use CreatesJwtTokens, AuthenticatesApplications, Macroable; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var \Lcobucci\JWT\Token |
|
16
|
|
|
*/ |
|
17
|
|
|
protected static $jwt; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var GitHub |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $github; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Create a new Integration instance. |
|
26
|
|
|
* |
|
27
|
|
|
* @param GitHub|null $client |
|
28
|
|
|
* |
|
29
|
|
|
* @return void |
|
|
|
|
|
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(GitHub $client = null) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->github = $client ?? new GitHub(null, 'machine-man-preview'); |
|
34
|
|
|
static::$jwt = $this->createToken(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Use am specific Client. |
|
39
|
|
|
* |
|
40
|
|
|
* @return self |
|
41
|
|
|
*/ |
|
42
|
|
|
public function withClient(GitHub $client = null) : self |
|
43
|
|
|
{ |
|
44
|
|
|
$this->github = $client ?? new GitHub(null, 'machine-man-preview'); |
|
45
|
|
|
|
|
46
|
|
|
return $this; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Authenticate as an application. |
|
51
|
|
|
* |
|
52
|
|
|
* @return self |
|
53
|
|
|
*/ |
|
54
|
|
|
public function authenticate() : self |
|
55
|
|
|
{ |
|
56
|
|
|
$this->github = $this->authenticateAsApplication($this->github, static::$jwt); |
|
57
|
|
|
|
|
58
|
|
|
return $this; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Authenticate as an installation. |
|
63
|
|
|
* |
|
64
|
|
|
* @param int $installation_id |
|
65
|
|
|
* |
|
66
|
|
|
* @return self |
|
67
|
|
|
*/ |
|
68
|
|
|
public function asInstallation(int $installation_id) : self |
|
69
|
|
|
{ |
|
70
|
|
|
$this->github = $this->authenticateAsInstallation($installation_id, $this->github, static::$jwt); |
|
71
|
|
|
|
|
72
|
|
|
return $this; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Access the GitHub API. |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $name |
|
79
|
|
|
* |
|
80
|
|
|
* @throws \Github\Exception\InvalidArgumentException |
|
81
|
|
|
* |
|
82
|
|
|
* @return \Github\Api\ApiInterface |
|
83
|
|
|
*/ |
|
84
|
|
|
public function api(string $name) : \Github\Api\ApiInterface |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->github->api($name); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.