Coverage Report - com.jcabi.github.Commit
 
Classes in this File Line Coverage Branch Coverage Complexity
Commit
N/A
N/A
1
Commit$Smart
42%
6/14
0%
0/16
1
Commit$Smart$AjcClosure1
100%
1/1
N/A
1
Commit$Smart$AjcClosure11
0%
0/1
N/A
1
Commit$Smart$AjcClosure3
0%
0/1
N/A
1
Commit$Smart$AjcClosure5
0%
0/1
N/A
1
Commit$Smart$AjcClosure7
0%
0/1
N/A
1
Commit$Smart$AjcClosure9
0%
0/1
N/A
1
 
 1  2
 /**
 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 javax.json.JsonObject;
 37  
 import javax.validation.constraints.NotNull;
 38  
 import lombok.EqualsAndHashCode;
 39  
 import lombok.ToString;
 40  
 
 41  
 /**
 42  
  * Github commit.
 43  
  *
 44  
  * <p>The commit exposes all available properties through its
 45  
  * {@code json()} method. However, it is recommended to use its
 46  
  * "smart" decorator, which helps you to get access to all JSON properties,
 47  
  * for example:
 48  
  *
 49  
  * <pre> URL url = new Commit.Smart(commit).url();</pre>
 50  
  *
 51  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 52  
  * @version $Id$
 53  
  * @since 0.3
 54  
  * @see <a href="http://developer.github.com/v3/pulls/">Pull Request API</a>
 55  
  * @see <a href="http://developer.github.com/v3/git/commits/">Commits API</a>
 56  
  */
 57  
 @Immutable
 58  
 public interface Commit extends Comparable<Commit>, JsonReadable {
 59  
 
 60  
     /**
 61  
      * The repo we're in.
 62  
      * @return Repo
 63  
      */
 64  
     @NotNull(message = "repo is never NULL")
 65  
     Repo repo();
 66  
 
 67  
     /**
 68  
      * SHA of it.
 69  
      * @return SHA
 70  
      */
 71  
     @NotNull(message = "commit SHA is never NULL")
 72  
     String sha();
 73  
 
 74  
     /**
 75  
      * Smart commit.
 76  
      */
 77  0
     @Immutable
 78  0
     @ToString
 79  
     @Loggable(Loggable.DEBUG)
 80  0
     @EqualsAndHashCode(of = { "commit", "jsn" })
 81  
     final class Smart implements Commit {
 82  
         /**
 83  
          * Encapsulated commit.
 84  
          */
 85  
         private final transient Commit commit;
 86  
         /**
 87  
          * SmartJson object for convenient JSON parsing.
 88  
          */
 89  
         private final transient SmartJson jsn;
 90  
         /**
 91  
          * Public ctor.
 92  
          * @param cmt Commit
 93  
          */
 94  
         public Smart(
 95  
             @NotNull(message = "cmt can't be NULL") final Commit cmt
 96  1
         ) {
 97  1
             this.commit = cmt;
 98  1
             this.jsn = new SmartJson(cmt);
 99  1
         }
 100  
         /**
 101  
          * Get its message.
 102  
          * @return Message of commit
 103  
          * @throws IOException If there is any I/O problem
 104  
          */
 105  
         @NotNull(message = "message is never NULL")
 106  
         public String message() throws IOException {
 107  2
             return this.jsn.json().getJsonObject("commit").getString("message");
 108  
         }
 109  
         /**
 110  
          * Get its URL.
 111  
          * @return URL of comment
 112  
          * @throws IOException If there is any I/O problem
 113  
          */
 114  
         @NotNull(message = "URL is never NULL")
 115  
         public URL url() throws IOException {
 116  0
             return new URL(this.jsn.text("url"));
 117  
         }
 118  
         @Override
 119  
         @NotNull(message = "repository is never NULL")
 120  
         public Repo repo() {
 121  0
             return this.commit.repo();
 122  
         }
 123  
         @Override
 124  
         @NotNull(message = "sha is never NULL")
 125  
         public String sha() {
 126  0
             return this.commit.sha();
 127  
         }
 128  
         @Override
 129  
         @NotNull(message = "JSON is never NULL")
 130  
         public JsonObject json() throws IOException {
 131  0
             return this.commit.json();
 132  
         }
 133  
         @Override
 134  
         public int compareTo(
 135  
             @NotNull(message = "obj can't be NULL") final Commit obj
 136  
         ) {
 137  0
             return this.commit.compareTo(obj);
 138  
         }
 139  
     }
 140  
 
 141  
 }