1
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;
31
32 import com.jcabi.aspects.Immutable;
33 import com.jcabi.aspects.Loggable;
34 import java.io.IOException;
35 import java.net.URL;
36 import java.text.ParseException;
37 import java.util.Date;
38 import javax.json.Json;
39 import javax.json.JsonObject;
40 import lombok.EqualsAndHashCode;
41 import lombok.ToString;
42
43
44
45
46
47
48
49
50
51
52
53 @Immutable
54 @SuppressWarnings("PMD.TooManyMethods")
55 public interface Pull extends Comparable<Pull>, JsonReadable, JsonPatchable {
56
57
58
59
60
61 Repo repo();
62
63
64
65
66
67 int number();
68
69
70
71
72
73
74 PullRef base() throws IOException;
75
76
77
78
79
80
81 PullRef head() throws IOException;
82
83
84
85
86
87
88
89 Iterable<Commit> commits() throws IOException;
90
91
92
93
94
95
96
97 Iterable<JsonObject> files() throws IOException;
98
99
100
101
102
103
104
105 void merge(String msg)
106 throws IOException;
107
108
109
110
111
112
113
114
115 MergeState merge(String msg,
116 String sha
117 ) throws IOException;
118
119
120
121
122
123
124
125 PullComments comments() throws IOException;
126
127
128
129
130
131
132
133
134 Checks checks() throws IOException;
135
136
137
138
139 @Immutable
140 @ToString
141 @Loggable(Loggable.DEBUG)
142 @EqualsAndHashCode(of = {"pull", "jsn"})
143 final class Smart implements Pull {
144
145
146
147 private final transient Pull pull;
148
149
150
151 private final transient SmartJson jsn;
152
153
154
155
156
157 public Smart(
158 final Pull pll
159 ) {
160 this.pull = pll;
161 this.jsn = new SmartJson(pll);
162 }
163
164
165
166
167
168
169 public boolean isOpen() throws IOException {
170 return Issue.OPEN_STATE.equals(this.state());
171 }
172
173
174
175
176
177
178 public String state() throws IOException {
179 return this.jsn.text("state");
180 }
181
182
183
184
185
186
187 public void state(
188 final String state
189 ) throws IOException {
190 this.pull.patch(
191 Json.createObjectBuilder().add("state", state).build()
192 );
193 }
194
195
196
197
198
199
200 public String title() throws IOException {
201 return this.jsn.text("title");
202 }
203
204
205
206
207
208
209 public void title(
210 final String text
211 ) throws IOException {
212 this.pull.patch(
213 Json.createObjectBuilder().add("title", text).build()
214 );
215 }
216
217
218
219
220
221
222 public String body() throws IOException {
223 return this.jsn.text("body");
224 }
225
226
227
228
229
230
231 public void body(
232 final String text
233 ) throws IOException {
234 this.pull.patch(
235 Json.createObjectBuilder().add("body", text).build()
236 );
237 }
238
239
240
241
242
243
244 public URL url() throws IOException {
245 return new URL(this.jsn.text("url"));
246 }
247
248
249
250
251
252
253 public URL htmlUrl() throws IOException {
254 return new URL(this.jsn.text("html_url"));
255 }
256
257
258
259
260
261
262 public Date createdAt() throws IOException {
263 try {
264 return new Github.Time(
265 this.jsn.text("created_at")
266 ).date();
267 } catch (final ParseException ex) {
268 throw new IllegalStateException(ex);
269 }
270 }
271
272
273
274
275
276
277 public Date updatedAt() throws IOException {
278 try {
279 return new Github.Time(
280 this.jsn.text("updated_at")
281 ).date();
282 } catch (final ParseException ex) {
283 throw new IllegalStateException(ex);
284 }
285 }
286
287
288
289
290
291
292 public Date closedAt() throws IOException {
293 try {
294 return new Github.Time(
295 this.jsn.text("closed_at")
296 ).date();
297 } catch (final ParseException ex) {
298 throw new IllegalStateException(ex);
299 }
300 }
301
302
303
304
305
306
307 public Date mergedAt() throws IOException {
308 try {
309 return new Github.Time(
310 this.jsn.text("merged_at")
311 ).date();
312 } catch (final ParseException ex) {
313 throw new IllegalStateException(ex);
314 }
315 }
316
317
318
319
320
321
322 public User author() throws IOException {
323 return this.pull.repo().github().users().get(
324 this.jsn.value(
325 "user", JsonObject.class
326 ).getString("login")
327 );
328 }
329
330
331
332
333
334 public Issue issue() {
335 return this.pull.repo().issues().get(this.pull.number());
336 }
337
338
339
340
341
342
343
344 public int commentsCount() throws IOException {
345 return this.jsn.number("comments");
346 }
347
348 @Override
349 public Repo repo() {
350 return this.pull.repo();
351 }
352
353 @Override
354 public int number() {
355 return this.pull.number();
356 }
357
358 @Override
359 public Iterable<Commit> commits() throws IOException {
360 return this.pull.commits();
361 }
362
363 @Override
364 public Iterable<JsonObject> files() throws IOException {
365 return this.pull.files();
366 }
367
368 @Override
369 public void merge(
370 final String msg
371 ) throws IOException {
372 this.pull.merge(msg);
373 }
374
375 @Override
376 public MergeState merge(
377 final String msg,
378 final String sha
379 )
380 throws IOException {
381 return this.pull.merge(msg, sha);
382 }
383
384 @Override
385 public PullComments comments() throws IOException {
386 return this.pull.comments();
387 }
388
389
390
391
392
393
394
395 @Override
396 public Checks checks() throws IOException {
397 return this.pull.checks();
398 }
399
400 @Override
401 public JsonObject json() throws IOException {
402 return this.pull.json();
403 }
404
405 @Override
406 public void patch(
407 final JsonObject json
408 ) throws IOException {
409 this.pull.patch(json);
410 }
411
412 @Override
413 public int compareTo(
414 final Pull obj
415 ) {
416 return this.pull.compareTo(obj);
417 }
418
419 @Override
420 public PullRef base() throws IOException {
421 return this.pull.base();
422 }
423
424 @Override
425 public PullRef head() throws IOException {
426 return this.pull.head();
427 }
428 }
429 }