| 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 java.io.IOException; | |
| 35 | import javax.json.JsonObject; | |
| 36 | import javax.json.JsonValue; | |
| 37 | import lombok.EqualsAndHashCode; | |
| 38 | import lombok.ToString; | |
| 39 | ||
| 40 | /** | |
| 41 | * Github repository. | |
| 42 | * @author Yegor Bugayenko (yegor@tpc2.com) | |
| 43 | * @version $Id: 8cfbedb6fd6ce1d6d223406379a811bf6a3df868 $ | |
| 44 | * @since 0.1 | |
| 45 | * @checkstyle MultipleStringLiterals (500 lines) | |
| 46 | */ | |
| 47 | @Immutable | |
| 48 | @SuppressWarnings({ "PMD.TooManyMethods", "PMD.ExcessivePublicCount" }) | |
| 49 | public interface Repo extends JsonReadable, JsonPatchable, Comparable<Repo> { | |
| 50 | ||
| 51 | /** | |
| 52 | * Get its owner. | |
| 53 | * @return Github | |
| 54 | */ | |
| 55 | Github github(); | |
| 56 | ||
| 57 | /** | |
| 58 | * Get its coordinates. | |
| 59 | * @return Coordinates | |
| 60 | */ | |
| 61 | Coordinates coordinates(); | |
| 62 | ||
| 63 | /** | |
| 64 | * Iterate issues. | |
| 65 | * @return Issues | |
| 66 | */ | |
| 67 | Issues issues(); | |
| 68 | ||
| 69 | /** | |
| 70 | * Iterate milestones. | |
| 71 | * @return Milestones | |
| 72 | * @since 0.7 | |
| 73 | */ | |
| 74 | Milestones milestones(); | |
| 75 | ||
| 76 | /** | |
| 77 | * Pull requests. | |
| 78 | * @return Pulls | |
| 79 | */ | |
| 80 | Pulls pulls(); | |
| 81 | ||
| 82 | /** | |
| 83 | * Hooks. | |
| 84 | * @return Hooks | |
| 85 | * @since 0.8 | |
| 86 | */ | |
| 87 | Hooks hooks(); | |
| 88 | ||
| 89 | /** | |
| 90 | * Get all issue events for the repository. | |
| 91 | * @return Issue events | |
| 92 | * @see <a href="http://developer.github.com/v3/issues/events/#list-events-for-a-repository">List Events for a Repository</a> | |
| 93 | */ | |
| 94 | IssueEvents issueEvents(); | |
| 95 | ||
| 96 | /** | |
| 97 | * Get all labels of the repo. | |
| 98 | * @return Labels | |
| 99 | * @see <a href="http://developer.github.com/v3/issues/labels/">Labels API</a> | |
| 100 | */ | |
| 101 | Labels labels(); | |
| 102 | ||
| 103 | /** | |
| 104 | * Get all available assignees to which issues may be assigned. | |
| 105 | * @return Assignees | |
| 106 | * @see <a href="http://developer.github.com/v3/issues/assignees/">Assignees API</a> | |
| 107 | */ | |
| 108 | Assignees assignees(); | |
| 109 | ||
| 110 | /** | |
| 111 | * Get all releases of the repo. | |
| 112 | * @return Releases | |
| 113 | * @see <a href="http://developer.github.com/v3/repos/releases/">Releases API</a> | |
| 114 | */ | |
| 115 | Releases releases(); | |
| 116 | ||
| 117 | /** | |
| 118 | * Get all deploy keys of the repo. | |
| 119 | * @return DeployKeys | |
| 120 | * @see <a href="http://developer.github.com/v3/repos/keys/">Deploy Keys API</a> | |
| 121 | */ | |
| 122 | DeployKeys keys(); | |
| 123 | ||
| 124 | /** | |
| 125 | * Get all forks of the repo. | |
| 126 | * @return Forks | |
| 127 | * @see <a href="http://developer.github.com/v3/repos/forks/">Forks API</a> | |
| 128 | */ | |
| 129 | Forks forks(); | |
| 130 | ||
| 131 | /** | |
| 132 | * Get repository's commits. | |
| 133 | * @return Commits | |
| 134 | * @see <a href="http://developer.github.com/v3/repos/commits/">Commits API</a> | |
| 135 | */ | |
| 136 | RepoCommits commits(); | |
| 137 | ||
| 138 | /** | |
| 139 | * Get repository's branches. | |
| 140 | * @return Branches | |
| 141 | * @see <a href="https://developer.github.com/v3/repos/#list-branches">List Branches API</a> | |
| 142 | */ | |
| 143 | Branches branches(); | |
| 144 | ||
| 145 | /** | |
| 146 | * Get all contents of the repo. | |
| 147 | * @return Contents | |
| 148 | * @see <a href="http://developer.github.com/v3/repos/contents/">Contents API</a> | |
| 149 | */ | |
| 150 | Contents contents(); | |
| 151 | ||
| 152 | /** | |
| 153 | * Gel all collaborators. | |
| 154 | * @return Collaborators | |
| 155 | * @see <a href="http://developer.github.com/v3/repos/collaborators/">Collaborators API</a> | |
| 156 | */ | |
| 157 | Collaborators collaborators(); | |
| 158 | ||
| 159 | /** | |
| 160 | * Get the Git API entry point. | |
| 161 | * @return Collaborators | |
| 162 | * @see <a href="http://developer.github.com/v3/git/">Git Data API</a> | |
| 163 | */ | |
| 164 | Git git(); | |
| 165 | ||
| 166 | /** | |
| 167 | * Get Starring API. | |
| 168 | * @return Stars | |
| 169 | * @see <a href="https://developer.github.com/v3/activity/starring/">Starring API</a> | |
| 170 | * @since 0.15 | |
| 171 | */ | |
| 172 | Stars stars(); | |
| 173 | ||
| 174 | /** | |
| 175 | * Get Notifications API. | |
| 176 | * @return Stars | |
| 177 | * @see <a href="https://developer.github.com/v3/activity/notifications/">Notifications API</a> | |
| 178 | * @since 0.15 | |
| 179 | */ | |
| 180 | Notifications notifications(); | |
| 181 | ||
| 182 | /** | |
| 183 | * Get languages for the specified repository. | |
| 184 | * @return Languages | |
| 185 | * @throws IOException If there is any I/O problem | |
| 186 | * @see <a href="https://developer.github.com/v3/repos/#list-languages">List languages</a> | |
| 187 | * @since 0.15 | |
| 188 | */ | |
| 189 | Iterable<Language> languages() throws IOException; | |
| 190 | ||
| 191 | /** | |
| 192 | * Smart Repo with extra features. | |
| 193 | */ | |
| 194 | 0 | @Immutable |
| 195 | 0 | @ToString |
| 196 | @Loggable(Loggable.DEBUG) | |
| 197 | 0 | @EqualsAndHashCode(of = { "repo", "jsn" }) |
| 198 | final class Smart implements Repo { | |
| 199 | /** | |
| 200 | * Encapsulated Repo. | |
| 201 | */ | |
| 202 | private final transient Repo repo; | |
| 203 | /** | |
| 204 | * SmartJson object for convenient JSON parsing. | |
| 205 | */ | |
| 206 | private final transient SmartJson jsn; | |
| 207 | /** | |
| 208 | * Public ctor. | |
| 209 | * @param rep Repo | |
| 210 | */ | |
| 211 | public Smart( | |
| 212 | final Repo rep | |
| 213 | 6 | ) { |
| 214 | 6 | this.repo = rep; |
| 215 | 6 | this.jsn = new SmartJson(rep); |
| 216 | 6 | } |
| 217 | ||
| 218 | /** | |
| 219 | * Does this Repo actually exist in Github? | |
| 220 | * @return True if it exists, false otherwise. | |
| 221 | * @throws IOException If there is any I/O problem. | |
| 222 | */ | |
| 223 | public boolean exists() throws IOException { | |
| 224 | 0 | return new Existence(this.repo).check(); |
| 225 | } | |
| 226 | ||
| 227 | /** | |
| 228 | * Does it have a description. | |
| 229 | * @return TRUE if description is present | |
| 230 | * @throws IOException If there is any I/O problem | |
| 231 | */ | |
| 232 | public boolean hasDescription() throws IOException { | |
| 233 | 0 | return this.jsn.hasNotNull("description"); |
| 234 | } | |
| 235 | /** | |
| 236 | * Get its description. | |
| 237 | * @return Description | |
| 238 | * @throws IOException If there is any I/O problem | |
| 239 | */ | |
| 240 | public String description() throws IOException { | |
| 241 | 6 | return this.jsn.text("description"); |
| 242 | } | |
| 243 | /** | |
| 244 | * Is it private?. | |
| 245 | * @return TRUE if it's private | |
| 246 | * @throws IOException If there is any I/O problem | |
| 247 | */ | |
| 248 | public boolean isPrivate() throws IOException { | |
| 249 | 9 | return Boolean.parseBoolean( |
| 250 | 3 | this.json() |
| 251 | 3 | .getOrDefault("private", JsonValue.FALSE) |
| 252 | 3 | .toString().replace("\"", "") |
| 253 | ); | |
| 254 | } | |
| 255 | @Override | |
| 256 | public Github github() { | |
| 257 | 0 | return this.repo.github(); |
| 258 | } | |
| 259 | @Override | |
| 260 | public Coordinates coordinates() { | |
| 261 | 0 | return this.repo.coordinates(); |
| 262 | } | |
| 263 | @Override | |
| 264 | public Issues issues() { | |
| 265 | 0 | return this.repo.issues(); |
| 266 | } | |
| 267 | @Override | |
| 268 | public Milestones milestones() { | |
| 269 | 0 | return this.repo.milestones(); |
| 270 | } | |
| 271 | @Override | |
| 272 | public Pulls pulls() { | |
| 273 | 0 | return this.repo.pulls(); |
| 274 | } | |
| 275 | ||
| 276 | @Override | |
| 277 | public Hooks hooks() { | |
| 278 | 0 | return this.repo.hooks(); |
| 279 | } | |
| 280 | @Override | |
| 281 | public IssueEvents issueEvents() { | |
| 282 | 0 | return this.repo.issueEvents(); |
| 283 | } | |
| 284 | @Override | |
| 285 | public Labels labels() { | |
| 286 | 0 | return this.repo.labels(); |
| 287 | } | |
| 288 | @Override | |
| 289 | public Assignees assignees() { | |
| 290 | 0 | return this.repo.assignees(); |
| 291 | } | |
| 292 | @Override | |
| 293 | public Releases releases() { | |
| 294 | 0 | return this.repo.releases(); |
| 295 | } | |
| 296 | @Override | |
| 297 | public DeployKeys keys() { | |
| 298 | 0 | return this.repo.keys(); |
| 299 | } | |
| 300 | @Override | |
| 301 | public Forks forks() { | |
| 302 | 0 | return this.repo.forks(); |
| 303 | } | |
| 304 | @Override | |
| 305 | public Contents contents() { | |
| 306 | 0 | return this.repo.contents(); |
| 307 | } | |
| 308 | @Override | |
| 309 | public Collaborators collaborators() { | |
| 310 | 0 | return this.repo.collaborators(); |
| 311 | } | |
| 312 | @Override | |
| 313 | public Git git() { | |
| 314 | 0 | return this.repo.git(); |
| 315 | } | |
| 316 | @Override | |
| 317 | public Stars stars() { | |
| 318 | 0 | return this.repo.stars(); |
| 319 | } | |
| 320 | @Override | |
| 321 | public Notifications notifications() { | |
| 322 | 0 | return this.repo.notifications(); |
| 323 | } | |
| 324 | @Override | |
| 325 | public Iterable<Language> languages() throws IOException { | |
| 326 | 0 | return this.repo.languages(); |
| 327 | } | |
| 328 | @Override | |
| 329 | public void patch( | |
| 330 | final JsonObject json | |
| 331 | ) throws IOException { | |
| 332 | 0 | this.repo.patch(json); |
| 333 | 0 | } |
| 334 | @Override | |
| 335 | public RepoCommits commits() { | |
| 336 | 0 | return this.repo.commits(); |
| 337 | } | |
| 338 | @Override | |
| 339 | public Branches branches() { | |
| 340 | 0 | return this.repo.branches(); |
| 341 | } | |
| 342 | @Override | |
| 343 | public JsonObject json() throws IOException { | |
| 344 | 6 | return this.repo.json(); |
| 345 | } | |
| 346 | ||
| 347 | @Override | |
| 348 | public int compareTo(final Repo repos) { | |
| 349 | 0 | return this.repo.compareTo(repos); |
| 350 | } | |
| 351 | } | |
| 352 | ||
| 353 | } |