简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM