@Override
    public void actionPerformed(ActionEvent e) {
      final GitHubIssuePanel p = getPanel();
      p.setNewCommentEnabled(false);

      GitHubIssues gitHubIssues = GitHubIssues.getInstance();
      RequestProcessor rp = gitHubIssues.getRequestProcessor();
      rp.post(
          new Runnable() {
            @Override
            public void run() {
              try {
                String comment = p.getNewComment();
                if (StringUtils.isEmpty(comment)) {
                  closeReopen();
                } else {
                  Comment newComment = comment(comment);
                  if (newComment != null) {
                    closeReopen();
                  }
                }

                SwingUtilities.invokeLater(
                    new Runnable() {
                      @Override
                      public void run() {
                        p.update();
                      }
                    });
              } finally {
                p.setNewCommentEnabled(true);
              }
            }
          });
    }
 @NbBundle.Messages({
   "CommentAction.message.comment.added=Comment has been added",
   "CommentAction.message.comment.added.fail=Comment has not been added."
 })
 protected Comment comment(String comment) {
   GitHubIssuePanel p = getPanel();
   if (StringUtils.isEmpty(comment)) {
     return null;
   }
   Comment newComment = GitHubIssueSupport.comment(p.getIssue(), comment);
   if (newComment != null) {
     p.setNewComment(""); // NOI18N
     StatusDisplayer.getDefault().setStatusText(Bundle.CommentAction_message_comment_added());
   } else {
     UiUtils.showErrorDialog(Bundle.CommentAction_message_comment_added_fail());
   }
   return newComment;
 }
 private CreateIssueParams getCreateIssueParams(boolean isNew, GitHubIssuePanel p) {
   User assignee = p.getAssignee();
   if (!isNew && assignee == null) {
     assignee = new User();
     assignee.setLogin(""); // NOI18N
   }
   Milestone milestone = p.getMilestone();
   if (milestone == null) {
     milestone = new Milestone();
   }
   CreateIssueParams createIssueParams =
       new CreateIssueParams(p.getTitle())
           .body(p.getDescription())
           .milestone(milestone)
           .labels(p.getLabels());
   if (assignee != null) {
     createIssueParams = createIssueParams.assignee(assignee);
   }
   return createIssueParams;
 }
 private GitHubIssuePanel getPanel() {
   if (panel == null) {
     panel = new GitHubIssuePanel(repositoryId);
     panel.addChangeListener(this);
     panel.addAction(getSubmitIssueAction());
     panel.addAction(getCommentAction());
     panel.addAction(getCloseReopenAction());
     panel.addAction(getCreatePullRequestAction());
     panel.addCommentsChangeListener(this);
   }
   return panel;
 }
    @Override
    public void actionPerformed(ActionEvent e) {
      String actionCommand = e.getActionCommand();
      final boolean isNewPullRequest = actionCommand.equals("New PR"); // NOI18N
      GitHubIssuePanel p = getPanel();
      p.setCreatePullRequestButtonEnabled(false);
      final GitHubIssue issue = p.getIssue();

      if (isNewPullRequest && !p.isNewPullRequestSelected()) {
        // remove the new pull request from the panle
        SwingUtilities.invokeLater(
            new Runnable() {
              @Override
              public void run() {
                getPanel().setNewPullRequest(null);
              }
            });
        return;
      }

      RequestProcessor rp = GitHubIssues.getInstance().getRequestProcessor();
      rp.post(
          new Runnable() {
            @Override
            public void run() {
              final GitHubRepository repository = issue.getRepository();
              GitHubCache cache = GitHubCache.create(repository);
              final User mySelf = cache.getMySelf();

              List<RepositoryBranch> baseBranches = cache.getBranches(true);
              final HashMap<Repository, List<RepositoryBranch>> baseRepositories = new HashMap<>();
              baseRepositories.put(repository.getRepository(), baseBranches);
              final Map<Repository, List<RepositoryBranch>> headRepositories =
                  getHeadRepositories(repository, baseBranches);

              SwingUtilities.invokeLater(
                  new Runnable() {
                    @Override
                    public void run() {
                      try {
                        if (baseRepositories.isEmpty() || headRepositories.isEmpty()) {
                          UiUtils.showErrorDialog(
                              Bundle
                                  .CreatePullRequestAction_error_message_cannot_find_base_head_repositories());
                          return;
                        }

                        // create descriptor
                        final CreatePullRequestPanel createPullRequestPanel =
                            new CreatePullRequestPanel(baseRepositories, headRepositories);
                        createPullRequestPanel.setMessage(
                            Bundle.CreatePullRequestAction_confirmation_message());
                        final NotifyDescriptor.Confirmation descriptor =
                            new NotifyDescriptor.Confirmation(
                                createPullRequestPanel,
                                Bundle.CreatePullRequestAction_descriptor_title(),
                                NotifyDescriptor.OK_CANCEL_OPTION,
                                NotifyDescriptor.QUESTION_MESSAGE);

                        // add listeners
                        ChangeListener changeListener =
                            new ChangeListener() {
                              @Override
                              public void stateChanged(ChangeEvent e) {
                                descriptor.setValid(false);
                                createPullRequestPanel.setErrorMessage(""); // NOI18N
                              }
                            };
                        createPullRequestPanel.addChangeListener(changeListener);
                        ComparePullRequestPropertyChangeListener propertyChangeListener =
                            new ComparePullRequestPropertyChangeListener(
                                repository, createPullRequestPanel, descriptor);
                        createPullRequestPanel.addPropertyChangeListener(propertyChangeListener);
                        changeListener.stateChanged(null);

                        // show dialog
                        if (DialogDisplayer.getDefault().notify(descriptor)
                            == NotifyDescriptor.OK_OPTION) {
                          RepositoryBranch selectedBaseBranch =
                              createPullRequestPanel.getSelectedBaseBranch();
                          RepositoryBranch selectedHeadBranch =
                              createPullRequestPanel.getSelectedHeadBranch();
                          String baseBranch = selectedBaseBranch.getName();
                          String headBranch =
                              mySelf.getLogin() + ":" + selectedHeadBranch.getName(); // NOI18N
                          PullRequest pullRequest;
                          try {
                            if (isNewPullRequest) {
                              // set new pull request to panel
                              PullRequestMarker baseMarker = new PullRequestMarker();
                              baseMarker.setLabel(baseBranch);
                              PullRequestMarker headMarker = new PullRequestMarker();
                              headMarker.setLabel(headBranch);
                              PullRequest newPullRequest =
                                  new PullRequest().setBase(baseMarker).setHead(headMarker);
                              getPanel().setNewPullRequest(newPullRequest);
                            } else {
                              pullRequest = issue.createPullRequest(headBranch, baseBranch);
                              if (pullRequest != null) {
                                getPanel().refresh();
                              }
                            }
                          } catch (IOException ex) {
                            UiUtils.showErrorDialog(
                                "Can't create a pull request:" + ex.getMessage()); // NOI18N
                          }
                        } else if (isNewPullRequest) {
                          getPanel().setNewPullRequestSelected(false);
                        }

                        // remove listeners
                        createPullRequestPanel.removeChangeListener(changeListener);
                        createPullRequestPanel.removePropertyChangeListener(propertyChangeListener);
                      } finally {
                        getPanel().setCreatePullRequestButtonEnabled(true);
                      }
                    }
                  });
            }
          });
    }
    @NbBundle.Messages({
      "SubmitIssueAction.message.pull.request.added.fail=The pull request has not been added.",
      "SubmitIssueAction.message.issue.added.fail=The issue has not been added.",
      "SubmitIssueAction.message.issue.updated.fail=The issue has not been updated."
    })
    @Override
    public void actionPerformed(ActionEvent e) {
      final GitHubIssuePanel p = getPanel();
      p.setSubmitButtonEnabled(false);
      RequestProcessor rp = GitHubIssues.getInstance().getRequestProcessor();
      rp.post(
          new Runnable() {

            @Override
            public void run() {
              SwingUtilities.invokeLater(
                  new Runnable() {
                    @Override
                    public void run() {
                      GitHubIssue issue = p.getIssue();
                      CreateIssueParams issueParams = getCreateIssueParams(issue.isNew(), p);
                      if (issue.isNew()) {
                        if (p.isNewPullRequestSelected()) {
                          // add pull request
                          // can be added only title and body to a pull request
                          // add other than those after the pull request was created
                          PullRequest newPullRequest = p.getNewPullRequest();
                          if (newPullRequest != null) {
                            newPullRequest
                                .setTitle(issueParams.getTitle())
                                .setBody(issueParams.getBody());
                            try {
                              PullRequest createdPullRequest =
                                  issue.createPullRequest(newPullRequest);
                              if (createdPullRequest != null) {
                                issue.editIssue(issueParams);
                                p.update();
                              } else {
                                // show dialog
                                UiUtils.showErrorDialog(
                                    Bundle.SubmitIssueAction_message_pull_request_added_fail());
                              }
                            } catch (IOException ex) {
                              UiUtils.showErrorDialog(ex.getMessage());
                            }
                          }
                        } else {
                          // add issue
                          Issue newIssue = issue.submitNewIssue(issueParams);
                          if (newIssue != null) {
                            p.update();
                          } else {
                            // show dialog
                            UiUtils.showErrorDialog(
                                Bundle.SubmitIssueAction_message_issue_added_fail());
                          }
                        }
                      } else {
                        // edit issue
                        Issue editIssue = issue.editIssue(issueParams);
                        if (editIssue != null) {
                          p.update();
                        } else {
                          // show dialog
                          UiUtils.showErrorDialog(
                              Bundle.SubmitIssueAction_message_issue_updated_fail());
                        }
                      }
                      p.setSubmitButtonEnabled(true);
                    }
                  });
            }
          });
    }