Ejemplo n.º 1
0
 @Override
 public void doLoadInBackground(HashMap<Integer, Object> result) throws IOException {
   Gh4Application app = (Gh4Application) getContext().getApplicationContext();
   GitHubClient client = new DefaultClient();
   client.setOAuth2Token(app.getAuthToken());
   IssueService issueService = new IssueService(client);
   result.put(LoaderResult.DATA, issueService.getComments(mRepoOwner, mRepoName, mIssueNumber));
 }
  @Override
  public IStatus performQuery(
      TaskRepository repository,
      IRepositoryQuery query,
      TaskDataCollector collector,
      ISynchronizationSession session,
      IProgressMonitor monitor) {
    IStatus result = Status.OK_STATUS;
    List<String> statuses = QueryUtils.getAttributes(IssueService.FILTER_STATE, query);

    monitor.beginTask(Messages.PullRequestConnector_TaskFetching, statuses.size());
    try {
      RepositoryId repo = getRepository(repository.getRepositoryUrl());

      GitHubClient client = IssueConnector.createClient(repository);
      PullRequestService service = new PullRequestService(client);
      IssueService commentService = new IssueService(client);

      for (String status : statuses) {
        List<PullRequest> pulls = service.getPullRequests(repo, status);

        // collect task data
        for (PullRequest pr : pulls) {
          pr = service.getPullRequest(repo, pr.getNumber());
          PullRequestComposite prComp = new PullRequestComposite();
          prComp.setRequest(pr);
          List<Comment> comments = null;
          if (pr.getComments() > 0)
            comments =
                commentService.getComments(
                    repo.getOwner(), repo.getName(), Integer.toString(pr.getNumber()));
          if (pr.getCommits() > 0) prComp.setCommits(service.getCommits(repo, pr.getNumber()));
          TaskData taskData =
              taskDataHandler.createTaskData(repository, monitor, repo, prComp, comments);
          collector.accept(taskData);
        }
        monitor.worked(1);
      }
    } catch (IOException e) {
      result = GitHub.createWrappedStatus(e);
    }

    monitor.done();
    return result;
  }
  @Override
  public TaskData getTaskData(TaskRepository repository, String taskId, IProgressMonitor monitor)
      throws CoreException {
    RepositoryId repo = getRepository(repository.getRepositoryUrl());

    try {
      GitHubClient client = IssueConnector.createClient(repository);
      PullRequestService service = new PullRequestService(client);
      PullRequest pr = service.getPullRequest(repo, Integer.parseInt(taskId));
      PullRequestComposite prComp = new PullRequestComposite();
      prComp.setRequest(pr);
      IssueService commentService = new IssueService(client);
      List<Comment> comments = null;
      if (pr.getComments() > 0)
        comments = commentService.getComments(repo.getOwner(), repo.getName(), taskId);
      if (pr.getCommits() > 0) prComp.setCommits(service.getCommits(repo, pr.getNumber()));
      return taskDataHandler.createTaskData(repository, monitor, repo, prComp, comments);
    } catch (IOException e) {
      throw new CoreException(GitHub.createWrappedStatus(e));
    }
  }