Coverage Report - com.jcabi.github.RtRepo
 
Classes in this File Line Coverage Branch Coverage Complexity
RtRepo
82%
42/51
6%
2/30
1.04
RtRepo$AjcClosure1
0%
0/1
N/A
1.04
RtRepo$AjcClosure11
100%
1/1
N/A
1.04
RtRepo$AjcClosure13
100%
1/1
N/A
1.04
RtRepo$AjcClosure15
100%
1/1
N/A
1.04
RtRepo$AjcClosure17
0%
0/1
N/A
1.04
RtRepo$AjcClosure19
100%
1/1
N/A
1.04
RtRepo$AjcClosure21
100%
1/1
N/A
1.04
RtRepo$AjcClosure23
0%
0/1
N/A
1.04
RtRepo$AjcClosure25
100%
1/1
N/A
1.04
RtRepo$AjcClosure27
0%
0/1
N/A
1.04
RtRepo$AjcClosure29
100%
1/1
N/A
1.04
RtRepo$AjcClosure3
100%
1/1
N/A
1.04
RtRepo$AjcClosure31
100%
1/1
N/A
1.04
RtRepo$AjcClosure33
100%
1/1
N/A
1.04
RtRepo$AjcClosure35
100%
1/1
N/A
1.04
RtRepo$AjcClosure37
100%
1/1
N/A
1.04
RtRepo$AjcClosure39
100%
1/1
N/A
1.04
RtRepo$AjcClosure41
100%
1/1
N/A
1.04
RtRepo$AjcClosure43
100%
1/1
N/A
1.04
RtRepo$AjcClosure45
0%
0/1
N/A
1.04
RtRepo$AjcClosure5
100%
1/1
N/A
1.04
RtRepo$AjcClosure7
0%
0/1
N/A
1.04
RtRepo$AjcClosure9
100%
1/1
N/A
1.04
 
 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 java.io.IOException;
 36  
 import java.util.ArrayList;
 37  
 import java.util.List;
 38  
 import java.util.Map;
 39  
 import javax.json.JsonObject;
 40  
 import javax.json.JsonValue;
 41  
 import lombok.EqualsAndHashCode;
 42  
 
 43  
 /**
 44  
  * Github repository.
 45  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 46  
  * @version $Id: ca1e44356707140a1aade4c1de2d7518a9b3545b $
 47  
  * @since 0.1
 48  
  * @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
 49  
  * @checkstyle ClassFanOutComplexity (10 lines)
 50  
  */
 51  0
 @Immutable
 52  
 @Loggable(Loggable.DEBUG)
 53  0
 @EqualsAndHashCode(of = { "ghub", "entry", "coords" })
 54  
 @SuppressWarnings
 55  
     (
 56  
         {
 57  
             "PMD.TooManyMethods",
 58  
         "PMD.CouplingBetweenObjects"
 59  
         }
 60  
     )
 61  
 final class RtRepo implements Repo {
 62  
 
 63  
     /**
 64  
      * Github.
 65  
      */
 66  
     private final transient Github ghub;
 67  
 
 68  
     /**
 69  
      * RESTful entry.
 70  
      */
 71  
     private final transient Request entry;
 72  
 
 73  
     /**
 74  
      * RESTful request.
 75  
      */
 76  
     private final transient Request request;
 77  
 
 78  
     /**
 79  
      * Repository coordinates.
 80  
      */
 81  
     private final transient Coordinates coords;
 82  
 
 83  
     /**
 84  
      * Public ctor.
 85  
      * @param github Github
 86  
      * @param req Request
 87  
      * @param crd Coordinate of the repo
 88  
      */
 89  36
     RtRepo(final Github github, final Request req, final Coordinates crd) {
 90  36
         this.ghub = github;
 91  36
         this.entry = req;
 92  36
         this.coords = crd;
 93  36
         this.request = this.entry.uri()
 94  36
             .path("/repos")
 95  36
             .path(this.coords.user())
 96  36
             .path(this.coords.repo())
 97  36
             .back();
 98  36
     }
 99  
 
 100  
     @Override
 101  
     public String toString() {
 102  0
         return this.coords.toString();
 103  
     }
 104  
 
 105  
     @Override
 106  
     public Github github() {
 107  0
         return this.ghub;
 108  
     }
 109  
 
 110  
     @Override
 111  
     public Coordinates coordinates() {
 112  102
         return this.coords;
 113  
     }
 114  
 
 115  
     @Override
 116  
     public Issues issues() {
 117  4
         return new RtIssues(this.entry, this);
 118  
     }
 119  
 
 120  
     @Override
 121  
     public Milestones milestones() {
 122  0
         return new RtMilestones(this.entry, this);
 123  
     }
 124  
 
 125  
     @Override
 126  
     public Pulls pulls() {
 127  2
         return new RtPulls(this.entry, this);
 128  
     }
 129  
 
 130  
     @Override
 131  
     public Hooks hooks() {
 132  2
         return new RtHooks(this.entry, this);
 133  
     }
 134  
 
 135  
     @Override
 136  
     public IssueEvents issueEvents() {
 137  2
         return new RtIssueEvents(this.entry, this);
 138  
     }
 139  
 
 140  
     @Override
 141  
     public Labels labels() {
 142  2
         return new RtLabels(this.entry, this);
 143  
     }
 144  
 
 145  
     @Override
 146  
     public Assignees assignees() {
 147  0
         return new RtAssignees(this.entry, this);
 148  
     }
 149  
 
 150  
     @Override
 151  
     public Releases releases() {
 152  2
         return new RtReleases(this.entry, this);
 153  
     }
 154  
 
 155  
     @Override
 156  
     public DeployKeys keys() {
 157  2
         return new RtDeployKeys(this.entry, this);
 158  
     }
 159  
 
 160  
     @Override
 161  
     public Forks forks() {
 162  0
         return new RtForks(this.entry, this);
 163  
     }
 164  
 
 165  
     @Override
 166  
     public Contents contents() {
 167  6
         return new RtContents(this.entry, this);
 168  
     }
 169  
 
 170  
     @Override
 171  
     public Collaborators collaborators() {
 172  0
         return new RtCollaborators(this.entry, this);
 173  
     }
 174  
 
 175  
     @Override
 176  
     public Git git() {
 177  2
         return new RtGit(this.entry, this);
 178  
     }
 179  
 
 180  
     @Override
 181  
     public Stars stars() {
 182  2
         return new RtStars(this.entry, this);
 183  
     }
 184  
 
 185  
     @Override
 186  
     public Notifications notifications() {
 187  3
         return new RtNotifications(
 188  1
             this.request.uri().path("notifications").back()
 189  
         );
 190  
     }
 191  
 
 192  
     @Override
 193  
     @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
 194  
     public Iterable<Language> languages() throws IOException {
 195  4
         final RtJson json = new RtJson(
 196  2
             this.request.uri()
 197  2
                 .path("/languages")
 198  2
                 .back()
 199  
         );
 200  2
         final JsonObject object = json.fetch();
 201  2
         final List<Language> languages =
 202  2
             new ArrayList<Language>(object.size());
 203  2
         for (final Map.Entry<String, JsonValue> value : object.entrySet()) {
 204  3
             final String name = value.getKey();
 205  6
             languages.add(
 206  
                 new RtLanguage(
 207  
                     name,
 208  3
                     object.getJsonNumber(name).longValue()
 209  
                 )
 210  
             );
 211  3
         }
 212  2
         return languages;
 213  
     }
 214  
 
 215  
     @Override
 216  
     public void patch(
 217  
         final JsonObject json)
 218  
         throws IOException {
 219  2
         new RtJson(this.request).patch(json);
 220  1
     }
 221  
 
 222  
     @Override
 223  
     public RepoCommits commits() {
 224  4
         return new RtRepoCommits(this.entry, this);
 225  
     }
 226  
 
 227  
     @Override
 228  
     public Branches branches() {
 229  2
         return new RtBranches(this.entry, this);
 230  
     }
 231  
 
 232  
     @Override
 233  
     public JsonObject json() throws IOException {
 234  2
         return new RtJson(this.request).fetch();
 235  
     }
 236  
 
 237  
     @Override
 238  
     public int compareTo(final Repo repo) {
 239  0
         return this.coords.compareTo(repo.coordinates());
 240  
     }
 241  
 }