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