Peter Penzov
Peter Penzov

Reputation: 1678

Get all issues in Github Milestone

I want to get all issues in Github with Java client for exact Milestone. I tried this:

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
                    }
                }

            }              
        }
    }    

But I can't find a way to implement this. I can't get the list of issues into milestone. Can you advice how I can do this?

Upvotes: 2

Views: 291

Answers (1)

s7vr
s7vr

Reputation: 75924

Use IssueService. Sorry I don't have any project set up to test. If passing the name directly to milestone doesn't work you may need to get MileStoneService by name and pass the number to the milestone filter.

Something like

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);
}

Upvotes: 2

Related Questions