|
39 | 39 |
|
40 | 40 | import org.gitlab4j.api.GitLabApi.ApiVersion; |
41 | 41 | import org.gitlab4j.api.models.AccessLevel; |
| 42 | +import org.gitlab4j.api.models.AccessRequest; |
42 | 43 | import org.gitlab4j.api.models.Event; |
43 | 44 | import org.gitlab4j.api.models.FileUpload; |
44 | 45 | import org.gitlab4j.api.models.Issue; |
|
56 | 57 | * This class provides an entry point to all the GitLab API project calls. |
57 | 58 | * @see <a href="https://docs.gitlab.com/ce/api/projects.html">Projects API at GitLab</a> |
58 | 59 | * @see <a href="https://docs.gitlab.com/ee/api/members.html">Group and project members API at GitLab</a> |
| 60 | + * @see <a href="https://docs.gitlab.com/ee/api/access_requests.html#group-and-project-access-requests-api">Group and project access requests API</a> |
59 | 61 | */ |
60 | 62 | public class ProjectApi extends AbstractApi implements Constants { |
61 | 63 |
|
@@ -2681,4 +2683,90 @@ public Variable updateVariable(Object projectIdOrPath, String key, String value, |
2681 | 2683 | public void deleteVariable(Object projectIdOrPath, String key) throws GitLabApiException { |
2682 | 2684 | delete(Response.Status.NO_CONTENT, null, "projects", getProjectIdOrPath(projectIdOrPath), "variables", key); |
2683 | 2685 | } |
| 2686 | + |
| 2687 | + /** |
| 2688 | + * Get a List of the project access requests viewable by the authenticated user. |
| 2689 | + * |
| 2690 | + * <pre><code>GET /projects/:id/access_requests</code></pre> |
| 2691 | + * |
| 2692 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 2693 | + * @return a List of project AccessRequest instances accessible by the authenticated user |
| 2694 | + * @throws GitLabApiException if any exception occurs |
| 2695 | + */ |
| 2696 | + public List<AccessRequest> getAccessRequests(Object projectIdOrPath) throws GitLabApiException { |
| 2697 | + return (getAccessRequests(projectIdOrPath, getDefaultPerPage()).all()); |
| 2698 | + } |
| 2699 | + |
| 2700 | + /** |
| 2701 | + * Get a Pager of the project access requests viewable by the authenticated user. |
| 2702 | + * |
| 2703 | + * <pre><code>GET /projects/:id/access_requests</code></pre> |
| 2704 | + * |
| 2705 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 2706 | + * @param itemsPerPage the number of AccessRequest instances that will be fetched per page |
| 2707 | + * @return a Pager of project AccessRequest instances accessible by the authenticated user |
| 2708 | + * @throws GitLabApiException if any exception occurs |
| 2709 | + */ |
| 2710 | + public Pager<AccessRequest> getAccessRequests(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException { |
| 2711 | + return (new Pager<AccessRequest>(this, AccessRequest.class, itemsPerPage, null, "projects", getProjectIdOrPath(projectIdOrPath), "access_requests")); |
| 2712 | + } |
| 2713 | + |
| 2714 | + /** |
| 2715 | + * Get a Stream of the project access requests viewable by the authenticated user. |
| 2716 | + * |
| 2717 | + * <pre><code>GET /projects/:id/access_requests</code></pre> |
| 2718 | + * |
| 2719 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 2720 | + * @return a Stream of project AccessRequest instances accessible by the authenticated user |
| 2721 | + * @throws GitLabApiException if any exception occurs |
| 2722 | + */ |
| 2723 | + public Stream<AccessRequest> getAccessRequestsStream(Object projectIdOrPath) throws GitLabApiException { |
| 2724 | + return (getAccessRequests(projectIdOrPath, getDefaultPerPage()).stream()); |
| 2725 | + } |
| 2726 | + |
| 2727 | + /** |
| 2728 | + * Requests access for the authenticated user to the specified project. |
| 2729 | + * |
| 2730 | + * <pre><code>POST /projects/:id/access_requests</code></pre> |
| 2731 | + * |
| 2732 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 2733 | + * @return the created AccessRequest instance |
| 2734 | + * @throws GitLabApiException if any exception occurs |
| 2735 | + */ |
| 2736 | + public AccessRequest requestAccess(Object projectIdOrPath) throws GitLabApiException { |
| 2737 | + Response response = post(Response.Status.CREATED, (Form)null, "projects", getProjectIdOrPath(projectIdOrPath), "access_requests"); |
| 2738 | + return (response.readEntity(AccessRequest.class)); |
| 2739 | + } |
| 2740 | + |
| 2741 | + /** |
| 2742 | + * Approve access for the specified user to the specified project. |
| 2743 | + * |
| 2744 | + * <pre><code>PUT /projects/:id/access_requests/:user_id/approve</code></pre> |
| 2745 | + * |
| 2746 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 2747 | + * @param userId the user ID to approve access for |
| 2748 | + * @param accessLevel the access level the user is approved for, if null will be developer (30) |
| 2749 | + * @return the approved AccessRequest instance |
| 2750 | + * @throws GitLabApiException if any exception occurs |
| 2751 | + */ |
| 2752 | + public AccessRequest approveAccessRequest(Object projectIdOrPath, Integer userId, AccessLevel accessLevel) throws GitLabApiException { |
| 2753 | + GitLabApiForm formData = new GitLabApiForm().withParam("access_level", accessLevel); |
| 2754 | + Response response = this.putWithFormData(Response.Status.CREATED, formData, |
| 2755 | + "projects", getProjectIdOrPath(projectIdOrPath), "access_requests", userId, "approve"); |
| 2756 | + return (response.readEntity(AccessRequest.class)); |
| 2757 | + } |
| 2758 | + |
| 2759 | + /** |
| 2760 | + * Deny access for the specified user to the specified project. |
| 2761 | + * |
| 2762 | + * <pre><code>DELETE /projects/:id/access_requests/:user_id</code></pre> |
| 2763 | + * |
| 2764 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 2765 | + * @param userId the user ID to deny access for |
| 2766 | + * @throws GitLabApiException if any exception occurs |
| 2767 | + */ |
| 2768 | + public void denyAccessRequest(Object projectIdOrPath, Integer userId) throws GitLabApiException { |
| 2769 | + delete(Response.Status.NO_CONTENT, null, |
| 2770 | + "projects", getProjectIdOrPath(projectIdOrPath), "access_requests", userId); |
| 2771 | + } |
2684 | 2772 | } |
0 commit comments