View Javadoc
1   /**
2    * Copyright (c) 2013-2023, 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 (yegor256@gmail.com)
43   * @version $Id: 059022e4c3030933a7c8b08b416a88b32297fb28 $
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="https://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="https://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="https://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="https://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="https://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="https://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="https://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="https://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="https://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="https://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      * Get default branch.
193      *
194      * @return Default branch.
195      * @throws IOException If there is any I/O problem.
196      */
197     Branch defaultBranch() throws IOException;
198 
199     /**
200      * Lists the people that have starred the repository.
201      * @return Lists the people that have starred the repository.
202      */
203     Stargazers stargazers();
204 
205     /**
206      * Smart Repo with extra features.
207      */
208     @Immutable
209     @ToString
210     @Loggable(Loggable.DEBUG)
211     @EqualsAndHashCode(of = {"repo", "jsn"})
212     final class Smart implements Repo {
213         /**
214          * Encapsulated Repo.
215          */
216         private final transient Repo repo;
217         /**
218          * SmartJson object for convenient JSON parsing.
219          */
220         private final transient SmartJson jsn;
221 
222         /**
223          * Public ctor.
224          * @param rep Repo
225          */
226         public Smart(
227             final Repo rep
228         ) {
229             this.repo = rep;
230             this.jsn = new SmartJson(rep);
231         }
232 
233         /**
234          * Does this Repo actually exist in Github?
235          * @return True if it exists, false otherwise.
236          * @throws IOException If there is any I/O problem.
237          */
238         public boolean exists() throws IOException {
239             return new Existence(this.repo).check();
240         }
241 
242         /**
243          * Does it have a description.
244          * @return TRUE if description is present
245          * @throws IOException If there is any I/O problem
246          */
247         public boolean hasDescription() throws IOException {
248             return this.jsn.hasNotNull("description");
249         }
250 
251         /**
252          * Get its description.
253          * @return Description
254          * @throws IOException If there is any I/O problem
255          */
256         public String description() throws IOException {
257             return this.jsn.text("description");
258         }
259 
260         /**
261          * Is it private?.
262          * @return TRUE if it's private
263          * @throws IOException If there is any I/O problem
264          */
265         public boolean isPrivate() throws IOException {
266             return Boolean.parseBoolean(
267                 this.json()
268                     .getOrDefault("private", JsonValue.FALSE)
269                     .toString().replace("\"", "")
270             );
271         }
272 
273         @Override
274         public Github github() {
275             return this.repo.github();
276         }
277 
278         @Override
279         public Coordinates coordinates() {
280             return this.repo.coordinates();
281         }
282 
283         @Override
284         public Issues issues() {
285             return this.repo.issues();
286         }
287 
288         @Override
289         public Milestones milestones() {
290             return this.repo.milestones();
291         }
292 
293         @Override
294         public Pulls pulls() {
295             return this.repo.pulls();
296         }
297 
298         @Override
299         public Hooks hooks() {
300             return this.repo.hooks();
301         }
302 
303         @Override
304         public IssueEvents issueEvents() {
305             return this.repo.issueEvents();
306         }
307 
308         @Override
309         public Labels labels() {
310             return this.repo.labels();
311         }
312 
313         @Override
314         public Assignees assignees() {
315             return this.repo.assignees();
316         }
317 
318         @Override
319         public Releases releases() {
320             return this.repo.releases();
321         }
322 
323         @Override
324         public DeployKeys keys() {
325             return this.repo.keys();
326         }
327 
328         @Override
329         public Forks forks() {
330             return this.repo.forks();
331         }
332 
333         @Override
334         public Contents contents() {
335             return this.repo.contents();
336         }
337 
338         @Override
339         public Collaborators collaborators() {
340             return this.repo.collaborators();
341         }
342 
343         @Override
344         public Git git() {
345             return this.repo.git();
346         }
347 
348         @Override
349         public Stars stars() {
350             return this.repo.stars();
351         }
352 
353         @Override
354         public Notifications notifications() {
355             return this.repo.notifications();
356         }
357 
358         @Override
359         public Iterable<Language> languages() throws IOException {
360             return this.repo.languages();
361         }
362 
363         @Override
364         public Branch defaultBranch() throws IOException {
365             return this.repo.defaultBranch();
366         }
367 
368         @Override
369         public Stargazers stargazers() {
370             throw new UnsupportedOperationException(
371                 "stargazers() not yet implemented"
372             );
373         }
374 
375         @Override
376         public void patch(
377             final JsonObject json
378         ) throws IOException {
379             this.repo.patch(json);
380         }
381 
382         @Override
383         public RepoCommits commits() {
384             return this.repo.commits();
385         }
386 
387         @Override
388         public Branches branches() {
389             return this.repo.branches();
390         }
391 
392         @Override
393         public JsonObject json() throws IOException {
394             return this.repo.json();
395         }
396 
397         @Override
398         public int compareTo(final Repo repos) {
399             return this.repo.compareTo(repos);
400         }
401     }
402 
403 }