6969import org .eclipse .egit .github .core .Issue ;
7070import org .eclipse .egit .github .core .Milestone ;
7171import org .eclipse .egit .github .core .PullRequest ;
72+ import org .eclipse .egit .github .core .PullRequestMarker ;
7273import org .eclipse .egit .github .core .Repository ;
7374import org .eclipse .egit .github .core .RepositoryBranch ;
7475import org .eclipse .egit .github .core .RepositoryCommitCompare ;
@@ -316,6 +317,7 @@ private SubmitIssueAction() {
316317 }
317318
318319 @ NbBundle .Messages ({
320+ "SubmitIssueAction.message.pull.request.added.fail=The pull request has not been added." ,
319321 "SubmitIssueAction.message.issue.added.fail=The issue has not been added." ,
320322 "SubmitIssueAction.message.issue.updated.fail=The issue has not been updated."
321323 })
@@ -334,13 +336,36 @@ public void run() {
334336 GitHubIssue issue = p .getIssue ();
335337 CreateIssueParams issueParams = getCreateIssueParams (issue .isNew (), p );
336338 if (issue .isNew ()) {
337- // add issue
338- Issue newIssue = issue .submitNewIssue (issueParams );
339- if (newIssue != null ) {
340- p .update ();
339+ if (p .isNewPullRequestSelected ()) {
340+ // add pull request
341+ // can be added only title and body to a pull request
342+ // add other than those after the pull request was created
343+ PullRequest newPullRequest = p .getNewPullRequest ();
344+ if (newPullRequest != null ) {
345+ newPullRequest .setTitle (issueParams .getTitle ())
346+ .setBody (issueParams .getBody ());
347+ try {
348+ PullRequest createdPullRequest = issue .createPullRequest (newPullRequest );
349+ if (createdPullRequest != null ) {
350+ issue .editIssue (issueParams );
351+ p .update ();
352+ } else {
353+ // show dialog
354+ UiUtils .showErrorDialog (Bundle .SubmitIssueAction_message_pull_request_added_fail ());
355+ }
356+ } catch (IOException ex ) {
357+ UiUtils .showErrorDialog (ex .getMessage ());
358+ }
359+ }
341360 } else {
342- // show dialog
343- UiUtils .showErrorDialog (Bundle .SubmitIssueAction_message_issue_added_fail ());
361+ // add issue
362+ Issue newIssue = issue .submitNewIssue (issueParams );
363+ if (newIssue != null ) {
364+ p .update ();
365+ } else {
366+ // show dialog
367+ UiUtils .showErrorDialog (Bundle .SubmitIssueAction_message_issue_added_fail ());
368+ }
344369 }
345370 } else {
346371 // edit issue
@@ -482,15 +507,29 @@ private boolean closeReopen() {
482507 @ NbBundle .Messages ({
483508 "CreatePullRequestAction.confirmation.message=Do you want to change this issue to Pull Request?" ,
484509 "CreatePullRequestAction.error.message.same.branch=Another branch must be set." ,
485- "CreatePullRequestAction.descriptor.title=Change to Pull Request"
510+ "CreatePullRequestAction.descriptor.title=Pull Request"
486511 })
487512 public class CreatePullRequestAction implements ActionListener {
488513
489514 @ Override
490515 public void actionPerformed (ActionEvent e ) {
516+ String actionCommand = e .getActionCommand ();
517+ final boolean isNewPullRequest = actionCommand .equals ("New PR" ); // NOI18N
491518 GitHubIssuePanel p = getPanel ();
492519 p .setCreatePullRequestButtonEnabled (false );
493520 final GitHubIssue issue = p .getIssue ();
521+
522+ if (isNewPullRequest && !p .isNewPullRequestSelected ()) {
523+ // remove the new pull request from the panle
524+ SwingUtilities .invokeLater (new Runnable () {
525+ @ Override
526+ public void run () {
527+ getPanel ().setNewPullRequest (null );
528+ }
529+ });
530+ return ;
531+ }
532+
494533 RequestProcessor rp = GitHubIssues .getInstance ().getRequestProcessor ();
495534 rp .post (new Runnable () {
496535 @ Override
@@ -533,7 +572,7 @@ public void stateChanged(ChangeEvent e) {
533572 createPullRequestPanel .addChangeListener (changeListener );
534573 ComparePullRequestPropertyChangeListener propertyChangeListener = new ComparePullRequestPropertyChangeListener (repository , createPullRequestPanel , descriptor );
535574 createPullRequestPanel .addPropertyChangeListener (propertyChangeListener );
536- propertyChangeListener . propertyChange (null );
575+ changeListener . stateChanged (null );
537576
538577 // show dialog
539578 if (DialogDisplayer .getDefault ().notify (descriptor ) == NotifyDescriptor .OK_OPTION ) {
@@ -543,13 +582,27 @@ public void stateChanged(ChangeEvent e) {
543582 String headBranch = mySelf .getLogin () + ":" + selectedHeadBranch .getName (); // NOI18N
544583 PullRequest pullRequest ;
545584 try {
546- pullRequest = issue .createPullRequest (headBranch , baseBranch );
547- if (pullRequest != null ) {
548- getPanel ().refresh ();
585+ if (isNewPullRequest ) {
586+ // set new pull request to panel
587+ PullRequestMarker baseMarker = new PullRequestMarker ();
588+ baseMarker .setLabel (baseBranch );
589+ PullRequestMarker headMarker = new PullRequestMarker ();
590+ headMarker .setLabel (headBranch );
591+ PullRequest newPullRequest = new PullRequest ()
592+ .setBase (baseMarker )
593+ .setHead (headMarker );
594+ getPanel ().setNewPullRequest (newPullRequest );
595+ } else {
596+ pullRequest = issue .createPullRequest (headBranch , baseBranch );
597+ if (pullRequest != null ) {
598+ getPanel ().refresh ();
599+ }
549600 }
550601 } catch (IOException ex ) {
551602 UiUtils .showErrorDialog ("Can't create a pull request:" + ex .getMessage ()); // NOI18N
552603 }
604+ } else if (isNewPullRequest ) {
605+ getPanel ().setNewPullRequestSelected (false );
553606 }
554607
555608 // remove listeners
0 commit comments