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  
31  package com.jcabi.github;
32  
33  import com.jcabi.aspects.Immutable;
34  import java.io.IOException;
35  
36  /**
37   * Github repository collaborators.
38   * @author Aleksey Popov (alopen@yandex.ru)
39   * @version $Id: 4fa67ddce019fd22e37f9b201af4356c29d9c739 $
40   * @since 0.8
41   */
42  @Immutable
43  public interface Collaborators {
44      /**
45       * Permission levels a user can be granted in an organization repository.
46       *
47       * @see <a href="https://developer.github.com/v3/repos/collaborators/#parameters-1">Add user with permissions</a>
48       */
49      enum Permission { PULL, PUSH, ADMIN, MAINTAIN, TRIAGE };
50  
51      /**
52       * Owner of them.
53       * @return Repo
54       */
55      Repo repo();
56  
57      /**
58       * Check if a user is collaborator.
59       *
60       * @param user User
61       * @return True is a user is a collaborator, otherwise returns false
62       * @throws IOException If there is any I/O problem
63       * @see <a href="https://developer.github.com/v3/repos/collaborators/#get">
64       *  Check if a user is collaborator</a>
65       */
66      boolean isCollaborator(String user) throws IOException;
67  
68      /**
69       * Add user as a collaborator.
70       *
71       * @param user User
72       * @throws IOException If there is any I/O problem
73       * @see <a href="https://developer.github.com/v3/repos/collaborators/#add-collaborator">Add user as a collaborator</a>
74       */
75      void add(String user) throws IOException;
76  
77      /**
78       * Add user with permissions. Only works on an organization repository
79       *
80       * @param user User to add
81       * @param permission Permission level to grant
82       * @throws IOException if there is an I/O problem
83       * @see <a href=https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator">Add user as a collaborator</a>
84       */
85      void addWithPermission(String user,
86          Collaborators.Permission permission) throws IOException;
87  
88      /**
89       * Get user permission in this repo.
90       *
91       * @param user User to check
92       * @return Permission level granted, incl. "admin", "write",
93       *  "read", or "none"
94       * @throws IOException if there is an I/O problem
95       * @see <a href=https://docs.github.com/en/rest/collaborators/collaborators#get-repository-permissions-for-a-user">Get repository permissions for a user</a>
96       */
97      String permission(String user) throws IOException;
98  
99      /**
100      * Remove user as a collaborator.
101      *
102      * @param user User
103      * @throws IOException If there is any I/O problem
104      * @see <a href="https://developer.github.com/v3/repos/collaborators/#remove-collaborator">Remove user as a collaborator</a>
105      */
106     void remove(String user) throws IOException;
107 
108     /**
109      * Iterates over repo collaborators.
110      * @return Iterator on repo collaborators.
111      */
112     Iterable<User> iterate();
113 }