-
-
Notifications
You must be signed in to change notification settings - Fork 592
Expand file tree
/
Copy pathApps.php
More file actions
188 lines (172 loc) · 4.93 KB
/
Apps.php
File metadata and controls
188 lines (172 loc) · 4.93 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
namespace Github\Api;
use Github\Api\App\Hook;
/**
* @link https://developer.github.com/v3/apps/
*
* @author Nils Adermann <[email protected]>
*/
class Apps extends AbstractApi
{
/**
* Create an access token for an installation.
*
* @param int $installationId An integration installation id
* @param int $userId An optional user id on behalf of whom the
* token will be requested
*
* @link https://developer.github.com/v3/apps/#create-a-new-installation-token
*
* @return array token and token metadata
*/
public function createInstallationToken($installationId, $userId = null)
{
$parameters = [];
if ($userId) {
$parameters['user_id'] = $userId;
}
return $this->post('/app/installations/'.$installationId.'/access_tokens', $parameters);
}
/**
* Find all installations for the authenticated application.
*
* @link https://developer.github.com/v3/apps/#find-installations
*
* @return array
*/
public function findInstallations()
{
return $this->get('/app/installations');
}
/**
* Get an installation of the application.
*
* @link https://developer.github.com/v3/apps/#get-an-installation
*
* @param int $installationId An integration installation id
*
* @return array
*/
public function getInstallation($installationId)
{
return $this->get('/app/installations/'.$installationId);
}
/**
* Get an installation of the application for an organization.
*
* @link https://developer.github.com/v3/apps/#get-an-organization-installation
*
* @param string $org An organization
*
* @return array
*/
public function getInstallationForOrganization($org)
{
return $this->get('/orgs/'.rawurldecode($org).'/installation');
}
/**
* Get an installation of the application for a repository.
*
* @link https://developer.github.com/v3/apps/#get-a-repository-installation
*
* @param string $owner the owner of a repository
* @param string $repo the name of the repository
*
* @return array
*/
public function getInstallationForRepo($owner, $repo)
{
return $this->get('/repos/'.rawurldecode($owner).'/'.rawurldecode($repo).'/installation');
}
/**
* Get an installation of the application for a user.
*
* @link https://developer.github.com/v3/apps/#get-a-user-installation
*
* @param string $username
*
* @return array
*/
public function getInstallationForUser($username)
{
return $this->get('/users/'.rawurldecode($username).'/installation');
}
/**
* Delete an installation of the application.
*
* @link https://developer.github.com/v3/apps/#delete-an-installation
*
* @param int $installationId An integration installation id
*/
public function removeInstallation($installationId)
{
$this->delete('/app/installations/'.$installationId);
}
/**
* List repositories that are accessible to the authenticated installation.
*
* @link https://developer.github.com/v3/apps/installations/#list-repositories
*
* @param int $userId
*
* @return array
*/
public function listRepositories($userId = null)
{
$parameters = [];
if ($userId) {
$parameters['user_id'] = $userId;
}
return $this->get('/installation/repositories', $parameters);
}
/**
* Add a single repository to an installation.
*
* @link https://developer.github.com/v3/apps/installations/#add-repository-to-installation
*
* @param int $installationId
* @param int $repositoryId
*
* @return array
*/
public function addRepository($installationId, $repositoryId)
{
return $this->put('/installations/'.$installationId.'/repositories/'.$repositoryId);
}
/**
* Remove a single repository from an installation.
*
* @link https://developer.github.com/v3/apps/installations/#remove-repository-from-installation
*
* @param int $installationId
* @param int $repositoryId
*
* @return array
*/
public function removeRepository($installationId, $repositoryId)
{
return $this->delete('/installations/'.$installationId.'/repositories/'.$repositoryId);
}
/**
* Get the currently authenticated app.
*
* @link https://docs.github.com/en/rest/reference/apps#get-the-authenticated-app
*
* @return array
*/
public function getAuthenticatedApp()
{
return $this->get('/app');
}
/**
* Manage the hook of an app.
*
* @link https://docs.github.com/en/rest/apps/webhooks
*
* @return Hook
*/
public function hook()
{
return new Hook($this->getClient());
}
}