| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Pull |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure1 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure11 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure13 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure15 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure17 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure19 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure21 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure23 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure25 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure27 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure29 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure3 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure31 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure33 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure35 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure37 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure39 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure41 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure43 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure45 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure47 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure49 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure5 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure51 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure53 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure55 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure7 |
|
| 1.3157894736842106;1.316 | ||||
| Pull$Smart$AjcClosure9 |
|
| 1.3157894736842106;1.316 |
| 1 | 0 | /** |
| 2 | * Copyright (c) 2013-2017, 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; | |
| 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 | * Github pull request. | |
| 45 | * | |
| 46 | * @author Yegor Bugayenko (yegor@tpc2.com) | |
| 47 | * @version $Id: 264af08503b768f1a6ca5e607d29fc45a5d61a15 $ | |
| 48 | * @since 0.3 | |
| 49 | * @see <a href="http://developer.github.com/v3/pulls/">Pull Request API</a> | |
| 50 | * @checkstyle MultipleStringLiterals (500 lines) | |
| 51 | * | |
| 52 | */ | |
| 53 | @Immutable | |
| 54 | @SuppressWarnings("PMD.TooManyMethods") | |
| 55 | public interface Pull extends Comparable<Pull>, JsonReadable, JsonPatchable { | |
| 56 | ||
| 57 | /** | |
| 58 | * Repo we're in. | |
| 59 | * @return Repo | |
| 60 | */ | |
| 61 | Repo repo(); | |
| 62 | ||
| 63 | /** | |
| 64 | * Get its number. | |
| 65 | * @return Pull request number | |
| 66 | */ | |
| 67 | int number(); | |
| 68 | ||
| 69 | /** | |
| 70 | * Get its base ref. | |
| 71 | * @return Base ref | |
| 72 | * @throws IOException If there is any I/O problem | |
| 73 | */ | |
| 74 | PullRef base() throws IOException; | |
| 75 | ||
| 76 | /** | |
| 77 | * Get its head ref. | |
| 78 | * @return Head ref | |
| 79 | * @throws IOException If there is any I/O problem | |
| 80 | */ | |
| 81 | PullRef head() throws IOException; | |
| 82 | ||
| 83 | /** | |
| 84 | * Get all commits of the pull request. | |
| 85 | * @return Commits | |
| 86 | * @throws IOException If there is any I/O problem | |
| 87 | * @see <a href="http://developer.github.com/v3/pulls/#list-commits-on-a-pull-request">List Commits on a Pull Request</a> | |
| 88 | */ | |
| 89 | Iterable<Commit> commits() throws IOException; | |
| 90 | ||
| 91 | /** | |
| 92 | * List all files of the pull request. | |
| 93 | * @return Files | |
| 94 | * @throws IOException If there is any I/O problem | |
| 95 | * @see <a href="http://developer.github.com/v3/pulls/#list-pull-requests-files">List Pull Request Files</a> | |
| 96 | */ | |
| 97 | Iterable<JsonObject> files() throws IOException; | |
| 98 | ||
| 99 | /** | |
| 100 | * Merge it. | |
| 101 | * @param msg Commit message | |
| 102 | * @throws IOException If there is any I/O problem | |
| 103 | * @see <a href="http://developer.github.com/v3/pulls/#merge-a-pull-request-merge-buttontrade">Merge a Pull Request</a> | |
| 104 | */ | |
| 105 | void merge(String msg) | |
| 106 | throws IOException; | |
| 107 | ||
| 108 | /** | |
| 109 | * Merge it. | |
| 110 | * @param msg Commit message | |
| 111 | * @param sha Optional SHA hash for head comparison | |
| 112 | * @return State of the Merge | |
| 113 | * @throws IOException IOException If there is any I/O problem | |
| 114 | */ | |
| 115 | MergeState merge(String msg, | |
| 116 | String sha) throws IOException; | |
| 117 | ||
| 118 | /** | |
| 119 | * Get Pull Comments. | |
| 120 | * @return Comments. | |
| 121 | * @throws IOException If there is any I/O problem | |
| 122 | * @see <a href="http://developer.github.com/v3/pulls/#link-relations">Link Relations - Review Comments</a> | |
| 123 | */ | |
| 124 | PullComments comments() throws IOException; | |
| 125 | ||
| 126 | /** | |
| 127 | * Smart pull request with extra features. | |
| 128 | */ | |
| 129 | 0 | @Immutable |
| 130 | 0 | @ToString |
| 131 | @Loggable(Loggable.DEBUG) | |
| 132 | 0 | @EqualsAndHashCode(of = { "pull", "jsn" }) |
| 133 | final class Smart implements Pull { | |
| 134 | /** | |
| 135 | * Encapsulated pull request. | |
| 136 | */ | |
| 137 | private final transient Pull pull; | |
| 138 | /** | |
| 139 | * SmartJson object for convenient JSON parsing. | |
| 140 | */ | |
| 141 | private final transient SmartJson jsn; | |
| 142 | /** | |
| 143 | * Public ctor. | |
| 144 | * @param pll Pull request | |
| 145 | */ | |
| 146 | public Smart( | |
| 147 | final Pull pll | |
| 148 | 6 | ) { |
| 149 | 6 | this.pull = pll; |
| 150 | 6 | this.jsn = new SmartJson(pll); |
| 151 | 6 | } |
| 152 | /** | |
| 153 | * Is it open? | |
| 154 | * @return TRUE if it's open | |
| 155 | * @throws IOException If there is any I/O problem | |
| 156 | */ | |
| 157 | public boolean isOpen() throws IOException { | |
| 158 | 0 | return Issue.OPEN_STATE.equals(this.state()); |
| 159 | } | |
| 160 | /** | |
| 161 | * Get its state. | |
| 162 | * @return State of pull request | |
| 163 | * @throws IOException If there is any I/O problem | |
| 164 | */ | |
| 165 | public String state() throws IOException { | |
| 166 | 0 | return this.jsn.text("state"); |
| 167 | } | |
| 168 | /** | |
| 169 | * Change its state. | |
| 170 | * @param state State of pull request | |
| 171 | * @throws IOException If there is any I/O problem | |
| 172 | */ | |
| 173 | public void state( | |
| 174 | final String state | |
| 175 | ) throws IOException { | |
| 176 | 0 | this.pull.patch( |
| 177 | 0 | Json.createObjectBuilder().add("state", state).build() |
| 178 | ); | |
| 179 | 0 | } |
| 180 | /** | |
| 181 | * Get its title. | |
| 182 | * @return Title of pull request | |
| 183 | * @throws IOException If there is any I/O problem | |
| 184 | */ | |
| 185 | public String title() throws IOException { | |
| 186 | 4 | return this.jsn.text("title"); |
| 187 | } | |
| 188 | /** | |
| 189 | * Change its title. | |
| 190 | * @param text Title of pull request | |
| 191 | * @throws IOException If there is any I/O problem | |
| 192 | */ | |
| 193 | public void title( | |
| 194 | final String text | |
| 195 | ) throws IOException { | |
| 196 | 0 | this.pull.patch( |
| 197 | 0 | Json.createObjectBuilder().add("title", text).build() |
| 198 | ); | |
| 199 | 0 | } |
| 200 | /** | |
| 201 | * Get its body. | |
| 202 | * @return Body of pull request | |
| 203 | * @throws IOException If there is any I/O problem | |
| 204 | */ | |
| 205 | public String body() throws IOException { | |
| 206 | 0 | return this.jsn.text("body"); |
| 207 | } | |
| 208 | /** | |
| 209 | * Change its body. | |
| 210 | * @param text Body of pull request | |
| 211 | * @throws IOException If there is any I/O problem | |
| 212 | */ | |
| 213 | public void body( | |
| 214 | final String text | |
| 215 | ) throws IOException { | |
| 216 | 0 | this.pull.patch( |
| 217 | 0 | Json.createObjectBuilder().add("body", text).build() |
| 218 | ); | |
| 219 | 0 | } |
| 220 | /** | |
| 221 | * Get its URL. | |
| 222 | * @return URL of pull request | |
| 223 | * @throws IOException If there is any I/O problem | |
| 224 | */ | |
| 225 | public URL url() throws IOException { | |
| 226 | 0 | return new URL(this.jsn.text("url")); |
| 227 | } | |
| 228 | /** | |
| 229 | * Get its HTML URL. | |
| 230 | * @return URL of pull request | |
| 231 | * @throws IOException If there is any I/O problem | |
| 232 | */ | |
| 233 | public URL htmlUrl() throws IOException { | |
| 234 | 0 | return new URL(this.jsn.text("html_url")); |
| 235 | } | |
| 236 | /** | |
| 237 | * When this pull request was created. | |
| 238 | * @return Date of creation | |
| 239 | * @throws IOException If there is any I/O problem | |
| 240 | */ | |
| 241 | public Date createdAt() throws IOException { | |
| 242 | try { | |
| 243 | 0 | return new Github.Time( |
| 244 | 0 | this.jsn.text("created_at") |
| 245 | 0 | ).date(); |
| 246 | 0 | } catch (final ParseException ex) { |
| 247 | 0 | throw new IllegalStateException(ex); |
| 248 | } | |
| 249 | } | |
| 250 | /** | |
| 251 | * When this pull request was updated. | |
| 252 | * @return Date of update | |
| 253 | * @throws IOException If there is any I/O problem | |
| 254 | */ | |
| 255 | public Date updatedAt() throws IOException { | |
| 256 | try { | |
| 257 | 0 | return new Github.Time( |
| 258 | 0 | this.jsn.text("updated_at") |
| 259 | 0 | ).date(); |
| 260 | 0 | } catch (final ParseException ex) { |
| 261 | 0 | throw new IllegalStateException(ex); |
| 262 | } | |
| 263 | } | |
| 264 | /** | |
| 265 | * When this pull request was closed. | |
| 266 | * @return Date of closing | |
| 267 | * @throws IOException If there is any I/O problem | |
| 268 | */ | |
| 269 | public Date closedAt() throws IOException { | |
| 270 | try { | |
| 271 | 0 | return new Github.Time( |
| 272 | 0 | this.jsn.text("closed_at") |
| 273 | 0 | ).date(); |
| 274 | 0 | } catch (final ParseException ex) { |
| 275 | 0 | throw new IllegalStateException(ex); |
| 276 | } | |
| 277 | } | |
| 278 | /** | |
| 279 | * When this pull request was merged. | |
| 280 | * @return Date of merging | |
| 281 | * @throws IOException If there is any I/O problem | |
| 282 | */ | |
| 283 | public Date mergedAt() throws IOException { | |
| 284 | try { | |
| 285 | 0 | return new Github.Time( |
| 286 | 0 | this.jsn.text("merged_at") |
| 287 | 0 | ).date(); |
| 288 | 0 | } catch (final ParseException ex) { |
| 289 | 0 | throw new IllegalStateException(ex); |
| 290 | } | |
| 291 | } | |
| 292 | ||
| 293 | /** | |
| 294 | * Get its author. | |
| 295 | * @return Author of pull request (who submitted it) | |
| 296 | * @throws IOException If there is any I/O problem | |
| 297 | */ | |
| 298 | public User author() throws IOException { | |
| 299 | 3 | return this.pull.repo().github().users().get( |
| 300 | 1 | this.jsn.value( |
| 301 | "user", JsonObject.class | |
| 302 | 1 | ).getString("login") |
| 303 | ); | |
| 304 | } | |
| 305 | ||
| 306 | /** | |
| 307 | * Get an issue where the pull request is submitted. | |
| 308 | * @return Issue | |
| 309 | */ | |
| 310 | public Issue issue() { | |
| 311 | 2 | return this.pull.repo().issues().get(this.pull.number()); |
| 312 | } | |
| 313 | /** | |
| 314 | * Get comments count. | |
| 315 | * @return Count of comments | |
| 316 | * @throws IOException If there is any I/O problem | |
| 317 | * @since 0.8 | |
| 318 | */ | |
| 319 | public int commentsCount() throws IOException { | |
| 320 | 2 | return this.jsn.number("comments"); |
| 321 | } | |
| 322 | @Override | |
| 323 | public Repo repo() { | |
| 324 | 0 | return this.pull.repo(); |
| 325 | } | |
| 326 | @Override | |
| 327 | public int number() { | |
| 328 | 0 | return this.pull.number(); |
| 329 | } | |
| 330 | @Override | |
| 331 | public Iterable<Commit> commits() throws IOException { | |
| 332 | 0 | return this.pull.commits(); |
| 333 | } | |
| 334 | @Override | |
| 335 | public Iterable<JsonObject> files() throws IOException { | |
| 336 | 0 | return this.pull.files(); |
| 337 | } | |
| 338 | @Override | |
| 339 | public void merge( | |
| 340 | final String msg | |
| 341 | ) throws IOException { | |
| 342 | 0 | this.pull.merge(msg); |
| 343 | 0 | } |
| 344 | ||
| 345 | @Override | |
| 346 | public MergeState merge( | |
| 347 | final String msg, | |
| 348 | final String sha) | |
| 349 | throws IOException { | |
| 350 | 0 | return this.pull.merge(msg, sha); |
| 351 | } | |
| 352 | ||
| 353 | @Override | |
| 354 | public PullComments comments() throws IOException { | |
| 355 | 2 | return this.pull.comments(); |
| 356 | } | |
| 357 | ||
| 358 | @Override | |
| 359 | public JsonObject json() throws IOException { | |
| 360 | 0 | return this.pull.json(); |
| 361 | } | |
| 362 | @Override | |
| 363 | public void patch( | |
| 364 | final JsonObject json | |
| 365 | ) throws IOException { | |
| 366 | 0 | this.pull.patch(json); |
| 367 | 0 | } |
| 368 | @Override | |
| 369 | public int compareTo( | |
| 370 | final Pull obj | |
| 371 | ) { | |
| 372 | 0 | return this.pull.compareTo(obj); |
| 373 | } | |
| 374 | ||
| 375 | @Override | |
| 376 | public PullRef base() throws IOException { | |
| 377 | 0 | return this.pull.base(); |
| 378 | } | |
| 379 | ||
| 380 | @Override | |
| 381 | public PullRef head() throws IOException { | |
| 382 | 0 | return this.pull.head(); |
| 383 | } | |
| 384 | } | |
| 385 | } |