我想获得Java客户端在Github中的所有问题,以获取确切的里程碑。我尝试过:
public void listClosedIssuesInMilestone(String host, String token, String repository_name, String milestone_name) throws IOException
{
GitHubClient client = new GitHubClient(host);
client.setOAuth2Token(token);
RepositoryService service = new RepositoryService(client);
List<Repository> repositories = service.getRepositories();
MilestoneService milestones = new MilestoneService(client);
for (int z = 0; z < repositories.size(); z++)
{
Repository repository = repositories.get(z);
if (repository.getName().equals(repository_name)) {
List<Milestone> closedMilestones = milestones.getMilestones(repository, "closed");
for (int i = 0; i < closedMilestones.size(); i++)
{
Milestone milestone = closedMilestones.get(i);
if (milestone.getTitle().equals(milestone_name)) {
// TODO get closed issues here
}
}
}
}
}
但是我找不到实现此目的的方法。我无法使问题清单具有里程碑意义。你能建议我怎么做吗?
答案 0 :(得分:2)
使用IssueService
。抱歉,我没有要测试的项目。如果将名称直接传递到里程碑不起作用,则可能需要按名称获取MileStoneService
并将数字传递到里程碑过滤器。
类似
RepositoryService service = new RepositoryService(client);
List<Repository> repositories = service.getRepositories();
Repository repository = null;
// Get the repository matching name
for(Repository repo:repositories) {
if(repo.getName().equals(repository_name)) {
repository = repo;
break;
}
}
List<Issue> issues = new ArrayList<>();
// Get issues in repository
if(repository != null) {
IssueService issueService = new IssueService(client);
Map<String,String> filters = new HashMap<>();
filters.put(IssueService.FILTER_STATE,IssueService.STATE_CLOSED);
filters.put(IssueService.FILTER_MILESTONE,milestone_name);
issues = issueService.getIssues(repository,filters);
}