Skip to content

Commit c9af2dc

Browse files
committed
Added more convenient constants naming, added labels support, added user info to comment.
1 parent 4bf77c3 commit c9af2dc

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

src/main/java/org/jetbrains/research/groups/ml_methods/error_reporting/AnonymousFeedback.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@
1111
import org.jetbrains.research.groups.ml_methods.utils.ArchitectureReloadedBundle;
1212

1313
import javax.annotation.Nullable;
14-
import java.io.IOException;
1514
import java.util.*;
1615
import java.util.Map.Entry;
1716

1817
/**
1918
* Provides functionality to create and send GitHub issues when an exception is thrown by a plugin.
2019
*/
2120
class AnonymousFeedback {
22-
private final static String tokenFile = "errorReporterToken";
23-
private final static String gitRepoUser = "ml-in-programming";
24-
private final static String gitRepo = "ArchitectureReloaded";
25-
26-
private final static String issueLabel = "auto-generated";
21+
private final static String TOKEN_FILE = "errorReporterToken";
22+
private final static String GIT_REPO_USER = "ml-in-programming";
23+
private final static String GIT_REPO = "ArchitectureReloaded";
24+
private final static String ISSUE_LABEL_BUG = "bug";
25+
private final static String ISSUE_LABEL_AUTO_GENERATED = "auto-generated";
2726

2827
private AnonymousFeedback() {
2928
}
@@ -40,11 +39,11 @@ static SubmittedReportInfo sendFeedback(LinkedHashMap<String, String> environmen
4039

4140
final SubmittedReportInfo result;
4241
try {
43-
final String gitAccessToken = GitHubAccessTokenScrambler.decrypt(AnonymousFeedback.class.getResourceAsStream(tokenFile));
42+
final String gitAccessToken = GitHubAccessTokenScrambler.decrypt(AnonymousFeedback.class.getResourceAsStream(TOKEN_FILE));
4443

4544
GitHubClient client = new GitHubClient();
4645
client.setOAuth2Token(gitAccessToken);
47-
RepositoryId repoID = new RepositoryId(gitRepoUser, gitRepo);
46+
RepositoryId repoID = new RepositoryId(GIT_REPO_USER, GIT_REPO);
4847
IssueService issueService = new IssueService(client);
4948

5049
String errorDescription = environmentDetails.get("error.description");
@@ -53,7 +52,9 @@ static SubmittedReportInfo sendFeedback(LinkedHashMap<String, String> environmen
5352
Issue duplicate = findFirstDuplicate(newGibHubIssue.getTitle(), issueService, repoID);
5453
boolean isNewIssue = true;
5554
if (duplicate != null) {
56-
errorDescription = errorDescription == null ? "Me too!" : errorDescription;
55+
// TODO: fix error description doesn't prints, implement enums
56+
errorDescription = errorDescription == null ? "Me too! \n" : "";
57+
errorDescription += generateGitHubIssueBody(environmentDetails, true);
5758
issueService.createComment(repoID, duplicate.getNumber(), errorDescription);
5859
newGibHubIssue = duplicate;
5960
isNewIssue = false;
@@ -81,10 +82,9 @@ static SubmittedReportInfo sendFeedback(LinkedHashMap<String, String> environmen
8182
* @param service Issue-service of the GitHub lib that lets you access all issues
8283
* @param repo The repository that should be used
8384
* @return The duplicate if one is found or null
84-
* @throws IOException Problems when connecting to GitHub
8585
*/
8686
@Nullable
87-
private static Issue findFirstDuplicate(String uniqueTitle, final IssueService service, RepositoryId repo) throws IOException {
87+
private static Issue findFirstDuplicate(String uniqueTitle, final IssueService service, RepositoryId repo) {
8888
Map<String, String> searchParameters = new HashMap<>(2);
8989
searchParameters.put(IssueService.FILTER_STATE, IssueService.STATE_OPEN);
9090
final PageIterator<Issue> pages = service.pageIssues(repo, searchParameters);
@@ -119,12 +119,14 @@ private static Issue createNewGibHubIssue(LinkedHashMap<String, String> details)
119119
details.remove("error.hash");
120120

121121
final Issue gitHubIssue = new Issue();
122-
final String body = generateGitHubIssueBody(details);
122+
final String body = generateGitHubIssueBody(details, false);
123123
gitHubIssue.setTitle(ArchitectureReloadedBundle.message("git.issue.title", errorHash, errorMessage));
124124
gitHubIssue.setBody(body);
125-
Label label = new Label();
126-
label.setName(issueLabel);
127-
gitHubIssue.setLabels(Collections.singletonList(label));
125+
Label bugLabel = new Label();
126+
bugLabel.setName(ISSUE_LABEL_BUG);
127+
Label autoGeneratedLabel = new Label();
128+
autoGeneratedLabel.setName(ISSUE_LABEL_AUTO_GENERATED);
129+
gitHubIssue.setLabels(Arrays.asList(autoGeneratedLabel, bugLabel));
128130
return gitHubIssue;
129131
}
130132

@@ -135,7 +137,7 @@ private static Issue createNewGibHubIssue(LinkedHashMap<String, String> details)
135137
* @param details Details provided by {@link IdeaInformationProxy}
136138
* @return A markdown string representing the GitHub issue body.
137139
*/
138-
private static String generateGitHubIssueBody(LinkedHashMap<String, String> details) {
140+
private static String generateGitHubIssueBody(LinkedHashMap<String, String> details, boolean onlyUserInfo) {
139141
String errorDescription = details.get("error.description");
140142
if (errorDescription == null) {
141143
errorDescription = "";
@@ -164,9 +166,11 @@ private static String generateGitHubIssueBody(LinkedHashMap<String, String> deta
164166
result.append("\n");
165167
}
166168

167-
result.append("\n```\n");
168-
result.append(stackTrace);
169-
result.append("\n```\n");
169+
if (!onlyUserInfo) {
170+
result.append("\n```\n");
171+
result.append(stackTrace);
172+
result.append("\n```\n");
173+
}
170174

171175
return result.toString();
172176
}

src/main/java/org/jetbrains/research/groups/ml_methods/error_reporting/GitHubErrorReporter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ private static boolean doSubmit(final IdeaLoggingEvent event,
7676

7777
final CallbackWithNotification notifyingCallback = new CallbackWithNotification(callback, project);
7878
AnonymousFeedbackTask task =
79-
new AnonymousFeedbackTask(project, ArchitectureReloadedBundle.message("report.error.progress.dialog.text"), true, reportValues, notifyingCallback);
79+
new AnonymousFeedbackTask(project,
80+
ArchitectureReloadedBundle.message("report.error.progress.dialog.text"),
81+
true,
82+
reportValues,
83+
notifyingCallback);
8084
if (project == null) {
8185
task.run(new EmptyProgressIndicator());
8286
} else {

src/main/resources/ArchitectureReloadedBundle.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,5 @@ report.error.to.plugin.vendor = Report error to plugin vendor
3939
report.error.progress.dialog.text = Submitting error report...
4040
report.error.connection.failure = Could not communicate with GitHub
4141
git.issue.title = [auto-generated:{0}] {1}
42-
git.issue.label = auto-generated
4342
git.issue.text = <a href="{0}">Created issue {1}</a>. Thank you for your feedback!
4443
git.issue.duplicate.text = <a href="{0}">A similar issues was already reported (#{1})</a>. Thank you for your feedback!

0 commit comments

Comments
 (0)