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