Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Link2015-12-02 08:06:01 +0000
committerAlexander Link2015-12-02 08:25:38 +0000
commitfbe6fc5d13d51fddf8c6bc504559932fb7dfecca (patch)
tree72a248bd270f32f35f5037fa0964a4775d7a3e45 /org.eclipse.egit.github.core
parente8c4ad3431b99f086f8ea1d8253ccd0323b9c7ba (diff)
downloadegit-github-fbe6fc5d13d51fddf8c6bc504559932fb7dfecca.tar.gz
egit-github-fbe6fc5d13d51fddf8c6bc504559932fb7dfecca.tar.xz
egit-github-fbe6fc5d13d51fddf8c6bc504559932fb7dfecca.zip
Enable getting owners of an organization
Until now the egit API did not provide a way to get the Organization owners. Using the GitHub API route /orgs/:org/members?role=<role> with "role" filter it is possible to get all members with a specific role. See https://developer.github.com/v3/orgs/members/#members-list for more information. Change-Id: Ida0bef8335f8d09b5650d3c26d960c0964e8a362 Signed-off-by: Alexander Link <Alexander.Link@sap.com>
Diffstat (limited to 'org.eclipse.egit.github.core')
-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
3 files changed, 70 insertions, 2 deletions
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