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 javax.json.JsonValue;
41 import lombok.EqualsAndHashCode;
42 import lombok.ToString;
43
44
45
46
47
48
49
50
51
52
53 @Immutable
54 @SuppressWarnings("PMD.TooManyMethods")
55 public interface Release extends JsonReadable, JsonPatchable {
56
57
58
59
60
61 Repo repo();
62
63
64
65
66
67 int number();
68
69
70
71
72
73 void delete() throws IOException;
74
75
76
77
78
79
80 ReleaseAssets assets();
81
82
83
84
85 @Immutable
86 @ToString
87 @Loggable(Loggable.DEBUG)
88 @EqualsAndHashCode(of = { "release", "jsn" })
89 final class Smart implements Release {
90
91
92
93
94 private final transient Release release;
95
96
97
98 private final transient SmartJson jsn;
99
100
101
102
103
104 public Smart(
105 final Release original
106 ) {
107 this.release = original;
108 this.jsn = new SmartJson(original);
109 }
110
111 @Override
112 public JsonObject json() throws IOException {
113 return this.release.json();
114 }
115
116 @Override
117 public void patch(
118 final JsonObject json
119 ) throws IOException {
120 this.release.patch(json);
121 }
122
123 @Override
124 public Repo repo() {
125 return this.release.repo();
126 }
127
128 @Override
129 public int number() {
130 return this.release.number();
131 }
132
133 @Override
134 public ReleaseAssets assets() {
135 return this.release.assets();
136 }
137
138
139
140
141
142
143 public URL url() throws IOException {
144 return new URL(this.jsn.text("url"));
145 }
146
147
148
149
150
151
152 public URL htmlUrl() throws IOException {
153 return new URL(this.jsn.text("html_url"));
154 }
155
156
157
158
159
160
161 public URL assetsUrl() throws IOException {
162 return new URL(this.jsn.text("assets_url"));
163 }
164
165
166
167
168
169
170 public URL uploadUrl() throws IOException {
171 return new URL(this.jsn.text("upload_url"));
172 }
173
174
175
176
177
178
179 public String tag() throws IOException {
180 return this.jsn.text("tag_name");
181 }
182
183
184
185
186
187
188
189 public boolean hasTag() throws IOException {
190 return this.jsn.hasNotNull("tag_name");
191 }
192
193
194
195
196
197
198 public void tag(
199 final String text
200 ) throws IOException {
201 this.release.patch(
202 Json.createObjectBuilder().add("tag_name", text).build()
203 );
204 }
205
206
207
208
209
210
211 public String commitish() throws IOException {
212 return this.jsn.text("target_commitish");
213 }
214
215
216
217
218
219
220 public void commitish(
221 final String text
222 ) throws IOException {
223 this.release.patch(
224 Json.createObjectBuilder()
225 .add("target_commitish", text)
226 .build()
227 );
228 }
229
230
231
232
233
234
235 public boolean hasName() throws IOException {
236 return this.jsn.hasNotNull("name");
237 }
238
239
240
241
242
243
244
245 public String name() throws IOException {
246 return this.jsn.text("name");
247 }
248
249
250
251
252
253
254 public void name(
255 final String text
256 ) throws IOException {
257 this.release.patch(
258 Json.createObjectBuilder().add("name", text).build()
259 );
260 }
261
262
263
264
265
266
267 public boolean hasBody() throws IOException {
268 return this.jsn.hasNotNull("body");
269 }
270
271
272
273
274
275
276 public String body() throws IOException {
277 final String body;
278 if (this.hasBody()) {
279 body = this.jsn.text("body");
280 } else {
281 body = "";
282 }
283 return body;
284 }
285
286
287
288
289
290
291 public void body(
292 final String text
293 ) throws IOException {
294 this.release.patch(
295 Json.createObjectBuilder().add("body", text).build()
296 );
297 }
298
299
300
301
302
303
304 public Date createdAt() throws IOException {
305 try {
306 return new Github.Time(this.jsn.text("created_at"))
307 .date();
308 } catch (final ParseException ex) {
309 throw new IOException(ex);
310 }
311 }
312
313
314
315
316
317
318 public Date publishedAt() throws IOException {
319 try {
320 return new Github.Time(this.jsn.text("published_at"))
321 .date();
322 } catch (final ParseException ex) {
323 throw new IOException(ex);
324 }
325 }
326
327
328
329
330
331
332 public boolean draft() throws IOException {
333 return this.json().getBoolean("draft", Boolean.FALSE);
334 }
335
336
337
338
339
340
341 public void draft(final boolean draft) throws IOException {
342 this.release.patch(
343 Json.createObjectBuilder().add("draft", draft).build()
344 );
345 }
346
347
348
349
350
351
352 public boolean prerelease() throws IOException {
353 return Boolean.parseBoolean(
354 this.json()
355 .getOrDefault("prerelease", JsonValue.FALSE)
356 .toString().replace("\"", "")
357 );
358 }
359
360
361
362
363
364
365 public void prerelease(final boolean pre) throws IOException {
366 this.release.patch(
367 Json.createObjectBuilder().add("prerelease", pre).build()
368 );
369 }
370
371 @Override
372 public void delete() throws IOException {
373 this.release.delete();
374 }
375
376 }
377
378 }