Coverage Report - com.jcabi.github.RtRepo
 
Classes in this File Line Coverage Branch Coverage Complexity
RtRepo
82%
41/50
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: 3bbac7d90c2e8ae7a6ad0c9b117c4bd2b67185c3 $
 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  35
     }
 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  104
         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  2
         return new RtNotifications();
 188  
     }
 189  
 
 190  
     @Override
 191  
     @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
 192  
     public Iterable<Language> languages() throws IOException {
 193  4
         final RtJson json = new RtJson(
 194  2
             this.request.uri()
 195  2
                 .path("/languages")
 196  2
                 .back()
 197  
         );
 198  2
         final JsonObject object = json.fetch();
 199  2
         final List<Language> languages =
 200  2
             new ArrayList<Language>(object.size());
 201  2
         for (final Map.Entry<String, JsonValue> value : object.entrySet()) {
 202  3
             final String name = value.getKey();
 203  6
             languages.add(
 204  
                 new RtLanguage(
 205  
                     name,
 206  3
                     object.getJsonNumber(name).longValue()
 207  
                 )
 208  
             );
 209  3
         }
 210  2
         return languages;
 211  
     }
 212  
 
 213  
     @Override
 214  
     public void patch(
 215  
         final JsonObject json)
 216  
         throws IOException {
 217  2
         new RtJson(this.request).patch(json);
 218  1
     }
 219  
 
 220  
     @Override
 221  
     public RepoCommits commits() {
 222  4
         return new RtRepoCommits(this.entry, this);
 223  
     }
 224  
 
 225  
     @Override
 226  
     public Branches branches() {
 227  2
         return new RtBranches(this.entry, this);
 228  
     }
 229  
 
 230  
     @Override
 231  
     public JsonObject json() throws IOException {
 232  2
         return new RtJson(this.request).fetch();
 233  
     }
 234  
 
 235  
     @Override
 236  
     public int compareTo(final Repo repo) {
 237  0
         return this.coords.compareTo(repo.coordinates());
 238  
     }
 239  
 }