@Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.m_edit:
       if (issue != null)
         startActivityForResult(
             EditIssueActivity.createIntent(
                 issue, repositoryId.getOwner(), repositoryId.getName(), user),
             ISSUE_EDIT);
       return true;
     case R.id.m_comment:
       if (issue != null)
         startActivityForResult(
             CreateCommentActivity.createIntent(repositoryId, issueNumber, user), COMMENT_CREATE);
       return true;
     case R.id.m_refresh:
       refreshIssue();
       return true;
     case R.id.m_share:
       if (issue != null) shareIssue();
       return true;
     case R.id.m_state:
       if (issue != null) stateTask.confirm(STATE_OPEN.equals(issue.getState()));
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
  @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));
    }
  }
Exemplo n.º 4
0
 /**
  * Add repository id to intent being built up
  *
  * @param repositoryId
  * @return this builder
  */
 public Builder repo(RepositoryId repositoryId) {
   return add(EXTRA_REPOSITORY_NAME, repositoryId.getName())
       .add(EXTRA_REPOSITORY_OWNER, repositoryId.getOwner());
 }
 private String getFileName() {
   return PATH + "/" + repoInfo.getOwner() + "/" + repoInfo.getName();
 }