diff options
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 72064a4f..b3420ad0 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 fb1420ae..e61961b6 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 00000000..c22219f3 --- /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(); + } +} |