Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn2015-12-15 00:35:40 +0000
committerMatthias Sohn2015-12-15 00:35:48 +0000
commit837a3ca8952d9ce8f91eb005823ba40f124065e6 (patch)
tree72a248bd270f32f35f5037fa0964a4775d7a3e45
parentcdccdbac94ef2ea3bdb8a319a47504b45aa605db (diff)
parentfbe6fc5d13d51fddf8c6bc504559932fb7dfecca (diff)
downloadegit-github-837a3ca8952d9ce8f91eb005823ba40f124065e6.tar.gz
egit-github-837a3ca8952d9ce8f91eb005823ba40f124065e6.tar.xz
egit-github-837a3ca8952d9ce8f91eb005823ba40f124065e6.zip
Merge branch 'master' into stable-4.2
Change-Id: I2afa3daa289e85b1667a18886fc3310e38dcd0b3 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/OrganizationServiceTest.java42
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java17
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java21
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/OrganizationService.java34
4 files changed, 112 insertions, 2 deletions
diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/OrganizationServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/OrganizationServiceTest.java
index 2d9ec924..a745bb69 100644
--- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/OrganizationServiceTest.java
+++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/OrganizationServiceTest.java
@@ -16,12 +16,14 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
import java.io.IOException;
+import java.util.HashMap;
import org.eclipse.egit.github.core.User;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.client.GitHubRequest;
import org.eclipse.egit.github.core.client.GitHubResponse;
import org.eclipse.egit.github.core.service.OrganizationService;
+import org.eclipse.egit.github.core.service.OrganizationService.RoleFilter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -216,6 +218,46 @@ public class OrganizationServiceTest {
}
/**
+ * Get members with role filter "all"
+ *
+ * @throws IOException
+ */
+ @Test
+ public void getMembersAll() throws IOException {
+ testMembersByRole(RoleFilter.all);
+ }
+
+ /**
+ * Get members with role filter "all"
+ *
+ * @throws IOException
+ */
+ @Test
+ public void getMembersAdmin() throws IOException {
+ testMembersByRole(RoleFilter.admin);
+ }
+
+ /**
+ * Get members with role filter "all"
+ *
+ * @throws IOException
+ */
+ @Test
+ public void getMembersMember() throws IOException {
+ testMembersByRole(RoleFilter.member);
+ }
+
+ private void testMembersByRole(RoleFilter roleFilter) throws IOException {
+ service.getMembers("group", roleFilter);
+ HashMap<String, String> params = new HashMap<String, String>();
+ params.put("role", roleFilter.toString());
+ GitHubRequest request = new GitHubRequest();
+ request.setParams(params);
+ request.setUri(Utils.page("/orgs/group/members?role=" + roleFilter.toString()));
+ verify(client).get(request);
+ }
+
+ /**
* Get public members with null name
*
* @throws IOException
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java
index 6fdd5274..1a1285a0 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java
@@ -234,7 +234,20 @@ public class GitHubClient {
else
headerAccept = ACCEPT_FULL;
return this;
- }
+ }
+
+ /**
+ * Returns the accept header currently used for all requests.
+ *
+ * @return header
+ * @since 4.2
+ */
+ public String getHeaderAccept() {
+ if (headerAccept != null && headerAccept.length() > 0)
+ return headerAccept;
+ else
+ return ACCEPT_FULL;
+ }
/**
* Configure request with standard headers
@@ -246,7 +259,7 @@ public class GitHubClient {
if (credentials != null)
request.setRequestProperty(HEADER_AUTHORIZATION, credentials);
request.setRequestProperty(HEADER_USER_AGENT, userAgent);
- request.setRequestProperty(HEADER_ACCEPT, headerAccept);
+ request.setRequestProperty(HEADER_ACCEPT, getHeaderAccept());
return request;
}
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java
index ed2bd637..25fc3abe 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/GitHubService.java
@@ -52,6 +52,27 @@ public abstract class GitHubService {
public static final String ACCEPT_FULL = "application/vnd.github.v3.full+json"; //$NON-NLS-1$
/**
+ * Accept header to use preview features of the 'ironman' release.
+ * @see <a href="https://developer.github.com/changes">https://developer.github.com/changes</a>
+ * @since 4.2
+ */
+ public static final String ACCEPT_PREVIEW_IRONMAN = "application/vnd.github.ironman-preview+json"; //$NON-NLS-1$
+
+ /**
+ * Accept header to use preview features of the 'loki' release.
+ * @see <a href="https://developer.github.com/changes">https://developer.github.com/changes</a>
+ * @since 4.2
+ */
+ public static final String ACCEPT_PREVIEW_LOKI = "application/vnd.github.loki-preview+json"; //$NON-NLS-1$
+
+ /**
+ * Accept header to use preview features of the 'drax' release.
+ * @see <a href="https://developer.github.com/changes">https://developer.github.com/changes</a>
+ * @since 4.2
+ */
+ public static final String ACCEPT_PREVIEW_DRAX = "application/vnd.github.drax-preview+json"; //$NON-NLS-1$
+
+ /**
* Client field
*/
protected final GitHubClient client;
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/OrganizationService.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/OrganizationService.java
index 11b6f86b..7a0235d2 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/OrganizationService.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/OrganizationService.java
@@ -21,6 +21,7 @@ import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_SIZE;
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
+import java.util.HashMap;
import java.util.List;
import org.eclipse.egit.github.core.User;
@@ -39,6 +40,14 @@ import org.eclipse.egit.github.core.client.PagedRequest;
public class OrganizationService extends GitHubService {
/**
+ * Filter for roles a member can have
+ * @since 4.2
+ */
+ public static enum RoleFilter {
+ all, admin, member
+ }
+
+ /**
* Create organization service
*/
public OrganizationService() {
@@ -156,19 +165,44 @@ public class OrganizationService extends GitHubService {
* Get members of organization
*
* @param organization
+ * the name of the organization
* @return list of all organization members
* @throws IOException
*/
public List<User> getMembers(String organization) throws IOException {
+ return getMembers(organization, null);
+ }
+
+ /**
+ * Get members of organization
+ *
+ * @param organization
+ * the name of the organization
+ * @param roleFilter
+ * only return members matching the {@link RoleFilter}<br>
+ * To use this feature it is currently required to set the
+ * {@link org.eclipse.egit.github.core.service.GitHubService#ACCEPT_PREVIEW_IRONMAN
+ * application/vnd.github.ironman-preview+json} Accept header in the
+ * {@link GitHubClient#setHeaderAccept GitHubClient}
+ * @return list of all organization members whose role matches the {@code roleFilter}
+ * @throws IOException
+ * @since 4.2
+ */
+ public List<User> getMembers(String organization, RoleFilter roleFilter) throws IOException
+ {
if (organization == null)
throw new IllegalArgumentException("Organization cannot be null"); //$NON-NLS-1$
if (organization.length() == 0)
throw new IllegalArgumentException("Organization cannot be empty"); //$NON-NLS-1$
+ HashMap<String, String> params = new HashMap<String, String>();
+ if(roleFilter != null) params.put("role", roleFilter.toString());
+
StringBuilder uri = new StringBuilder(SEGMENT_ORGS);
uri.append('/').append(organization);
uri.append(SEGMENT_MEMBERS);
PagedRequest<User> request = createPagedRequest();
+ request.setParams(params);
request.setUri(uri);
request.setType(new TypeToken<List<User>>() {
}.getType());

Back to the top