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