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