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