Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormcmathews2014-11-03 21:33:39 +0000
committerMichael Mathews2015-03-09 23:20:20 +0000
commita4b06eb46a951c821ba69fdec48ec4c5196cb718 (patch)
treec680e210a1bda9445eedd19f885e433ebb0fafaf /org.eclipse.egit.github.core
parenteb83c17e47247e19c41aaba497f4c91d6e2a96c5 (diff)
downloadegit-github-a4b06eb46a951c821ba69fdec48ec4c5196cb718.tar.gz
egit-github-a4b06eb46a951c821ba69fdec48ec4c5196cb718.tar.xz
egit-github-a4b06eb46a951c821ba69fdec48ec4c5196cb718.zip
Implemented the GitHub Team Membership API
Github recently rolled out the Team Membership API, and subsequently deprecated the Team Members API. Currently, using the Team Members API to add a member to a team who is not already part of the org, will result in an error. The changes made are to implement the new Team Memberships API. Bug: 447419 Change-Id: I6773e31113688ac027cf8b061107f54a35ab10ff Signed-off-by: Michael Mathews <mcmathe1@asu.edu>
Diffstat (limited to 'org.eclipse.egit.github.core')
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/TeamMembership.java61
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/IGitHubConstants.java2
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/TeamService.java49
3 files changed, 111 insertions, 1 deletions
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/TeamMembership.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/TeamMembership.java
new file mode 100644
index 00000000..cbc3ad8b
--- /dev/null
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/TeamMembership.java
@@ -0,0 +1,61 @@
+/******************************************************************************
+ * Copyright (c) 2014, 2015 Arizona Board of Regents
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Michael Mathews (Arizona Board of Regents) - (Bug: 447419)
+ * Team Membership API implementation
+ *****************************************************************************/
+package org.eclipse.egit.github.core;
+
+import java.io.Serializable;
+
+/**
+ * Team Membership model class.
+ */
+public class TeamMembership implements Serializable {
+
+ private static final long serialVersionUID = -8207728181588115431L;
+
+ /**
+ * The possible states of a Team Membership
+ */
+ public static enum TeamMembershipState {
+ ACTIVE, PENDING;
+ }
+
+ private TeamMembershipState state;
+
+ private String url;
+
+ /**
+ * @return state
+ */
+ public TeamMembershipState getState() {
+ return state;
+ }
+
+ /**
+ * @param state
+ */
+ public void setState(TeamMembershipState state) {
+ this.state = state;
+ }
+
+ /**
+ * @return url
+ */
+ public String getUrl() {
+ return url;
+ }
+
+ /**
+ * @param url
+ */
+ public void setUrl(String url) {
+ this.url = url;
+ }
+}
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/IGitHubConstants.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/IGitHubConstants.java
index 83dc0206..eb0518b9 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/IGitHubConstants.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/IGitHubConstants.java
@@ -137,6 +137,8 @@ public interface IGitHubConstants {
/** */
String SEGMENT_ORGANIZATIONS = "/organizations"; //$NON-NLS-1$
/** */
+ String SEGMENT_MEMBERSHIPS = "/memberships"; //$NON-NLS-1$
+ /** */
String SEGMENT_ORGS = "/orgs"; //$NON-NLS-1$
/** */
String SEGMENT_PUBLIC = "/public"; //$NON-NLS-1$
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/TeamService.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/TeamService.java
index f015af19..7b439e58 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/TeamService.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/TeamService.java
@@ -1,5 +1,5 @@
/******************************************************************************
- * Copyright (c) 2011 GitHub Inc.
+ * Copyright (c) 2011, 2014 GitHub Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,13 @@
*
* Contributors:
* Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ * Michael Mathews (Arizona Board of Regents) - (Bug: 447419)
+ * Team Membership API implementation
*****************************************************************************/
package org.eclipse.egit.github.core.service;
import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_MEMBERS;
+import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_MEMBERSHIPS;
import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_ORGS;
import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_REPOS;
import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_TEAMS;
@@ -25,6 +28,7 @@ import java.util.Map;
import org.eclipse.egit.github.core.IRepositoryIdProvider;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.Team;
+import org.eclipse.egit.github.core.TeamMembership;
import org.eclipse.egit.github.core.User;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.client.GitHubRequest;
@@ -242,6 +246,49 @@ public class TeamService extends GitHubService {
client.delete(uri.toString());
}
+ public TeamMembership getMembership(int id, String user) throws IOException {
+ if (user == null)
+ throw new IllegalArgumentException("User cannot be null"); //$NON-NLS-1$
+ if (user.length() == 0)
+ throw new IllegalArgumentException("User cannot be empty"); //$NON-NLS-1$
+
+ StringBuilder uri = new StringBuilder(SEGMENT_TEAMS);
+ uri.append('/').append(id);
+ uri.append(SEGMENT_MEMBERSHIPS);
+ uri.append('/').append(user);
+
+ GitHubRequest request = createRequest();
+ request.setUri(uri);
+ request.setType(TeamMembership.class);
+ return (TeamMembership) client.get(request).getBody();
+ }
+
+ public TeamMembership addMembership(int id, String user) throws IOException {
+ if (user == null)
+ throw new IllegalArgumentException("User cannot be null"); //$NON-NLS-1$
+ if (user.length() == 0)
+ throw new IllegalArgumentException("User cannot be empty"); //$NON-NLS-1$
+
+ StringBuilder uri = new StringBuilder(SEGMENT_TEAMS);
+ uri.append('/').append(id);
+ uri.append(SEGMENT_MEMBERSHIPS);
+ uri.append('/').append(user);
+ return client.put(uri.toString(), null, TeamMembership.class);
+ }
+
+ public void removeMembership(int id, String user) throws IOException {
+ if (user == null)
+ throw new IllegalArgumentException("User cannot be null"); //$NON-NLS-1$
+ if (user.length() == 0)
+ throw new IllegalArgumentException("User cannot be empty"); //$NON-NLS-1$
+
+ StringBuilder uri = new StringBuilder(SEGMENT_TEAMS);
+ uri.append('/').append(id);
+ uri.append(SEGMENT_MEMBERSHIPS);
+ uri.append('/').append(user);
+ client.delete(uri.toString());
+ }
+
/**
* Get all repositories for given team
*

Back to the top