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/20
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-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 commit.
 42  
  *
 43  
  * <p>The 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 Commit.Smart(commit).url();</pre>
 49  
  *
 50  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 51  
  * @version $Id: dfe63df7f52858534773a59a7d089c203d43ab20 $
 52  
  * @since 0.3
 53  
  * @see <a href="http://developer.github.com/v3/pulls/">Pull Request API</a>
 54  
  * @see <a href="http://developer.github.com/v3/git/commits/">Commits API</a>
 55  
  */
 56  
 @Immutable
 57  
 public interface Commit extends Comparable<Commit>, JsonReadable {
 58  
 
 59  
     /**
 60  
      * The repo we're in.
 61  
      * @return Repo
 62  
      */
 63  
     Repo repo();
 64  
 
 65  
     /**
 66  
      * SHA of it.
 67  
      * @return SHA
 68  
      */
 69  
     String sha();
 70  
 
 71  
     /**
 72  
      * Smart commit.
 73  
      */
 74  0
     @Immutable
 75  0
     @ToString
 76  
     @Loggable(Loggable.DEBUG)
 77  0
     @EqualsAndHashCode(of = { "commit", "jsn" })
 78  
     final class Smart implements Commit {
 79  
         /**
 80  
          * Encapsulated commit.
 81  
          */
 82  
         private final transient Commit commit;
 83  
         /**
 84  
          * SmartJson object for convenient JSON parsing.
 85  
          */
 86  
         private final transient SmartJson jsn;
 87  
         /**
 88  
          * Public ctor.
 89  
          * @param cmt Commit
 90  
          */
 91  1
         public Smart(final Commit cmt) {
 92  1
             this.commit = cmt;
 93  1
             this.jsn = new SmartJson(cmt);
 94  1
         }
 95  
         /**
 96  
          * Get its message.
 97  
          * @return Message of commit
 98  
          * @throws IOException If there is any I/O problem
 99  
          */
 100  
         public String message() throws IOException {
 101  2
             return this.jsn.json().getJsonObject("commit").getString("message");
 102  
         }
 103  
         /**
 104  
          * Get its URL.
 105  
          * @return URL of comment
 106  
          * @throws IOException If there is any I/O problem
 107  
          */
 108  
         public URL url() throws IOException {
 109  0
             return new URL(this.jsn.text("url"));
 110  
         }
 111  
         @Override
 112  
         public Repo repo() {
 113  0
             return this.commit.repo();
 114  
         }
 115  
         @Override
 116  
         public String sha() {
 117  0
             return this.commit.sha();
 118  
         }
 119  
         @Override
 120  
         public JsonObject json() throws IOException {
 121  0
             return this.commit.json();
 122  
         }
 123  
         @Override
 124  
         public int compareTo(final Commit obj) {
 125  0
             return this.commit.compareTo(obj);
 126  
         }
 127  
     }
 128  
 
 129  
 }