Coverage Report - com.jcabi.github.Repos
 
Classes in this File Line Coverage Branch Coverage Complexity
Repos
N/A
N/A
1.158
Repos$RepoCreate
70%
24/34
6%
3/44
1.158
Repos$RepoCreate$AjcClosure1
100%
1/1
N/A
1.158
Repos$RepoCreate$AjcClosure11
100%
1/1
N/A
1.158
Repos$RepoCreate$AjcClosure13
0%
0/1
N/A
1.158
Repos$RepoCreate$AjcClosure15
100%
1/1
N/A
1.158
Repos$RepoCreate$AjcClosure17
0%
0/1
N/A
1.158
Repos$RepoCreate$AjcClosure19
0%
0/1
N/A
1.158
Repos$RepoCreate$AjcClosure21
100%
1/1
N/A
1.158
Repos$RepoCreate$AjcClosure23
100%
1/1
N/A
1.158
Repos$RepoCreate$AjcClosure3
0%
0/1
N/A
1.158
Repos$RepoCreate$AjcClosure5
0%
0/1
N/A
1.158
Repos$RepoCreate$AjcClosure7
0%
0/1
N/A
1.158
Repos$RepoCreate$AjcClosure9
0%
0/1
N/A
1.158
 
 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.google.common.base.Optional;
 33  
 import com.jcabi.aspects.Immutable;
 34  
 import com.jcabi.aspects.Loggable;
 35  
 import java.io.IOException;
 36  
 import javax.json.Json;
 37  
 import javax.json.JsonObject;
 38  
 import javax.json.JsonObjectBuilder;
 39  
 import lombok.EqualsAndHashCode;
 40  
 import lombok.ToString;
 41  
 
 42  
 /**
 43  
  * Github Repo API.
 44  
  *
 45  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 46  
  * @version $Id: 1c62e9ef0661c87bfe9254d66a3cc62852749c71 $
 47  
  * @since 0.5
 48  
  * @see <a href="http://developer.github.com/v3/repos/">Repos API</a>
 49  
  */
 50  
 @SuppressWarnings("PMD.TooManyMethods")
 51  
 @Immutable
 52  
 public interface Repos {
 53  
 
 54  
     /**
 55  
      * Get its owner.
 56  
      * @return Github
 57  
      */
 58  
     Github github();
 59  
     //byte[]
 60  
 
 61  
     /**
 62  
      * Create repository.
 63  
      * @param settings Settings to use for creating the new repository
 64  
      * @return Repository
 65  
      * @throws IOException If there is any I/O problem
 66  
      * @since 0.5
 67  
      * @see <a href="http://developer.github.com/v3/repos/#create">Create Repository</a>
 68  
      */
 69  
     Repo create(RepoCreate settings)
 70  
         throws IOException;
 71  
 
 72  
     /**
 73  
      * Get repository by name.
 74  
      * @param coords Repository name in "user/repo" format
 75  
      * @return Repository
 76  
      * @see <a href="http://developer.github.com/v3/repos/#get">Get Repository</a>
 77  
      */
 78  
     Repo get(Coordinates coords);
 79  
 
 80  
     /**
 81  
      * Remove repository by name.
 82  
      *
 83  
      * <p>Note: Deleting a repository requires admin access.
 84  
      * If OAuth is used, the delete_repo scope is required.
 85  
      *
 86  
      * @param coords Repository name in "user/repo" format
 87  
      * @throws IOException If there is any I/O problem
 88  
      * @see <a href="http://developer.github.com/v3/repos/#delete-a-repository">Delete a Repository</a>
 89  
      */
 90  
     void remove(Coordinates coords) throws IOException;
 91  
 
 92  
     /**
 93  
      * Iterate all public repos, starting with the one you've seen already.
 94  
      * @param identifier The integer ID of the last Repo that you’ve seen.
 95  
      * @return Iterator of repo
 96  
      * @see <a href="https://developer.github.com/v3/repos/#list-all-public-repositories">List all public repositories</a>
 97  
      */
 98  
     Iterable<Repo> iterate(
 99  
         String identifier
 100  
     );
 101  
 
 102  
     /**
 103  
      * Settings to use when creating a new GitHub repository.
 104  
      *
 105  
      * @author Chris Rebert (github@rebertia.com)
 106  
      * @version $Id: 1c62e9ef0661c87bfe9254d66a3cc62852749c71 $
 107  
      * @since 0.24
 108  
      * @see <a href="https://developer.github.com/v3/repos/#create">Create Repo API</a>
 109  
      * @todo #1095:30m Add the ability to set the other parameters of
 110  
      *  the repo creation API (has_issues, has_wiki, has_downloads,
 111  
      *  team_id, gitignore_template, license_template).
 112  
      */
 113  
     @SuppressWarnings("PMD.TooManyMethods")
 114  0
     @ToString
 115  
     @Loggable(Loggable.DEBUG)
 116  0
     @EqualsAndHashCode(of = { "nam", "priv", "descr", "home", "init" })
 117  
     final class RepoCreate implements JsonReadable {
 118  
         /**
 119  
          * Name of the new repo.
 120  
          */
 121  
         private final transient String nam;
 122  
         /**
 123  
          * Privateness of the new repo.
 124  
          */
 125  
         private final transient boolean priv;
 126  
         /**
 127  
          * Description of the new repo.
 128  
          */
 129  
         private final transient String descr;
 130  
         /**
 131  
          * Homepage of the new repo.
 132  
          */
 133  
         private final transient String home;
 134  
         /**
 135  
          * Auto-init the new repo?
 136  
          */
 137  
         private final transient Optional<Boolean> init;
 138  
 
 139  
         /**
 140  
          * Public ctor.
 141  
          * @param nme Name of the new repository. Cannot be empty.
 142  
          * @param prvt Will the new repo be private?
 143  
          *  If not, then it will be public.
 144  
          */
 145  
         public RepoCreate(final String nme, final boolean prvt) {
 146  234
             this(nme, prvt, "", "", Optional.<Boolean>absent());
 147  235
         }
 148  
 
 149  
         /**
 150  
          * Private ctor.
 151  
          * @param nme Name of the new repo. Cannot be empty.
 152  
          * @param prvt Will the new repo be private?
 153  
          *  If not, then it will be public.
 154  
          * @param desc Description of the new repo
 155  
          * @param page Homepage of the new repo
 156  
          * @param auto Auto-init the new repo?
 157  
          * @checkstyle ParameterNumberCheck (7 lines)
 158  
          */
 159  
         private RepoCreate(
 160  
             final String nme,
 161  
             final boolean prvt,
 162  
             final String desc,
 163  
             final String page,
 164  241
             final Optional<Boolean> auto) {
 165  242
             if (nme.isEmpty()) {
 166  0
                 throw new IllegalArgumentException("Name cannot be empty!");
 167  
             }
 168  242
             this.nam = nme;
 169  242
             this.priv = prvt;
 170  242
             this.descr = desc;
 171  241
             this.home = page;
 172  242
             this.init = auto;
 173  241
         }
 174  
 
 175  
         /**
 176  
          * Name of the new repo.
 177  
          * @return Name
 178  
          */
 179  
         public String name() {
 180  931
             return this.nam;
 181  
         }
 182  
 
 183  
         /**
 184  
          * Will the new repo be private? If not, then it will be public.
 185  
          * @return Is this repo private?
 186  
          */
 187  
         public boolean isPrivate() {
 188  0
             return this.priv;
 189  
         }
 190  
 
 191  
         /**
 192  
          * Description of the new repo.
 193  
          * If it has no description, this is an empty string.
 194  
          * @return Description
 195  
          */
 196  
         public String description() {
 197  0
             return this.descr;
 198  
         }
 199  
 
 200  
         /**
 201  
          * Homepage of the new repo.
 202  
          * If it has no homepage, this is an empty string.
 203  
          * @return Homepage
 204  
          */
 205  
         public String homepage() {
 206  0
             return this.home;
 207  
         }
 208  
 
 209  
         /**
 210  
          * Auto-init the new repo?
 211  
          * If absent, the GitHub default will be used.
 212  
          * @return Optional boolean
 213  
          */
 214  
         public Optional<Boolean> autoInit() {
 215  0
             return this.init;
 216  
         }
 217  
 
 218  
         /**
 219  
          * Returns a RepoCreate with the given name.
 220  
          * The name cannot be empty.
 221  
          * @param nme Name of the new repo
 222  
          * @return RepoCreate
 223  
          */
 224  
         public RepoCreate withName(
 225  
             final String nme
 226  
         ) {
 227  2
             return new RepoCreate(
 228  
                 nme,
 229  
                 this.priv,
 230  
                 this.descr,
 231  
                 this.home,
 232  
                 this.init
 233  
             );
 234  
         }
 235  
 
 236  
         /**
 237  
          * Returns a RepoCreate with the given privacy.
 238  
          * @param privacy Privateness of the new repo
 239  
          * @return RepoCreate
 240  
          */
 241  
         public RepoCreate withPrivacy(final boolean privacy) {
 242  0
             return new RepoCreate(
 243  
                 this.nam,
 244  
                 privacy,
 245  
                 this.descr,
 246  
                 this.home,
 247  
                 this.init
 248  
             );
 249  
         }
 250  
 
 251  
         /**
 252  
          * Returns a RepoCreate with the given description.
 253  
          * @param desc Description
 254  
          * @return RepoCreate
 255  
          */
 256  
         public RepoCreate withDescription(
 257  
             final String desc
 258  
         ) {
 259  10
             return new RepoCreate(
 260  
                 this.nam,
 261  
                 this.priv,
 262  
                 desc,
 263  
                 this.home,
 264  
                 this.init
 265  
             );
 266  
         }
 267  
 
 268  
         /**
 269  
          * Returns a RepoCreate with the given homepage.
 270  
          * @param page Homepage URL
 271  
          * @return RepoCreate
 272  
          */
 273  
         public RepoCreate withHomepage(
 274  
             final String page
 275  
         ) {
 276  0
             return new RepoCreate(
 277  
                 this.nam,
 278  
                 this.priv,
 279  
                 this.descr,
 280  
                 page,
 281  
                 this.init
 282  
             );
 283  
         }
 284  
 
 285  
         /**
 286  
          * Returns a RepoCreate with the given auto-init enabledness.
 287  
          * @param auto Auto-init the new repo?
 288  
          * @return RepoCreate
 289  
          */
 290  
         public RepoCreate withAutoInit(final Optional<Boolean> auto) {
 291  0
             return new RepoCreate(
 292  
                 this.nam,
 293  
                 this.priv,
 294  
                 this.descr,
 295  
                 this.home,
 296  
                 auto
 297  
             );
 298  
         }
 299  
 
 300  
         /**
 301  
          * Returns a RepoCreate with the given auto-init enabledness.
 302  
          * @param auto Auto-init the new repo?
 303  
          * @return RepoCreate
 304  
          */
 305  
         public RepoCreate withAutoInit(final boolean auto) {
 306  3
             return new RepoCreate(
 307  
                 this.nam,
 308  
                 this.priv,
 309  
                 this.descr,
 310  
                 this.home,
 311  1
                 Optional.of(auto)
 312  
             );
 313  
         }
 314  
 
 315  
         @Override
 316  
         public JsonObject json() {
 317  472
             JsonObjectBuilder builder = Json.createObjectBuilder()
 318  234
                 .add("name", this.nam)
 319  235
                 .add("description", this.descr)
 320  238
                 .add("homepage", this.home)
 321  236
                 .add("private", this.priv);
 322  235
             if (this.init.isPresent()) {
 323  1
                 builder = builder.add("auto_init", this.init.get());
 324  
             }
 325  235
             return builder.build();
 326  
         }
 327  
     }
 328  
 }