Skip to content

Commit 8d14d76

Browse files
Add checks to Pull interface
1 parent 76d0248 commit 8d14d76

File tree

6 files changed

+211
-18
lines changed

6 files changed

+211
-18
lines changed

src/main/java/com/jcabi/github/Pull.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ void merge(String msg)
113113
* @throws IOException IOException If there is any I/O problem
114114
*/
115115
MergeState merge(String msg,
116-
String sha) throws IOException;
116+
String sha
117+
) throws IOException;
117118

118119
/**
119120
* Get Pull Comments.
@@ -123,13 +124,21 @@ MergeState merge(String msg,
123124
*/
124125
PullComments comments() throws IOException;
125126

127+
/**
128+
* Get Pull Checks.
129+
* @return Checks.
130+
* @throws IOException If there is any I/O problem.
131+
* @see <a href="https://developer.github.com/v3/checks/runs/">Checks API</a>
132+
*/
133+
Checks checks() throws IOException;
134+
126135
/**
127136
* Smart pull request with extra features.
128137
*/
129138
@Immutable
130139
@ToString
131140
@Loggable(Loggable.DEBUG)
132-
@EqualsAndHashCode(of = { "pull", "jsn" })
141+
@EqualsAndHashCode(of = {"pull", "jsn"})
133142
final class Smart implements Pull {
134143
/**
135144
* Encapsulated pull request.
@@ -139,6 +148,7 @@ final class Smart implements Pull {
139148
* SmartJson object for convenient JSON parsing.
140149
*/
141150
private final transient SmartJson jsn;
151+
142152
/**
143153
* Public ctor.
144154
* @param pll Pull request
@@ -149,6 +159,7 @@ public Smart(
149159
this.pull = pll;
150160
this.jsn = new SmartJson(pll);
151161
}
162+
152163
/**
153164
* Is it open?
154165
* @return TRUE if it's open
@@ -157,6 +168,7 @@ public Smart(
157168
public boolean isOpen() throws IOException {
158169
return Issue.OPEN_STATE.equals(this.state());
159170
}
171+
160172
/**
161173
* Get its state.
162174
* @return State of pull request
@@ -165,6 +177,7 @@ public boolean isOpen() throws IOException {
165177
public String state() throws IOException {
166178
return this.jsn.text("state");
167179
}
180+
168181
/**
169182
* Change its state.
170183
* @param state State of pull request
@@ -177,6 +190,7 @@ public void state(
177190
Json.createObjectBuilder().add("state", state).build()
178191
);
179192
}
193+
180194
/**
181195
* Get its title.
182196
* @return Title of pull request
@@ -185,6 +199,7 @@ public void state(
185199
public String title() throws IOException {
186200
return this.jsn.text("title");
187201
}
202+
188203
/**
189204
* Change its title.
190205
* @param text Title of pull request
@@ -197,6 +212,7 @@ public void title(
197212
Json.createObjectBuilder().add("title", text).build()
198213
);
199214
}
215+
200216
/**
201217
* Get its body.
202218
* @return Body of pull request
@@ -205,6 +221,7 @@ public void title(
205221
public String body() throws IOException {
206222
return this.jsn.text("body");
207223
}
224+
208225
/**
209226
* Change its body.
210227
* @param text Body of pull request
@@ -217,6 +234,7 @@ public void body(
217234
Json.createObjectBuilder().add("body", text).build()
218235
);
219236
}
237+
220238
/**
221239
* Get its URL.
222240
* @return URL of pull request
@@ -225,6 +243,7 @@ public void body(
225243
public URL url() throws IOException {
226244
return new URL(this.jsn.text("url"));
227245
}
246+
228247
/**
229248
* Get its HTML URL.
230249
* @return URL of pull request
@@ -233,6 +252,7 @@ public URL url() throws IOException {
233252
public URL htmlUrl() throws IOException {
234253
return new URL(this.jsn.text("html_url"));
235254
}
255+
236256
/**
237257
* When this pull request was created.
238258
* @return Date of creation
@@ -247,6 +267,7 @@ public Date createdAt() throws IOException {
247267
throw new IllegalStateException(ex);
248268
}
249269
}
270+
250271
/**
251272
* When this pull request was updated.
252273
* @return Date of update
@@ -261,6 +282,7 @@ public Date updatedAt() throws IOException {
261282
throw new IllegalStateException(ex);
262283
}
263284
}
285+
264286
/**
265287
* When this pull request was closed.
266288
* @return Date of closing
@@ -275,6 +297,7 @@ public Date closedAt() throws IOException {
275297
throw new IllegalStateException(ex);
276298
}
277299
}
300+
278301
/**
279302
* When this pull request was merged.
280303
* @return Date of merging
@@ -310,6 +333,7 @@ public User author() throws IOException {
310333
public Issue issue() {
311334
return this.pull.repo().issues().get(this.pull.number());
312335
}
336+
313337
/**
314338
* Get comments count.
315339
* @return Count of comments
@@ -319,22 +343,27 @@ public Issue issue() {
319343
public int commentsCount() throws IOException {
320344
return this.jsn.number("comments");
321345
}
346+
322347
@Override
323348
public Repo repo() {
324349
return this.pull.repo();
325350
}
351+
326352
@Override
327353
public int number() {
328354
return this.pull.number();
329355
}
356+
330357
@Override
331358
public Iterable<Commit> commits() throws IOException {
332359
return this.pull.commits();
333360
}
361+
334362
@Override
335363
public Iterable<JsonObject> files() throws IOException {
336364
return this.pull.files();
337365
}
366+
338367
@Override
339368
public void merge(
340369
final String msg
@@ -345,7 +374,8 @@ public void merge(
345374
@Override
346375
public MergeState merge(
347376
final String msg,
348-
final String sha)
377+
final String sha
378+
)
349379
throws IOException {
350380
return this.pull.merge(msg, sha);
351381
}
@@ -355,16 +385,23 @@ public PullComments comments() throws IOException {
355385
return this.pull.comments();
356386
}
357387

388+
@Override
389+
public Checks checks() throws IOException {
390+
return this.pull.checks();
391+
}
392+
358393
@Override
359394
public JsonObject json() throws IOException {
360395
return this.pull.json();
361396
}
397+
362398
@Override
363399
public void patch(
364400
final JsonObject json
365401
) throws IOException {
366402
this.pull.patch(json);
367403
}
404+
368405
@Override
369406
public int compareTo(
370407
final Pull obj

src/main/java/com/jcabi/github/RtPull.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ public PullComments comments() {
178178
return new RtPullComments(this.entry, this);
179179
}
180180

181+
@Override
182+
public Checks checks() throws IOException {
183+
return new RtChecks(this.entry, this);
184+
}
185+
181186
@Override
182187
public PullRef base() throws IOException {
183188
return new RtPullRef(
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright (c) 2013-2023, jcabi.com
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met: 1) Redistributions of source code must retain the above
8+
* copyright notice, this list of conditions and the following
9+
* disclaimer. 2) Redistributions in binary form must reproduce the above
10+
* copyright notice, this list of conditions and the following
11+
* disclaimer in the documentation and/or other materials provided
12+
* with the distribution. 3) Neither the name of the jcabi.com nor
13+
* the names of its contributors may be used to endorse or promote
14+
* products derived from this software without specific prior written
15+
* permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
19+
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20+
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21+
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28+
* OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
package com.jcabi.github.mock;
31+
32+
import com.jcabi.github.Check;
33+
import com.jcabi.github.Checks;
34+
import java.io.IOException;
35+
import java.util.Collection;
36+
import java.util.Collections;
37+
38+
/**
39+
* Mock Github Checks.
40+
*
41+
* @author Volodya Lombrozo ([email protected])
42+
* @version $Id$
43+
* @since 1.6.0
44+
*/
45+
public final class MkChecks implements Checks {
46+
@Override
47+
public Collection<Check> all() throws IOException {
48+
return Collections.emptyList();
49+
}
50+
}

src/main/java/com/jcabi/github/mock/MkPull.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import com.jcabi.aspects.Immutable;
3333
import com.jcabi.aspects.Loggable;
34+
import com.jcabi.github.Checks;
3435
import com.jcabi.github.Commit;
3536
import com.jcabi.github.Coordinates;
3637
import com.jcabi.github.MergeState;
@@ -53,12 +54,13 @@
5354
* Mock Github pull.
5455
* @author Yegor Bugayenko ([email protected])
5556
* @version $Id$
57+
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
5658
* @since 0.5
5759
*/
5860
@Immutable
5961
@Loggable(Loggable.DEBUG)
6062
@ToString
61-
@EqualsAndHashCode(of = { "storage", "self", "coords", "num" })
63+
@EqualsAndHashCode(of = {"storage", "self", "coords", "num"})
6264
@SuppressWarnings("PMD.TooManyMethods")
6365
final class MkPull implements Pull {
6466
/**
@@ -123,7 +125,8 @@ final class MkPull implements Pull {
123125
final MkStorage stg,
124126
final String login,
125127
final Coordinates rep,
126-
final int number) {
128+
final int number
129+
) {
127130
this.storage = stg;
128131
this.self = login;
129132
this.coords = rep;
@@ -200,7 +203,8 @@ public void merge(
200203
@Override
201204
public MergeState merge(
202205
final String msg,
203-
final String sha) {
206+
final String sha
207+
) {
204208
throw new UnsupportedOperationException("Merge not supported");
205209
}
206210

@@ -209,6 +213,11 @@ public PullComments comments() throws IOException {
209213
return new MkPullComments(this.storage, this.self, this.coords, this);
210214
}
211215

216+
@Override
217+
public Checks checks() {
218+
return new MkChecks();
219+
}
220+
212221
@Override
213222
public int compareTo(
214223
final Pull pull
@@ -241,8 +250,8 @@ public JsonObject json() throws IOException {
241250
json.add(
242251
MkPull.USER_PROP,
243252
Json.createObjectBuilder()
244-
.add("login", xml.xpath("user/login/text()").get(0))
245-
.build()
253+
.add("login", xml.xpath("user/login/text()").get(0))
254+
.build()
246255
);
247256
} else if (MkPull.HEAD_PROP.equals(val.getKey())) {
248257
json.add(

0 commit comments

Comments
 (0)