1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace ApiClients\Client\Github\Resource\Async; |
4
|
|
|
|
5
|
|
|
use ApiClients\Client\Github\CommandBus\Command\RefreshCommand; |
6
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\AddLabelCommand; |
7
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\AddWebHookCommand; |
8
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\AppVeyorCommand; |
9
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\BlobCommand; |
10
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\BranchesCommand; |
11
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\CommitCommand; |
12
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\CommitsCommand; |
13
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\CommunityHealthCommand; |
14
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\CompareCommitsCommand; |
15
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\Contents\FileUploadCommand; |
16
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\ContentsCommand; |
17
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\DetailedCommitCommand; |
18
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\LabelsCommand; |
19
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\LanguagesCommand; |
20
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\MilestonesCommand; |
21
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\PullRequestsCommand; |
22
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\RefCommand; |
23
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\RefsCommand; |
24
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\ReleasesCommand; |
25
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\ReplaceTopicsCommand; |
26
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\ScrutinizerCommand; |
27
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\SubscribeCommand; |
28
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\TagsCommand; |
29
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\TravisCommand; |
30
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\TreeCommand; |
31
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\UnSubscribeCommand; |
32
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\UpdateSettingsCommand; |
33
|
|
|
use ApiClients\Client\Github\CommandBus\Command\WebHooksCommand; |
34
|
|
|
use ApiClients\Client\Github\Resource\Git\CommitInterface; |
35
|
|
|
use ApiClients\Client\Github\Resource\Git\RefInterface; |
36
|
|
|
use ApiClients\Client\Github\Resource\Git\TreeInterface; |
37
|
|
|
use ApiClients\Client\Github\Resource\Repository as BaseRepository; |
38
|
|
|
use ApiClients\Client\Github\VO\NamedBlob; |
39
|
|
|
use function ApiClients\Tools\Rx\unwrapObservableFromPromise; |
40
|
|
|
use React\Promise\PromiseInterface; |
41
|
|
|
use React\Stream\ReadableStreamInterface; |
42
|
|
|
use Rx\Observable; |
43
|
|
|
use Rx\ObservableInterface; |
44
|
|
|
|
45
|
|
|
class Repository extends BaseRepository |
46
|
|
|
{ |
47
|
|
|
public function refresh(): PromiseInterface |
48
|
|
|
{ |
49
|
|
|
return $this->handleCommand( |
50
|
|
|
new RefreshCommand($this) |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function branches(): ObservableInterface |
55
|
|
|
{ |
56
|
|
|
return unwrapObservableFromPromise($this->handleCommand( |
57
|
|
|
new BranchesCommand($this->fullName()) |
58
|
|
|
)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function commits(): ObservableInterface |
62
|
|
|
{ |
63
|
|
|
return unwrapObservableFromPromise($this->handleCommand( |
64
|
|
|
new CommitsCommand($this->fullName()) |
65
|
|
|
)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function specificCommit(string $sha): PromiseInterface |
69
|
|
|
{ |
70
|
|
|
return $this->handleCommand( |
71
|
|
|
new DetailedCommitCommand( |
72
|
|
|
$this->fullName(), |
73
|
|
|
$sha |
74
|
|
|
) |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function labels(): ObservableInterface |
79
|
|
|
{ |
80
|
|
|
return unwrapObservableFromPromise($this->handleCommand( |
81
|
|
|
new LabelsCommand($this->fullName()) |
82
|
|
|
)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function addLabel(string $name, string $colour): PromiseInterface |
86
|
|
|
{ |
87
|
|
|
return $this->handleCommand( |
88
|
|
|
new AddLabelCommand($this->fullName(), $name, $colour) |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function contents(string $path = '/'): Observable |
93
|
|
|
{ |
94
|
|
|
return unwrapObservableFromPromise( |
95
|
|
|
$this->handleCommand( |
96
|
|
|
new ContentsCommand($this->fullName(), $path) |
97
|
|
|
) |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function communityHealth(): PromiseInterface |
102
|
|
|
{ |
103
|
|
|
return $this->handleCommand( |
104
|
|
|
new CommunityHealthCommand($this->fullName()) |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function tags(): ObservableInterface |
109
|
|
|
{ |
110
|
|
|
return unwrapObservableFromPromise($this->handleCommand( |
111
|
|
|
new TagsCommand($this->fullName()) |
112
|
|
|
)); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function releases(): ObservableInterface |
116
|
|
|
{ |
117
|
|
|
return unwrapObservableFromPromise($this->handleCommand( |
118
|
|
|
new ReleasesCommand($this->fullName()) |
119
|
|
|
)); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function languages(): PromiseInterface |
123
|
|
|
{ |
124
|
|
|
return $this->handleCommand( |
125
|
|
|
new LanguagesCommand($this->fullName()) |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function webHooks(): ObservableInterface |
130
|
|
|
{ |
131
|
|
|
return unwrapObservableFromPromise($this->handleCommand( |
132
|
|
|
new WebHooksCommand($this->fullName(), 'repos') |
133
|
|
|
)); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function milestones(): ObservableInterface |
137
|
|
|
{ |
138
|
|
|
return unwrapObservableFromPromise($this->handleCommand( |
139
|
|
|
new MilestonesCommand($this->fullName()) |
140
|
|
|
)); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function pullRequests(): ObservableInterface |
144
|
|
|
{ |
145
|
|
|
return unwrapObservableFromPromise($this->handleCommand( |
146
|
|
|
new PullRequestsCommand($this->fullName()) |
147
|
|
|
)); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function compareCommits(string $base, string $head): PromiseInterface |
151
|
|
|
{ |
152
|
|
|
return $this->handleCommand(new CompareCommitsCommand($this, $base, $head)); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function addWebHook( |
156
|
|
|
string $name, |
157
|
|
|
array $config, |
158
|
|
|
array $events, |
159
|
|
|
bool $active |
160
|
|
|
): PromiseInterface { |
161
|
|
|
return $this->handleCommand( |
162
|
|
|
new AddWebHookCommand( |
163
|
|
|
$this->fullName(), |
164
|
|
|
$name, |
165
|
|
|
$config, |
166
|
|
|
$events, |
167
|
|
|
$active |
168
|
|
|
) |
169
|
|
|
); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function addFile( |
173
|
|
|
string $filename, |
174
|
|
|
ReadableStreamInterface $stream, |
175
|
|
|
string $commitMessage = '', |
176
|
|
|
string $branch = '' |
177
|
|
|
): PromiseInterface { |
178
|
|
|
if ($commitMessage === '') { |
179
|
|
|
$commitMessage = 'Update ' . $this->name; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
return $this->handleCommand(new FileUploadCommand( |
183
|
|
|
$this->full_name, |
184
|
|
|
$commitMessage, |
185
|
|
|
'/repos/' . $this->full_name . '/contents/' . $filename, |
186
|
|
|
'', |
187
|
|
|
$branch, |
188
|
|
|
$stream |
189
|
|
|
)); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
public function subscribe(bool $subscribed = true, bool $ignored = false): PromiseInterface |
193
|
|
|
{ |
194
|
|
|
return $this->handleCommand( |
195
|
|
|
new SubscribeCommand($this->fullName(), $subscribed, $ignored) |
196
|
|
|
); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
public function unSubscribe(): PromiseInterface |
200
|
|
|
{ |
201
|
|
|
return $this->handleCommand( |
202
|
|
|
new UnSubscribeCommand($this->fullName()) |
203
|
|
|
); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function replaceTopics(string ...$topics): PromiseInterface |
207
|
|
|
{ |
208
|
|
|
return $this->handleCommand( |
209
|
|
|
new ReplaceTopicsCommand($this->fullName(), ...$topics) |
210
|
|
|
); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function travisRepository(): PromiseInterface |
214
|
|
|
{ |
215
|
|
|
return $this->handleCommand(new TravisCommand($this->fullName())); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
public function appVeyorRepository(): PromiseInterface |
219
|
|
|
{ |
220
|
|
|
return $this->handleCommand(new AppVeyorCommand($this->fullName())); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
public function scrutinizerRepository(): PromiseInterface |
224
|
|
|
{ |
225
|
|
|
return $this->handleCommand(new ScrutinizerCommand(...\explode('/', $this->fullName()))); |
|
|
|
|
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
public function updateSettings(array $settings): PromiseInterface |
229
|
|
|
{ |
230
|
|
|
if (!isset($settings['name'])) { |
231
|
|
|
$settings['name'] = $this->name(); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
return $this->handleCommand(new UpdateSettingsCommand($this->fullName(), $settings)); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
public function blob(ReadableStreamInterface $contents): PromiseInterface |
238
|
|
|
{ |
239
|
|
|
return $this->handleCommand(new BlobCommand($this->fullName(), $contents)); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
public function tree(?string $baseTree, NamedBlob ...$blobs): PromiseInterface |
243
|
|
|
{ |
244
|
|
|
return $this->handleCommand(new TreeCommand($this->fullName(), $baseTree, ...$blobs)); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
public function commit(string $message, TreeInterface $tree, ?string ...$baseCommits): PromiseInterface |
248
|
|
|
{ |
249
|
|
|
return $this->handleCommand(new CommitCommand($this->fullName(), $message, $tree->sha(), ...$baseCommits)); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
public function refs(?string $namespace = null): ObservableInterface |
253
|
|
|
{ |
254
|
|
|
return unwrapObservableFromPromise($this->handleCommand( |
255
|
|
|
new RefsCommand($this->fullName(), $namespace) |
256
|
|
|
)); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
public function ref(RefInterface $ref, CommitInterface $tree): PromiseInterface |
260
|
|
|
{ |
261
|
|
|
return $this->handleCommand(new RefCommand($this->fullName(), $ref->ref(), $tree->sha())); |
262
|
|
|
} |
263
|
|
|
} |
264
|
|
|
|
This check looks for function calls that miss required arguments.