Skip to content

Commit ceb1f1a

Browse files
committed
Merge branch 'nb80'
2 parents 3eba870 + a127176 commit ceb1f1a

12 files changed

Lines changed: 472 additions & 32 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ This plugin provides support for GitHub Issue Tracker.
77
- Create a new issue
88
- Edit an issue
99
- Create queries
10+
- Edit an issue comment
11+
- Delete an issue comment
1012
- Search issues with issue number or keywords
1113

1214
## Usage
@@ -20,6 +22,14 @@ This plugin provides support for GitHub Issue Tracker.
2022
5. Click Connect button (If you can't connect a repository, please try to check input values)
2123
6. Click OK button
2224

25+
## Default queries
26+
27+
1. Open
28+
2. Assigned to me
29+
3. Created by me
30+
31+
If you want to enable/disable these queries, Please change them on the Options panel.(Tools > Options > Team > GitHub Issues)
32+
2333
## Resources
2434

2535
- [egit-github](https://github.com/eclipse/egit-github)

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.junichi11</groupId>
55
<artifactId>netbeans-github-issues</artifactId>
6-
<version>0.0.1-SNAPSHOT</version>
6+
<version>0.0.2-SNAPSHOT</version>
77
<packaging>nbm</packaging>
88
<build>
99
<plugins>

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/GitHubIssue.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
import org.netbeans.modules.bugtracking.spi.IssueProvider;
6565
import org.netbeans.modules.bugtracking.spi.IssueStatusProvider;
6666
import org.openide.util.NbBundle;
67+
import org.pegdown.Extensions;
68+
import org.pegdown.PegDownProcessor;
6769

6870
/**
6971
*
@@ -246,6 +248,28 @@ public Issue editIssue(CreateIssueParams params) {
246248
return editIssue;
247249
}
248250

251+
public Comment editComment(Comment comment, String editedBody) {
252+
if (editedBody != null) {
253+
String originalBody = comment.getBody();
254+
if (issue != null) {
255+
comment.setBody(editedBody);
256+
Comment editComment = GitHubIssueSupport.editComment(getRepository(), comment);
257+
if (editComment != null) {
258+
PegDownProcessor processor = new PegDownProcessor(Extensions.FENCED_CODE_BLOCKS);
259+
String body = editComment.getBody();
260+
String bodyHtml = processor.markdownToHtml(body);
261+
comment.setBodyHtml(String.format("<html>%s</html>", bodyHtml)); // NOI18N
262+
comment.setBody(body);
263+
comment.setUpdatedAt(editComment.getUpdatedAt());
264+
} else {
265+
comment.setBody(originalBody);
266+
}
267+
return editComment;
268+
}
269+
}
270+
return null;
271+
}
272+
249273
public boolean isCreatedUser() {
250274
if (issue == null) {
251275
return false;

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/GitHubIssueController.java

Lines changed: 98 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@
4242
package com.junichi11.netbeans.modules.github.issues.issue;
4343

4444
import com.junichi11.netbeans.modules.github.issues.GitHubIssues;
45+
import com.junichi11.netbeans.modules.github.issues.issue.ui.CommentTabbedPanel;
46+
import com.junichi11.netbeans.modules.github.issues.issue.ui.CommentsPanel;
4547
import com.junichi11.netbeans.modules.github.issues.issue.ui.GitHubIssuePanel;
48+
import com.junichi11.netbeans.modules.github.issues.repository.GitHubRepository;
4649
import com.junichi11.netbeans.modules.github.issues.utils.StringUtils;
4750
import com.junichi11.netbeans.modules.github.issues.utils.UiUtils;
4851
import java.awt.event.ActionEvent;
4952
import java.awt.event.ActionListener;
53+
import java.beans.PropertyChangeEvent;
5054
import java.beans.PropertyChangeListener;
5155
import javax.swing.JComponent;
5256
import javax.swing.SwingUtilities;
@@ -66,7 +70,7 @@
6670
*
6771
* @author junichi11
6872
*/
69-
public class GitHubIssueController implements IssueController, ChangeListener {
73+
public class GitHubIssueController implements IssueController, ChangeListener, PropertyChangeListener {
7074

7175
private GitHubIssuePanel panel;
7276
private String errorMessage;
@@ -126,6 +130,7 @@ private GitHubIssuePanel getPanel() {
126130
panel.addAction(getSubmitIssueAction());
127131
panel.addAction(getCommentAction());
128132
panel.addAction(getCloseReopenAction());
133+
panel.addCommentsChangeListener(this);
129134
}
130135
return panel;
131136
}
@@ -172,6 +177,91 @@ private CloseReopenAction getCloseReopenAction() {
172177
return new CloseReopenAction();
173178
}
174179

180+
@Override
181+
public void propertyChange(PropertyChangeEvent evt) {
182+
switch (evt.getPropertyName()) {
183+
case CommentsPanel.PROP_COMMENT_QUOTE:
184+
GitHubIssuePanel p = getPanel();
185+
String quoteComment = StringUtils.toQuoteComment(p.getQuoteComment()) + "\n"; // NOI18N
186+
p.appendNewComment(quoteComment);
187+
break;
188+
case CommentsPanel.PROP_COMMENT_EDITED:
189+
editComment();
190+
break;
191+
case CommentsPanel.PROP_COMMENT_DELETED:
192+
deleteComment();
193+
break;
194+
default:
195+
break;
196+
}
197+
}
198+
199+
@NbBundle.Messages({
200+
"GitHubIssueController.edit.comment.title=Edit Comment",
201+
"GitHubIssueController.edit.comment.fail=Can't edit this comment."
202+
})
203+
private void editComment() {
204+
final Comment comment = getPanel().getEditedComment();
205+
final String editedBody = CommentTabbedPanel.showDialog(Bundle.GitHubIssueController_edit_comment_title(), comment.getBody());
206+
if (editedBody != null) {
207+
final GitHubIssue issue = getPanel().getIssue();
208+
if (issue != null) {
209+
RequestProcessor rp = GitHubIssues.getInstance().getRequestProcessor();
210+
rp.post(new Runnable() {
211+
212+
@Override
213+
public void run() {
214+
Comment editedComment = issue.editComment(comment, editedBody);
215+
if (editedComment == null) {
216+
UiUtils.showErrorDialog(Bundle.GitHubIssueController_edit_comment_fail());
217+
return;
218+
}
219+
SwingUtilities.invokeLater(new Runnable() {
220+
221+
@Override
222+
public void run() {
223+
getPanel().loadComments();
224+
}
225+
});
226+
}
227+
});
228+
}
229+
}
230+
}
231+
232+
@NbBundle.Messages({
233+
"GitHubIssueController.delete.comment.fail=Can't delete this issue."
234+
})
235+
private void deleteComment() {
236+
final Comment deletedComment = getPanel().getDeletedComment();
237+
if (deletedComment == null) {
238+
return;
239+
}
240+
RequestProcessor rp = GitHubIssues.getInstance().getRequestProcessor();
241+
rp.post(new Runnable() {
242+
243+
@Override
244+
public void run() {
245+
GitHubRepository repository = getPanel().getIssue().getRepository();
246+
final boolean success = GitHubIssueSupport.deleteComment(repository, deletedComment);
247+
248+
SwingUtilities.invokeLater(new Runnable() {
249+
250+
@Override
251+
public void run() {
252+
if (success) {
253+
// remove comment panel
254+
getPanel().removeDeletedComment();
255+
} else {
256+
// show error message
257+
UiUtils.showErrorDialog(Bundle.GitHubIssueController_delete_comment_fail());
258+
}
259+
}
260+
});
261+
}
262+
});
263+
}
264+
175265
//~ inner classes
176266
public class SubmitIssueAction implements ActionListener {
177267

@@ -195,7 +285,7 @@ public void run() {
195285
@Override
196286
public void run() {
197287
GitHubIssue issue = p.getIssue();
198-
CreateIssueParams issueParams = getCreateIssueParams(p);
288+
CreateIssueParams issueParams = getCreateIssueParams(issue.isNew(), p);
199289
if (issue.isNew()) {
200290
// add issue
201291
Issue newIssue = issue.submitNewIssue(issueParams);
@@ -223,9 +313,9 @@ public void run() {
223313

224314
}
225315

226-
private CreateIssueParams getCreateIssueParams(GitHubIssuePanel p) {
316+
private CreateIssueParams getCreateIssueParams(boolean isNew, GitHubIssuePanel p) {
227317
User assignee = p.getAssignee();
228-
if (assignee == null) {
318+
if (!isNew && assignee == null) {
229319
assignee = new User();
230320
assignee.setLogin(""); // NOI18N
231321
}
@@ -236,8 +326,10 @@ private CreateIssueParams getCreateIssueParams(GitHubIssuePanel p) {
236326
CreateIssueParams createIssueParams = new CreateIssueParams(p.getTitle())
237327
.body(p.getDescription())
238328
.milestone(milestone)
239-
.labels(p.getLabels())
240-
.assignee(assignee);
329+
.labels(p.getLabels());
330+
if (assignee != null) {
331+
createIssueParams = createIssueParams.assignee(assignee);
332+
}
241333
return createIssueParams;
242334
}
243335
}

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/GitHubIssueFinder.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
*/
4242
package com.junichi11.netbeans.modules.github.issues.issue;
4343

44+
import org.netbeans.modules.bugtracking.commons.SimpleIssueFinder;
4445
import org.netbeans.modules.bugtracking.spi.IssueFinder;
4546

4647
/**
@@ -49,16 +50,14 @@
4950
*/
5051
public class GitHubIssueFinder implements IssueFinder {
5152

52-
private static final int[] EMPTY_INT_ARRAY = new int[0];
53-
5453
@Override
5554
public int[] getIssueSpans(CharSequence cs) {
56-
return EMPTY_INT_ARRAY;
55+
return SimpleIssueFinder.getInstance().getIssueSpans(cs);
5756
}
5857

5958
@Override
6059
public String getIssueId(String string) {
61-
return null;
60+
return SimpleIssueFinder.getInstance().getIssueId(string);
6261
}
6362

6463
}

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/GitHubIssueSupport.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,49 @@ private static Comment createComment(GitHubRepository gitHubRepository, Issue is
149149
return issueService.createComment(gitHubRepository.getRepository(), issue.getNumber(), comment);
150150
}
151151

152+
/**
153+
* Edit comment.
154+
*
155+
* @param repository GitHubRepository
156+
* @param comment Comment
157+
* @return comment if editing successfully, otherwise {@code null}
158+
*/
159+
@CheckForNull
160+
public static Comment editComment(GitHubRepository repository, Comment comment) {
161+
IssueService issueService = createIssueService(repository);
162+
if (issueService == null) {
163+
return null;
164+
}
165+
try {
166+
return issueService.editComment(repository.getRepository(), comment);
167+
} catch (IOException ex) {
168+
LOGGER.log(Level.WARNING, ex.getMessage());
169+
}
170+
return null;
171+
}
172+
173+
/**
174+
* Delete comment.
175+
*
176+
* @param repository
177+
* @param comment
178+
* @return {@code true} if comment is deleted, otherwise {@code false}
179+
*/
180+
public static boolean deleteComment(GitHubRepository repository, Comment comment) {
181+
IssueService issueService = createIssueService(repository);
182+
if (issueService == null) {
183+
return false;
184+
}
185+
boolean success = true;
186+
try {
187+
issueService.deleteComment(repository.getRepository(), comment.getId());
188+
} catch (IOException ex) {
189+
success = false;
190+
LOGGER.log(Level.WARNING, ex.getMessage());
191+
}
192+
return success;
193+
}
194+
152195
/**
153196
* Show in browser.
154197
*

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/ui/CommentPanel.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,16 @@ private CommentPanel() {
7070
public CommentPanel(Comment comment) {
7171
this.comment = comment;
7272
initComponents();
73-
setUserName(comment.getUser().getLogin());
74-
setCreatedDate(comment.getCreatedAt());
75-
setUpdatedDate(comment.getUpdatedAt());
76-
setContent(comment.getBodyHtml());
77-
78-
// TODO
79-
deleteLinkButton.setEnabled(false);
80-
editLinkButton.setEnabled(false);
81-
quoteLinkButton.setEnabled(false);
73+
load();
74+
}
75+
76+
final void load() {
77+
if (comment != null) {
78+
setUserName(comment.getUser().getLogin());
79+
setCreatedDate(comment.getCreatedAt());
80+
setUpdatedDate(comment.getUpdatedAt());
81+
setContent(comment.getBodyHtml());
82+
}
8283
}
8384

8485
private void setUserName(String name) {
@@ -127,6 +128,18 @@ public boolean isDeleted() {
127128
return isDeleted;
128129
}
129130

131+
public void setQuoteEnabled(boolean isEnabled) {
132+
quoteLinkButton.setEnabled(isEnabled);
133+
}
134+
135+
public void setEditEnabled(boolean isEnabled) {
136+
editLinkButton.setEnabled(isEnabled);
137+
}
138+
139+
public void setDeleteEnabled(boolean isEnabled) {
140+
deleteLinkButton.setEnabled(isEnabled);
141+
}
142+
130143
void resetProperties() {
131144
isQuote = false;
132145
isEdited = false;

0 commit comments

Comments
 (0)