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\BranchesCommand; |
8
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\CommitsCommand; |
9
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\CommunityHealthCommand; |
10
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\Contents\FileUploadCommand; |
11
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\ContentsCommand; |
12
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\LabelsCommand; |
13
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\LanguagesCommand; |
14
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\ReleasesCommand; |
15
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\SubscribeCommand; |
16
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\TagsCommand; |
17
|
|
|
use ApiClients\Client\Github\CommandBus\Command\Repository\UnSubscribeCommand; |
18
|
|
|
use ApiClients\Client\Github\Resource\Repository as BaseRepository; |
19
|
|
|
use React\Promise\PromiseInterface; |
20
|
|
|
use React\Stream\ReadableStreamInterface; |
21
|
|
|
use Rx\Observable; |
22
|
|
|
use Rx\ObservableInterface; |
23
|
|
|
use function ApiClients\Tools\Rx\unwrapObservableFromPromise; |
24
|
|
|
|
25
|
|
|
class Repository extends BaseRepository |
26
|
|
|
{ |
27
|
|
|
public function refresh(): PromiseInterface |
28
|
|
|
{ |
29
|
|
|
return $this->handleCommand( |
30
|
|
|
new RefreshCommand($this) |
31
|
|
|
); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function branches(): ObservableInterface |
35
|
|
|
{ |
36
|
|
|
return unwrapObservableFromPromise($this->handleCommand( |
37
|
|
|
new BranchesCommand($this->fullName()) |
38
|
|
|
)); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function commits(): ObservableInterface |
42
|
|
|
{ |
43
|
|
|
return unwrapObservableFromPromise($this->handleCommand( |
44
|
|
|
new CommitsCommand($this->fullName()) |
45
|
|
|
)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function labels(): ObservableInterface |
49
|
|
|
{ |
50
|
|
|
return unwrapObservableFromPromise($this->handleCommand( |
51
|
|
|
new LabelsCommand($this->fullName()) |
52
|
|
|
)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function addLabel(string $name, string $colour): PromiseInterface |
56
|
|
|
{ |
57
|
|
|
return $this->handleCommand( |
58
|
|
|
new AddLabelCommand($this->fullName(), $name, $colour) |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function contents(string $path = '/'): Observable |
63
|
|
|
{ |
64
|
|
|
return unwrapObservableFromPromise( |
65
|
|
|
$this->handleCommand( |
66
|
|
|
new ContentsCommand($this->fullName(), $path) |
67
|
|
|
) |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function communityHealth(): PromiseInterface |
72
|
|
|
{ |
73
|
|
|
return $this->handleCommand( |
74
|
|
|
new CommunityHealthCommand($this->fullName()) |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function tags(): ObservableInterface |
79
|
|
|
{ |
80
|
|
|
return unwrapObservableFromPromise($this->handleCommand( |
81
|
|
|
new TagsCommand($this->fullName()) |
82
|
|
|
)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function releases(): ObservableInterface |
86
|
|
|
{ |
87
|
|
|
return unwrapObservableFromPromise($this->handleCommand( |
88
|
|
|
new ReleasesCommand($this->fullName()) |
89
|
|
|
)); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function languages(): PromiseInterface |
93
|
|
|
{ |
94
|
|
|
return $this->handleCommand( |
95
|
|
|
new LanguagesCommand($this->fullName()) |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function addFile( |
100
|
|
|
string $filename, |
101
|
|
|
ReadableStreamInterface $stream, |
102
|
|
|
string $commitMessage = '', |
103
|
|
|
string $branch = '' |
104
|
|
|
): PromiseInterface { |
105
|
|
|
if ($commitMessage === '') { |
106
|
|
|
$commitMessage = 'Update ' . $this->name; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $this->handleCommand(new FileUploadCommand( |
110
|
|
|
$this->full_name, |
111
|
|
|
$commitMessage, |
112
|
|
|
'/repos/' . $this->full_name . '/contents/' . $filename, |
113
|
|
|
'', |
114
|
|
|
$branch, |
115
|
|
|
$stream |
116
|
|
|
)); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function subscribe(bool $subscribed = true, bool $ignored = false): PromiseInterface |
120
|
|
|
{ |
121
|
|
|
return $this->handleCommand( |
122
|
|
|
new SubscribeCommand($this->fullName(), $subscribed, $ignored) |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function unSubscribe(): PromiseInterface |
127
|
|
|
{ |
128
|
|
|
return $this->handleCommand( |
129
|
|
|
new UnSubscribeCommand($this->fullName()) |
130
|
|
|
); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|