Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,16 @@ public GitHubIssueController getController() {

public Issue submitNewIssue(CreateIssueParams params) {
Issue newIssue = repository.submitNewIssue(params);
setNewIssue(newIssue);
return newIssue;
}

/**
* Set a new issue. Add GitHubIssue to the issue cache.
*
* @param newIssue a new Issue
*/
private void setNewIssue(Issue newIssue) {
if (newIssue != null) {
setIssue(newIssue);
// add to cache
Expand All @@ -305,7 +315,6 @@ public Issue submitNewIssue(CreateIssueParams params) {
fireScheduleChange();
setIssueStatus(Status.SEEN);
}
return newIssue;
}

public Issue editIssue(CreateIssueParams params) {
Expand Down Expand Up @@ -360,6 +369,25 @@ public PullRequest createPullRequest(String head, String base) throws IOExceptio
return pullRequest;
}

/**
* Create a new pull request. Title, body, base and head can be set.
*
* @param pullRequest PullRequest
* @return PullRequest if new pull request has been created, otherwise
* {@code null}
* @throws IOException
*/
@CheckForNull
public PullRequest createPullRequest(PullRequest pullRequest) throws IOException {
GitHubRepository repo = getRepository();
PullRequest newPullRequest = repo.createPullRequest(pullRequest);
if (newPullRequest != null) {
Issue newIssue = repo.getIssue(newPullRequest.getNumber());
setNewIssue(newIssue);
}
return newPullRequest;
}

public boolean isCreatedUser() {
if (issue == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.eclipse.egit.github.core.Issue;
import org.eclipse.egit.github.core.Milestone;
import org.eclipse.egit.github.core.PullRequest;
import org.eclipse.egit.github.core.PullRequestMarker;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.RepositoryBranch;
import org.eclipse.egit.github.core.RepositoryCommitCompare;
Expand Down Expand Up @@ -316,6 +317,7 @@ private SubmitIssueAction() {
}

@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."
})
Expand All @@ -334,13 +336,36 @@ public void run() {
GitHubIssue issue = p.getIssue();
CreateIssueParams issueParams = getCreateIssueParams(issue.isNew(), p);
if (issue.isNew()) {
// add issue
Issue newIssue = issue.submitNewIssue(issueParams);
if (newIssue != null) {
p.update();
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 {
// show dialog
UiUtils.showErrorDialog(Bundle.SubmitIssueAction_message_issue_added_fail());
// 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
Expand Down Expand Up @@ -482,15 +507,29 @@ private boolean closeReopen() {
@NbBundle.Messages({
"CreatePullRequestAction.confirmation.message=Do you want to change this issue to Pull Request?",
"CreatePullRequestAction.error.message.same.branch=Another branch must be set.",
"CreatePullRequestAction.descriptor.title=Change to Pull Request"
"CreatePullRequestAction.descriptor.title=Pull Request"
})
public class CreatePullRequestAction implements ActionListener {

@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
Expand Down Expand Up @@ -533,7 +572,7 @@ public void stateChanged(ChangeEvent e) {
createPullRequestPanel.addChangeListener(changeListener);
ComparePullRequestPropertyChangeListener propertyChangeListener = new ComparePullRequestPropertyChangeListener(repository, createPullRequestPanel, descriptor);
createPullRequestPanel.addPropertyChangeListener(propertyChangeListener);
propertyChangeListener.propertyChange(null);
changeListener.stateChanged(null);

// show dialog
if (DialogDisplayer.getDefault().notify(descriptor) == NotifyDescriptor.OK_OPTION) {
Expand All @@ -543,13 +582,27 @@ public void stateChanged(ChangeEvent e) {
String headBranch = mySelf.getLogin() + ":" + selectedHeadBranch.getName(); // NOI18N
PullRequest pullRequest;
try {
pullRequest = issue.createPullRequest(headBranch, baseBranch);
if (pullRequest != null) {
getPanel().refresh();
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@
<Group type="102" alignment="1" attributes="0">
<Component id="headerErrorLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="newPullRequestToggleButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="changeToPullRequestButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="newMilestoneButton" min="-2" max="-2" attributes="0"/>
Expand Down Expand Up @@ -198,6 +200,7 @@
<Component id="newLabelButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="newMilestoneButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="changeToPullRequestButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="newPullRequestToggleButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
Expand Down Expand Up @@ -333,6 +336,13 @@
</Property>
</Properties>
</Component>
<Component class="javax.swing.JToggleButton" name="newPullRequestToggleButton">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/junichi11/netbeans/modules/github/issues/issue/ui/Bundle.properties" key="GitHubIssuePanel.newPullRequestToggleButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JScrollPane" name="mainScrollPane">
Expand Down
Loading