aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-27 16:23:16 (EDT)
committerKevin Sawicki2011-04-27 16:23:16 (EDT)
commit87d89f6f25da8df735adab7515bc30a07a3dacd3 (patch)
tree03fa7fd63f8cd367c6bb9484ae92b380f809a76c
parentbf6eea85ba768c9951ff84767bb071a1c820dba5 (diff)
downloadegit-github-87d89f6f25da8df735adab7515bc30a07a3dacd3.zip
egit-github-87d89f6f25da8df735adab7515bc30a07a3dacd3.tar.gz
egit-github-87d89f6f25da8df735adab7515bc30a07a3dacd3.tar.bz2
Add pull request service.refs/changes/71/3271/1
Supports requesting a single pull request from a repository or all the pull requests of a certain state. Change-Id: Iae38efb99bb113ab956612e98f8d61466d7bd74c Signed-off-by: Kevin Sawicki <kevin@github.com>
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/DateFormatter.java2
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java10
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PullRequestService.java103
3 files changed, 115 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/DateFormatter.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/DateFormatter.java
index 72064a4..b3420ad 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/DateFormatter.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/DateFormatter.java
@@ -41,6 +41,8 @@ public class DateFormatter implements JsonDeserializer<Date> {
this.formats.add(new SimpleDateFormat(IGitHubConstants.DATE_FORMAT));
this.formats
.add(new SimpleDateFormat(IGitHubConstants.DATE_FORMAT_V2_1));
+ this.formats
+ .add(new SimpleDateFormat(IGitHubConstants.DATE_FORMAT_V2_2));
TimeZone timeZone = TimeZone.getTimeZone("Zulu"); //$NON-NLS-1$
for (DateFormat format : this.formats)
format.setTimeZone(timeZone);
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java
index fb1420a..e61961b 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/IGitHubConstants.java
@@ -61,6 +61,11 @@ public interface IGitHubConstants {
String SEGMENT_GISTS = "/gists"; //$NON-NLS-1$
/**
+ * SEGMENT_PULLS
+ */
+ String SEGMENT_PULLS = "/pulls"; //$NON-NLS-1$
+
+ /**
* SEGMENT_USERS
*/
String SEGMENT_USERS = "/users"; //$NON-NLS-1$
@@ -101,6 +106,11 @@ public interface IGitHubConstants {
String DATE_FORMAT_V2_1 = "yyyy/MM/dd HH:mm:ss Z"; //$NON-NLS-N$
/**
+ * DATE_FORMAT_V2_2
+ */
+ String DATE_FORMAT_V2_2 = "yyyy-MM-dd'T'HH:mm:ss"; //$NON-NLS-1$
+
+ /**
* CONTENT_TYPE_JSON
*/
String CONTENT_TYPE_JSON = "application/json"; //$NON-NLS-1$
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PullRequestService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PullRequestService.java
new file mode 100644
index 0000000..c22219f
--- /dev/null
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/PullRequestService.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * 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:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.github.internal;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+
+/**
+ * @author Kevin Sawicki (kevin@github.com)
+ */
+public class PullRequestService {
+
+ /**
+ * Pull request wrapper
+ */
+ private static class PullRequestWrapper {
+
+ private PullRequest pull;
+
+ public PullRequest getPull() {
+ return this.pull;
+ }
+
+ }
+
+ /**
+ * Pull requests wrapper
+ */
+ private static class PullRequestsWrapper {
+
+ private List<PullRequest> pulls;
+
+ public List<PullRequest> getPulls() {
+ return this.pulls;
+ }
+
+ }
+
+ private GitHubClient client;
+
+ /**
+ * Create pull request service
+ *
+ * @param client
+ * cannot be null
+ */
+ public PullRequestService(GitHubClient client) {
+ Assert.isNotNull(client, "Client cannot be null"); //$NON-NLS-1$
+ this.client = client;
+ }
+
+ /**
+ * Get pull request from repository with id
+ *
+ * @param repository
+ * @param id
+ * @return pull request
+ * @throws IOException
+ */
+ public PullRequest getPullRequest(Repository repository, String id)
+ throws IOException {
+ Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$
+ Assert.isNotNull(id, "Id cannot be null"); //$NON-NLS-1$
+ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_V2_API);
+ uri.append(IGitHubConstants.SEGMENT_PULLS);
+ uri.append('/').append(repository.getId());
+ uri.append('/').append(id);
+ PullRequestWrapper wrapper = this.client.get(uri.toString(),
+ PullRequestWrapper.class);
+ return wrapper.getPull();
+ }
+
+ /**
+ * Get pull requests from repository matching state
+ *
+ * @param repository
+ * @param state
+ * @return list of pull requests
+ * @throws IOException
+ */
+ public List<PullRequest> getPullRequests(Repository repository, String state)
+ throws IOException {
+ Assert.isNotNull(repository, "Repository cannot be null"); //$NON-NLS-1$
+ Assert.isNotNull(state, "State cannot be null"); //$NON-NLS-1$
+ StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_V2_API);
+ uri.append(IGitHubConstants.SEGMENT_PULLS);
+ uri.append('/').append(repository.getId());
+ uri.append('/').append(state);
+ PullRequestsWrapper wrapper = this.client.get(uri.toString(),
+ PullRequestsWrapper.class);
+ return wrapper.getPulls();
+ }
+}