Coverage Report - com.jcabi.github.RtTags
 
Classes in this File Line Coverage Branch Coverage Complexity
RtTags
83%
10/12
0%
0/22
1
RtTags$AjcClosure1
0%
0/1
N/A
1
RtTags$AjcClosure3
100%
1/1
N/A
1
RtTags$AjcClosure5
100%
1/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 Tags.
 45  
  * @author Mihai Andronache (amihaiemil@gmail.com)
 46  
  * @version $Id$
 47  
  */
 48  
 @Immutable
 49  
 @Loggable(Loggable.DEBUG)
 50  0
 @EqualsAndHashCode(of = {"entry", "request", "owner" })
 51  
 final class RtTags implements Tags {
 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  
     RtTags(
 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()).path("/git").path("/tags").back();
 80  1
     }
 81  
 
 82  
     @Override
 83  
     @NotNull(message = "Repository is never NULL")
 84  
     public Repo repo() {
 85  0
         return this.owner;
 86  
     }
 87  
 
 88  
     @Override
 89  
     @NotNull(message = "tag is never NULL")
 90  
     public Tag create(
 91  
         @NotNull(message = "params can't be NULL") final JsonObject params
 92  
     ) throws IOException {
 93  2
         final Tag created = this.get(
 94  
             this.request.method(Request.POST)
 95  
                 .body().set(params).back()
 96  
                 .fetch().as(RestResponse.class)
 97  
                 .assertStatus(HttpURLConnection.HTTP_CREATED)
 98  
                 .as(JsonResponse.class)
 99  
                 .json().readObject().getString("sha")
 100  
         );
 101  1
         new RtReferences(this.entry, this.owner).create(
 102  
             new StringBuilder().append("refs/tags/").append(
 103  
                 params.getString("tag")
 104  
             ).toString(),
 105  
             created.key()
 106  
         );
 107  1
         return created;
 108  
     }
 109  
 
 110  
     @Override
 111  
     @NotNull(message = "tag is never NULL")
 112  
     public Tag get(
 113  
         @NotNull(message = "sha can't be NULL") final String sha
 114  
     ) {
 115  2
         return new RtTag(this.entry, this.owner, sha);
 116  
     }
 117  
 
 118  
 }