diff options
author | Kevin Sawicki | 2011-04-11 03:18:00 +0000 |
---|---|---|
committer | Chris Aniszczyk | 2011-04-11 11:22:50 +0000 |
commit | c52d054e54c61e8a22f6ed970e547f5adea3d95b (patch) | |
tree | 029512514e3a4a3410d78307c70e5fd67b7431f9 | |
parent | ad7ca72365ecf4144bb57c25a41a6c2ccc7541f4 (diff) | |
download | egit-github-c52d054e54c61e8a22f6ed970e547f5adea3d95b.tar.gz egit-github-c52d054e54c61e8a22f6ed970e547f5adea3d95b.tar.xz egit-github-c52d054e54c61e8a22f6ed970e547f5adea3d95b.zip |
Add support for getting milestones used in a repository
This will be used in the query dialog to search for
issues that are in a selected milestone.
Change-Id: I54d1e490c554a26bdd7cef9a1b458d00bca443ca
Signed-off-by: Kevin Sawicki <kevin@github.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2 files changed, 72 insertions, 3 deletions
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 d21984b3..1d02cc4a 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 @@ -11,9 +11,7 @@ package org.eclipse.mylyn.github.internal; /** - * GitHub constants. - * - * @author Kevin Sawicki (kevin@github.com) + * GitHub constants */ public interface IGitHubConstants { @@ -38,6 +36,11 @@ public interface IGitHubConstants { String SEGMENT_LABELS = "/labels"; //$NON-NLS-1$ /** + * SEGMENT_MILESTONES + */ + String SEGMENT_MILESTONES = "/milestones"; //$NON-NLS-1$ + + /** * SUFFIX_JSON */ String SUFFIX_JSON = ".json"; //$NON-NLS-1$ diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/MilestoneService.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/MilestoneService.java new file mode 100644 index 00000000..b9149a2b --- /dev/null +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/github/internal/MilestoneService.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * 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 com.google.gson.reflect.TypeToken; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.Assert; + +/** + * Milestone service class for listing the {@link Milestone} objects in use by a + * repository and user accessed via a {@link GitHubClient}. + */ +public class MilestoneService { + + private GitHubClient client; + + /** + * Create milestone service + * + * @param client + * cannot be null + */ + public MilestoneService(GitHubClient client) { + Assert.isNotNull(client, "Client cannot be null"); //$NON-NLS-1$ + this.client = client; + } + + /** + * Get milestones + * + * @param user + * @param repository + * @param state + * @return list of milestones + * @throws IOException + */ + public List<Milestone> getMilestones(String user, String repository, + String state) throws IOException { + StringBuilder uri = new StringBuilder(IGitHubConstants.SEGMENT_REPOS); + uri.append('/').append(user).append('/').append(repository); + uri.append(IGitHubConstants.SEGMENT_MILESTONES).append( + IGitHubConstants.SUFFIX_JSON); + Map<String, String> params = null; + if (state != null) { + params = Collections.singletonMap(IssueService.FILTER_STATE, state); + } + TypeToken<List<Milestone>> milestoneToken = new TypeToken<List<Milestone>>() { + }; + return this.client + .get(uri.toString(), params, milestoneToken.getType()); + } + +} |