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