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