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,34 @@ 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+ newPullRequest .setTitle (issueParams .getTitle ())
345+ .setBody (issueParams .getBody ());
346+ try {
347+ PullRequest createdPullRequest = issue .createPullRequest (newPullRequest );
348+ if (createdPullRequest != null ) {
349+ issue .editIssue (issueParams );
350+ p .update ();
351+ } else {
352+ // show dialog
353+ UiUtils .showErrorDialog (Bundle .SubmitIssueAction_message_pull_request_added_fail ());
354+ }
355+ } catch (IOException ex ) {
356+ UiUtils .showErrorDialog (ex .getMessage ());
357+ }
341358 } else {
342- // show dialog
343- UiUtils .showErrorDialog (Bundle .SubmitIssueAction_message_issue_added_fail ());
359+ // add issue
360+ Issue newIssue = issue .submitNewIssue (issueParams );
361+ if (newIssue != null ) {
362+ p .update ();
363+ } else {
364+ // show dialog
365+ UiUtils .showErrorDialog (Bundle .SubmitIssueAction_message_issue_added_fail ());
366+ }
344367 }
345368 } else {
346369 // edit issue
@@ -482,15 +505,29 @@ private boolean closeReopen() {
482505 @ NbBundle .Messages ({
483506 "CreatePullRequestAction.confirmation.message=Do you want to change this issue to Pull Request?" ,
484507 "CreatePullRequestAction.error.message.same.branch=Another branch must be set." ,
485- "CreatePullRequestAction.descriptor.title=Change to Pull Request"
508+ "CreatePullRequestAction.descriptor.title=Pull Request"
486509 })
487510 public class CreatePullRequestAction implements ActionListener {
488511
489512 @ Override
490513 public void actionPerformed (ActionEvent e ) {
514+ String actionCommand = e .getActionCommand ();
515+ final boolean isNewPullRequest = actionCommand .equals ("New PR" ); // NOI18N
491516 GitHubIssuePanel p = getPanel ();
492517 p .setCreatePullRequestButtonEnabled (false );
493518 final GitHubIssue issue = p .getIssue ();
519+
520+ if (isNewPullRequest && !p .isNewPullRequestSelected ()) {
521+ // remove the new pull request from the panle
522+ SwingUtilities .invokeLater (new Runnable () {
523+ @ Override
524+ public void run () {
525+ getPanel ().setNewPullRequest (null );
526+ }
527+ });
528+ return ;
529+ }
530+
494531 RequestProcessor rp = GitHubIssues .getInstance ().getRequestProcessor ();
495532 rp .post (new Runnable () {
496533 @ Override
@@ -543,13 +580,27 @@ public void stateChanged(ChangeEvent e) {
543580 String headBranch = mySelf .getLogin () + ":" + selectedHeadBranch .getName (); // NOI18N
544581 PullRequest pullRequest ;
545582 try {
546- pullRequest = issue .createPullRequest (headBranch , baseBranch );
547- if (pullRequest != null ) {
548- getPanel ().refresh ();
583+ if (isNewPullRequest ) {
584+ // set new pull request to panel
585+ PullRequestMarker baseMarker = new PullRequestMarker ();
586+ baseMarker .setLabel (baseBranch );
587+ PullRequestMarker headMarker = new PullRequestMarker ();
588+ headMarker .setLabel (headBranch );
589+ PullRequest newPullRequest = new PullRequest ()
590+ .setBase (baseMarker )
591+ .setHead (headMarker );
592+ getPanel ().setNewPullRequest (newPullRequest );
593+ } else {
594+ pullRequest = issue .createPullRequest (headBranch , baseBranch );
595+ if (pullRequest != null ) {
596+ getPanel ().refresh ();
597+ }
549598 }
550599 } catch (IOException ex ) {
551600 UiUtils .showErrorDialog ("Can't create a pull request:" + ex .getMessage ()); // NOI18N
552601 }
602+ } else if (isNewPullRequest ) {
603+ getPanel ().setNewPullRequestSelected (false );
553604 }
554605
555606 // remove listeners
0 commit comments