2

我想用 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
                    }
                }

            }              
        }
    }    

但我找不到实现这一点的方法。我无法将问题列表纳入里程碑。你能建议我怎么做吗?

4

1 回答 1

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);
}
于 2018-08-30T01:03:44.600 回答