Coverage Report - com.jcabi.github.RtCommits
 
Classes in this File Line Coverage Branch Coverage Complexity
RtCommits
85%
17/20
0%
0/28
1
RtCommits$AjcClosure1
0%
0/1
N/A
1
RtCommits$AjcClosure3
100%
1/1
N/A
1
RtCommits$AjcClosure5
100%
1/1
N/A
1
RtCommits$AjcClosure7
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 com.jcabi.http.Request;
 35  
 import com.jcabi.http.response.JsonResponse;
 36  
 import com.jcabi.http.response.RestResponse;
 37  
 import java.io.IOException;
 38  
 import java.net.HttpURLConnection;
 39  
 import javax.json.JsonObject;
 40  
 import lombok.EqualsAndHashCode;
 41  
 
 42  
 /**
 43  
  * Github Commits.
 44  
  * @author Ed Hillmann (edhillmann@yahoo.com)
 45  
  * @version $Id: 82f7f4d2112d10a943c4e2fceb42ba36bbfba93d $
 46  
  */
 47  
 @Immutable
 48  
 @Loggable(Loggable.DEBUG)
 49  0
 @EqualsAndHashCode(of = {"entry", "request", "owner" })
 50  
 public final class RtCommits implements Commits {
 51  
     /**
 52  
      * RESTful API entry point.
 53  
      */
 54  
     private final transient Request entry;
 55  
 
 56  
     /**
 57  
      * RESTful request for the commits.
 58  
      */
 59  
     private final transient Request request;
 60  
 
 61  
     /**
 62  
      * Repository.
 63  
      */
 64  
     private final transient Repo owner;
 65  
 
 66  
     /**
 67  
      * Public constructor.
 68  
      * @param req The entry request.
 69  
      * @param repo The owner repo.
 70  
      */
 71  
     RtCommits(
 72  
         final Request req,
 73  
         final Repo repo
 74  1
     ) {
 75  1
         this.entry = req;
 76  1
         this.owner = repo;
 77  1
         this.request = req.uri().path("/repos").path(repo.coordinates().user())
 78  1
             .path(repo.coordinates().repo())
 79  1
             .path("/git")
 80  1
             .path("/commits").back();
 81  1
     }
 82  
 
 83  
     @Override
 84  
     public Repo repo() {
 85  0
         return this.owner;
 86  
     }
 87  
 
 88  
     @Override
 89  
     public Commit create(
 90  
         final JsonObject params
 91  
     ) throws IOException {
 92  3
         return this.get(
 93  1
             this.request.method(Request.POST)
 94  1
                 .body().set(params).back()
 95  1
                 .fetch().as(RestResponse.class)
 96  1
                 .assertStatus(HttpURLConnection.HTTP_CREATED)
 97  1
                 .as(JsonResponse.class)
 98  1
                 .json().readObject().getString("sha")
 99  
         );
 100  
     }
 101  
 
 102  
     @Override
 103  
     public Commit get(
 104  
         final String sha
 105  
     ) {
 106  2
         return new RtCommit(this.entry, this.owner, sha);
 107  
     }
 108  
 
 109  
     @Override
 110  
     public Statuses statuses(
 111  
         final String ref
 112  
     ) {
 113  0
         return new RtStatuses(this.entry, this.get(ref));
 114  
     }
 115  
 }