1 | 88 | |
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 | |
package com.jcabi.github.mock; |
31 | |
|
32 | |
import com.jcabi.aspects.Immutable; |
33 | |
import com.jcabi.aspects.Loggable; |
34 | |
import com.jcabi.github.Assignees; |
35 | |
import com.jcabi.github.Branches; |
36 | |
import com.jcabi.github.Collaborators; |
37 | |
import com.jcabi.github.Contents; |
38 | |
import com.jcabi.github.Coordinates; |
39 | |
import com.jcabi.github.DeployKeys; |
40 | |
import com.jcabi.github.Forks; |
41 | |
import com.jcabi.github.Git; |
42 | |
import com.jcabi.github.Github; |
43 | |
import com.jcabi.github.Hooks; |
44 | |
import com.jcabi.github.IssueEvents; |
45 | |
import com.jcabi.github.Issues; |
46 | |
import com.jcabi.github.Labels; |
47 | |
import com.jcabi.github.Language; |
48 | |
import com.jcabi.github.Milestones; |
49 | |
import com.jcabi.github.Notifications; |
50 | |
import com.jcabi.github.Pulls; |
51 | |
import com.jcabi.github.Releases; |
52 | |
import com.jcabi.github.Repo; |
53 | |
import com.jcabi.github.RepoCommits; |
54 | |
import com.jcabi.github.RtLanguage; |
55 | |
import com.jcabi.github.Stars; |
56 | |
import java.io.IOException; |
57 | |
import java.util.ArrayList; |
58 | |
import java.util.List; |
59 | |
import javax.json.JsonObject; |
60 | |
import lombok.EqualsAndHashCode; |
61 | |
import lombok.ToString; |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | 0 | @Immutable |
73 | |
@Loggable(Loggable.DEBUG) |
74 | 0 | @ToString |
75 | 10 | @EqualsAndHashCode(of = {"storage", "self", "coords" }) |
76 | |
@SuppressWarnings |
77 | |
( |
78 | |
{ |
79 | |
"PMD.TooManyMethods", |
80 | |
"PMD.ExcessiveImports", |
81 | |
"PMD.CouplingBetweenObjects" |
82 | |
} |
83 | |
) |
84 | |
final class MkRepo implements Repo { |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
private final transient MkStorage storage; |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
private final transient String self; |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
private final transient Coordinates coords; |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
MkRepo( |
108 | |
final MkStorage stg, |
109 | |
final String login, |
110 | |
final Coordinates repo |
111 | 521 | ) { |
112 | 521 | this.storage = stg; |
113 | 521 | this.self = login; |
114 | 521 | this.coords = repo; |
115 | 521 | } |
116 | |
|
117 | |
@Override |
118 | |
public Github github() { |
119 | 51 | return new MkGithub(this.storage, this.self); |
120 | |
} |
121 | |
|
122 | |
@Override |
123 | |
public Coordinates coordinates() { |
124 | 690 | return this.coords; |
125 | |
} |
126 | |
|
127 | |
@Override |
128 | |
public Issues issues() { |
129 | |
try { |
130 | 336 | return new MkIssues(this.storage, this.self, this.coords); |
131 | 0 | } catch (final IOException ex) { |
132 | 0 | throw new IllegalStateException(ex); |
133 | |
} |
134 | |
} |
135 | |
|
136 | |
@Override |
137 | |
public Milestones milestones() { |
138 | |
try { |
139 | 12 | return new MkMilestones(this.storage, this.self, this.coords); |
140 | 0 | } catch (final IOException ex) { |
141 | 0 | throw new IllegalStateException(ex); |
142 | |
} |
143 | |
} |
144 | |
|
145 | |
@Override |
146 | |
public Pulls pulls() { |
147 | |
try { |
148 | 36 | return new MkPulls(this.storage, this.self, this.coords); |
149 | 0 | } catch (final IOException ex) { |
150 | 0 | throw new IllegalStateException(ex); |
151 | |
} |
152 | |
} |
153 | |
|
154 | |
@Override |
155 | |
public Hooks hooks() { |
156 | |
try { |
157 | 9 | return new MkHooks(this.storage, this.self, this.coords); |
158 | 0 | } catch (final IOException ex) { |
159 | 0 | throw new IllegalStateException(ex); |
160 | |
} |
161 | |
} |
162 | |
|
163 | |
@Override |
164 | |
public IssueEvents issueEvents() { |
165 | |
try { |
166 | 14 | return new MkIssueEvents(this.storage, this.self, this.coords); |
167 | 0 | } catch (final IOException ex) { |
168 | 0 | throw new IllegalStateException(ex); |
169 | |
} |
170 | |
} |
171 | |
|
172 | |
@Override |
173 | |
public Labels labels() { |
174 | |
try { |
175 | 30 | return new MkLabels(this.storage, this.self, this.coords); |
176 | 0 | } catch (final IOException ex) { |
177 | 0 | throw new IllegalStateException(ex); |
178 | |
} |
179 | |
} |
180 | |
|
181 | |
@Override |
182 | |
public Assignees assignees() { |
183 | |
try { |
184 | 6 | return new MkAssignees(this.storage, this.self, this.coords); |
185 | 0 | } catch (final IOException ex) { |
186 | 0 | throw new IllegalStateException(ex); |
187 | |
} |
188 | |
} |
189 | |
|
190 | |
@Override |
191 | |
public Releases releases() { |
192 | |
try { |
193 | 66 | return new MkReleases(this.storage, this.self, this.coords); |
194 | 0 | } catch (final IOException ex) { |
195 | 0 | throw new IllegalStateException(ex); |
196 | |
} |
197 | |
} |
198 | |
|
199 | |
@Override |
200 | |
public Forks forks() { |
201 | |
try { |
202 | 6 | return new MkForks(this.storage, this.self, this.coords); |
203 | 0 | } catch (final IOException ex) { |
204 | 0 | throw new IllegalStateException(ex); |
205 | |
} |
206 | |
} |
207 | |
|
208 | |
@Override |
209 | |
public Collaborators collaborators() { |
210 | |
try { |
211 | 6 | return new MkCollaborators(this.storage, this.self, this.coords); |
212 | 0 | } catch (final IOException ex) { |
213 | 0 | throw new IllegalStateException(ex); |
214 | |
} |
215 | |
} |
216 | |
|
217 | |
@Override |
218 | |
public DeployKeys keys() { |
219 | |
try { |
220 | 10 | return new MkDeployKeys(this.storage, this.self, this.coords); |
221 | 0 | } catch (final IOException ex) { |
222 | 0 | throw new IllegalStateException(ex); |
223 | |
} |
224 | |
} |
225 | |
|
226 | |
@Override |
227 | |
public Contents contents() { |
228 | |
try { |
229 | 44 | return new MkContents(this.storage, this.self, this.coords); |
230 | 0 | } catch (final IOException ex) { |
231 | 0 | throw new IllegalStateException(ex); |
232 | |
} |
233 | |
} |
234 | |
|
235 | |
@Override |
236 | |
public void patch( |
237 | |
final JsonObject json |
238 | |
) throws IOException { |
239 | 484 | new JsonPatch(this.storage).patch(this.xpath(), json); |
240 | 242 | } |
241 | |
|
242 | |
@Override |
243 | |
public RepoCommits commits() { |
244 | |
try { |
245 | 6 | return new MkRepoCommits( |
246 | 2 | this.storage, this.self, this.coordinates() |
247 | |
); |
248 | 0 | } catch (final IOException ex) { |
249 | 0 | throw new IllegalStateException(ex); |
250 | |
} |
251 | |
} |
252 | |
|
253 | |
@Override |
254 | |
public Branches branches() { |
255 | |
try { |
256 | 45 | return new MkBranches( |
257 | 15 | this.storage, this.self, this.coordinates() |
258 | |
); |
259 | 0 | } catch (final IOException ex) { |
260 | 0 | throw new IllegalStateException(ex); |
261 | |
} |
262 | |
} |
263 | |
|
264 | |
@Override |
265 | |
public Git git() { |
266 | |
try { |
267 | 88 | return new MkGit(this.storage, this.self, this.coords); |
268 | 0 | } catch (final IOException ex) { |
269 | 0 | throw new IllegalStateException(ex); |
270 | |
} |
271 | |
} |
272 | |
|
273 | |
@Override |
274 | |
public Stars stars() { |
275 | |
try { |
276 | 6 | return new MkStars(this.storage, this.self, this.coords); |
277 | 0 | } catch (final IOException ex) { |
278 | 0 | throw new IllegalStateException(ex); |
279 | |
} |
280 | |
} |
281 | |
|
282 | |
@Override |
283 | |
public Notifications notifications() { |
284 | 3 | return new MkNotifications( |
285 | |
this.storage, |
286 | 1 | this.xpath().concat("/notifications/notification") |
287 | |
); |
288 | |
} |
289 | |
|
290 | |
@Override |
291 | |
public Iterable<Language> languages() { |
292 | 2 | final List<Language> languages = new ArrayList<Language>(0); |
293 | 1 | final int java = 999; |
294 | 1 | languages.add(new RtLanguage("Java", java)); |
295 | 1 | final int php = 888; |
296 | 1 | languages.add(new RtLanguage("PHP", php)); |
297 | 1 | final int ruby = 777; |
298 | 1 | languages.add(new RtLanguage("Ruby", ruby)); |
299 | 1 | return languages; |
300 | |
} |
301 | |
|
302 | |
@Override |
303 | |
public JsonObject json() throws IOException { |
304 | 15 | return new JsonNode( |
305 | 5 | this.storage.xml().nodes(this.xpath()).get(0) |
306 | 5 | ).json(); |
307 | |
} |
308 | |
|
309 | |
@Override |
310 | |
public int compareTo(final Repo repo) { |
311 | 0 | return this.coords.compareTo(repo.coordinates()); |
312 | |
} |
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
private String xpath() { |
319 | 248 | return String.format( |
320 | |
"/github/repos/repo[@coords='%s']", |
321 | |
this.coords |
322 | |
); |
323 | |
} |
324 | |
|
325 | |
} |