Skip to content

Commit c2e8d57

Browse files
committed
Added support for specifying scopes as an array (#338).
1 parent 6db9b9f commit c2e8d57

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/main/java/org/gitlab4j/api/ApplicationsApi.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.gitlab4j.api;
22

3+
import java.util.Arrays;
34
import java.util.List;
45
import java.util.stream.Collectors;
56
import java.util.stream.Stream;
@@ -63,6 +64,24 @@ public Stream<Application> getApplicationsStream() throws GitLabApiException {
6364
return (getApplications(getDefaultPerPage()).stream());
6465
}
6566

67+
/**
68+
* Create an OAUTH Application.
69+
*
70+
* @param name the name for the OAUTH Application
71+
* @param redirectUri the redirect URI for the OAUTH Application
72+
* @param scopes the scopes of the application (api, read_user, sudo, read_repository, openid, profile, email)
73+
* @return the created Application instance
74+
* @throws GitLabApiException if any exception occurs
75+
*/
76+
public Application createApplication(String name, String redirectUri, ApplicationScope[] scopes) throws GitLabApiException {
77+
78+
if (scopes == null || scopes.length == 0) {
79+
throw new GitLabApiException("scopes cannot be null or empty");
80+
}
81+
82+
return (createApplication(name, redirectUri, Arrays.asList(scopes)));
83+
}
84+
6685
/**
6786
* Create an OAUTH Application.
6887
*

src/test/java/org/gitlab4j/api/TestApplications.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import static org.junit.Assert.assertTrue;
2929
import static org.junit.Assume.assumeNotNull;
3030

31-
import java.util.Arrays;
3231
import java.util.List;
3332

3433
import org.gitlab4j.api.Constants.ApplicationScope;
@@ -52,8 +51,8 @@ public class TestApplications extends AbstractIntegrationTest {
5251

5352
private static final String TEST_APPLICATION_NAME = "Test Application for GitLab4J-API";
5453
private static final String TEST_APPLICATION_REDIRECT = "http://example.com/application";
55-
private static final List<ApplicationScope> TEST_APPLICATION_SCOPES =
56-
Arrays.asList(ApplicationScope.SUDO, ApplicationScope.EMAIL);
54+
private static final ApplicationScope[] TEST_APPLICATION_SCOPES =
55+
{ApplicationScope.SUDO, ApplicationScope.EMAIL};
5756

5857
private static GitLabApi gitLabApi;
5958

0 commit comments

Comments
 (0)