Skip to content

Commit e73a449

Browse files
committed
Created more suitable enum for getting information.
1 parent c9af2dc commit e73a449

File tree

6 files changed

+116
-98
lines changed

6 files changed

+116
-98
lines changed

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

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
import org.eclipse.egit.github.core.client.GitHubClient;
99
import org.eclipse.egit.github.core.client.PageIterator;
1010
import org.eclipse.egit.github.core.service.IssueService;
11+
import org.jetbrains.research.groups.ml_methods.error_reporting.ErrorReportInformation.InformationType;
1112
import org.jetbrains.research.groups.ml_methods.utils.ArchitectureReloadedBundle;
1213

1314
import javax.annotation.Nullable;
1415
import java.util.*;
15-
import java.util.Map.Entry;
16+
17+
import static org.jetbrains.research.groups.ml_methods.error_reporting.ErrorReportInformation.InformationType.*;
1618

1719
/**
1820
* Provides functionality to create and send GitHub issues when an exception is thrown by a plugin.
@@ -23,6 +25,24 @@ class AnonymousFeedback {
2325
private final static String GIT_REPO = "ArchitectureReloaded";
2426
private final static String ISSUE_LABEL_BUG = "bug";
2527
private final static String ISSUE_LABEL_AUTO_GENERATED = "auto-generated";
28+
private final static String GIT_ISSUE_TITLE = "[auto-generated:%s] %s";
29+
private final static EnumMap<InformationType, String> usersInformationToPresentableForm
30+
= new EnumMap<>(InformationType.class);
31+
32+
static {
33+
usersInformationToPresentableForm.put(PLUGIN_NAME, "Plugin Name");
34+
usersInformationToPresentableForm.put(PLUGIN_VERSION, "Plugin Version");
35+
usersInformationToPresentableForm.put(OS_NAME, "OS Name");
36+
usersInformationToPresentableForm.put(JAVA_VERSION, "Java Version");
37+
usersInformationToPresentableForm.put(JAVA_VM_VENDOR, "Java VM Vendor");
38+
usersInformationToPresentableForm.put(APP_NAME, "App Name");
39+
usersInformationToPresentableForm.put(APP_FULL_NAME, "App Full Name");
40+
usersInformationToPresentableForm.put(APP_VERSION_NAME, "App Version Name");
41+
usersInformationToPresentableForm.put(IS_EAP, "Is EAP");
42+
usersInformationToPresentableForm.put(APP_BUILD, "App Build");
43+
usersInformationToPresentableForm.put(APP_VERSION, "App Version");
44+
usersInformationToPresentableForm.put(LAST_ACTION, "Last Action");
45+
}
2646

2747
private AnonymousFeedback() {
2848
}
@@ -31,11 +51,11 @@ private AnonymousFeedback() {
3151
* Makes a connection to GitHub. Checks if there is an issue that is a duplicate and based on this, creates either a
3252
* new issue or comments on the duplicate (if the user provided additional information).
3353
*
34-
* @param environmentDetails Information collected by {@link IdeaInformationProxy}
54+
* @param errorReportInformation Information collected by {@link ErrorReportInformation}
3555
* @return The report info that is then used in {@link GitHubErrorReporter} to show the user a balloon with the link
3656
* of the created issue.
3757
*/
38-
static SubmittedReportInfo sendFeedback(LinkedHashMap<String, String> environmentDetails) {
58+
static SubmittedReportInfo sendFeedback(ErrorReportInformation errorReportInformation) {
3959

4060
final SubmittedReportInfo result;
4161
try {
@@ -46,16 +66,12 @@ static SubmittedReportInfo sendFeedback(LinkedHashMap<String, String> environmen
4666
RepositoryId repoID = new RepositoryId(GIT_REPO_USER, GIT_REPO);
4767
IssueService issueService = new IssueService(client);
4868

49-
String errorDescription = environmentDetails.get("error.description");
50-
51-
Issue newGibHubIssue = createNewGibHubIssue(environmentDetails);
69+
Issue newGibHubIssue = createNewGibHubIssue(errorReportInformation);
5270
Issue duplicate = findFirstDuplicate(newGibHubIssue.getTitle(), issueService, repoID);
5371
boolean isNewIssue = true;
5472
if (duplicate != null) {
55-
// TODO: fix error description doesn't prints, implement enums
56-
errorDescription = errorDescription == null ? "Me too! \n" : "";
57-
errorDescription += generateGitHubIssueBody(environmentDetails, true);
58-
issueService.createComment(repoID, duplicate.getNumber(), errorDescription);
73+
String newErrorComment = generateGitHubIssueBody(errorReportInformation, false);
74+
issueService.createComment(repoID, duplicate.getNumber(), newErrorComment);
5975
newGibHubIssue = duplicate;
6076
isNewIssue = false;
6177
} else {
@@ -86,6 +102,7 @@ static SubmittedReportInfo sendFeedback(LinkedHashMap<String, String> environmen
86102
@Nullable
87103
private static Issue findFirstDuplicate(String uniqueTitle, final IssueService service, RepositoryId repo) {
88104
Map<String, String> searchParameters = new HashMap<>(2);
105+
// TODO: process closed: if it is closed advice update
89106
searchParameters.put(IssueService.FILTER_STATE, IssueService.STATE_OPEN);
90107
final PageIterator<Issue> pages = service.pageIssues(repo, searchParameters);
91108
for (Collection<Issue> page : pages) {
@@ -101,26 +118,23 @@ private static Issue findFirstDuplicate(String uniqueTitle, final IssueService s
101118
/**
102119
* Turns collected information of an error into a new (offline) GitHub issue
103120
*
104-
* @param details A map of the information. Note that I remove items from there when they should not go in the issue
121+
* @param errorReportInformation A map of the information. Note that I remove items from there when they should not go in the issue
105122
* body as well. When creating the body, all remaining items are iterated.
106123
* @return The new issue
107124
*/
108-
private static Issue createNewGibHubIssue(LinkedHashMap<String, String> details) {
109-
String errorMessage = details.get("error.message");
125+
private static Issue createNewGibHubIssue(ErrorReportInformation errorReportInformation) {
126+
String errorMessage = errorReportInformation.get(ERROR_MESSAGE);
110127
if (errorMessage == null || errorMessage.isEmpty()) {
111128
errorMessage = "Unspecified error";
112129
}
113-
details.remove("error.message");
114-
115-
String errorHash = details.get("error.hash");
130+
String errorHash = errorReportInformation.get(ERROR_HASH);
116131
if (errorHash == null) {
117132
errorHash = "";
118133
}
119-
details.remove("error.hash");
120134

121135
final Issue gitHubIssue = new Issue();
122-
final String body = generateGitHubIssueBody(details, false);
123-
gitHubIssue.setTitle(ArchitectureReloadedBundle.message("git.issue.title", errorHash, errorMessage));
136+
final String body = generateGitHubIssueBody(errorReportInformation, true);
137+
gitHubIssue.setTitle(String.format(GIT_ISSUE_TITLE, errorHash, errorMessage));
124138
gitHubIssue.setBody(body);
125139
Label bugLabel = new Label();
126140
bugLabel.setName(ISSUE_LABEL_BUG);
@@ -131,42 +145,36 @@ private static Issue createNewGibHubIssue(LinkedHashMap<String, String> details)
131145
}
132146

133147
/**
134-
* Creates the body of the GitHub issue. It will contain information about the system, details provided by the user
135-
* and the full stack trace. Everything is formatted using markdown.
148+
* Creates the body of the GitHub issue. It will contain information about the system, error report information
149+
* provided by the user and the full stack trace. Everything is formatted using markdown.
136150
*
137-
* @param details Details provided by {@link IdeaInformationProxy}
151+
* @param errorReportInformation Details provided by {@link ErrorReportInformation}
138152
* @return A markdown string representing the GitHub issue body.
139153
*/
140-
private static String generateGitHubIssueBody(LinkedHashMap<String, String> details, boolean onlyUserInfo) {
141-
String errorDescription = details.get("error.description");
154+
private static String generateGitHubIssueBody(ErrorReportInformation errorReportInformation, boolean addStacktrace) {
155+
String errorDescription = errorReportInformation.get(ERROR_DESCRIPTION);
142156
if (errorDescription == null) {
143157
errorDescription = "";
144158
}
145-
details.remove("error.description");
146-
147-
148-
String stackTrace = details.get("error.stacktrace");
159+
String stackTrace = errorReportInformation.get(ERROR_STACKTRACE);
149160
if (stackTrace == null || stackTrace.isEmpty()) {
150161
stackTrace = "invalid stacktrace";
151162
}
152-
details.remove("error.stacktrace");
153163

154164
StringBuilder result = new StringBuilder();
155-
156165
if (!errorDescription.isEmpty()) {
157166
result.append(errorDescription);
158167
result.append("\n\n----------------------\n\n");
159168
}
160-
161-
for (Entry<String, String> entry : details.entrySet()) {
169+
for (Map.Entry<InformationType, String> usersInformationEntry : usersInformationToPresentableForm.entrySet()) {
162170
result.append("- ");
163-
result.append(entry.getKey());
171+
result.append(usersInformationEntry.getValue());
164172
result.append(": ");
165-
result.append(entry.getValue());
173+
result.append(errorReportInformation.get(usersInformationEntry.getKey()));
166174
result.append("\n");
167175
}
168176

169-
if (!onlyUserInfo) {
177+
if (addStacktrace) {
170178
result.append("\n```\n");
171179
result.append(stackTrace);
172180
result.append("\n```\n");

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,28 @@
88
import org.jetbrains.annotations.NotNull;
99
import org.jetbrains.annotations.Nullable;
1010

11-
import java.util.LinkedHashMap;
12-
1311

1412
/**
1513
* Encapsulates the sending of feedback into a background task that is run by {@link GitHubErrorReporter}
1614
*/
1715
public class AnonymousFeedbackTask extends Backgroundable {
1816
private final Consumer<SubmittedReportInfo> myCallback;
19-
private final LinkedHashMap<String, String> myParams;
17+
private final ErrorReportInformation errorReportInformation;
2018

2119
AnonymousFeedbackTask(@Nullable Project project,
2220
@NotNull String title,
2321
boolean canBeCancelled,
24-
LinkedHashMap<String, String> params,
22+
ErrorReportInformation errorReportInformation,
2523
final Consumer<SubmittedReportInfo> callback) {
2624
super(project, title, canBeCancelled);
2725

28-
myParams = params;
26+
this.errorReportInformation = errorReportInformation;
2927
myCallback = callback;
3028
}
3129

3230
@Override
3331
public void run(@NotNull ProgressIndicator indicator) {
3432
indicator.setIndeterminate(true);
35-
myCallback.consume(AnonymousFeedback.sendFeedback(myParams));
33+
myCallback.consume(AnonymousFeedback.sendFeedback(errorReportInformation));
3634
}
3735
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.jetbrains.research.groups.ml_methods.error_reporting;
2+
3+
import com.intellij.openapi.application.ApplicationNamesInfo;
4+
import com.intellij.openapi.application.ex.ApplicationInfoEx;
5+
import com.intellij.openapi.diagnostic.Attachment;
6+
import com.intellij.util.SystemProperties;
7+
8+
import java.util.EnumMap;
9+
10+
import static org.jetbrains.research.groups.ml_methods.error_reporting.ErrorReportInformation.InformationType.*;
11+
12+
/**
13+
* Collects information about the running IDEA and the error
14+
*/
15+
class ErrorReportInformation {
16+
public enum InformationType {
17+
ERROR_DESCRIPTION, PLUGIN_NAME, PLUGIN_VERSION, OS_NAME, JAVA_VERSION, JAVA_VM_VENDOR,
18+
APP_NAME, APP_FULL_NAME, APP_VERSION_NAME, IS_EAP, APP_BUILD, APP_VERSION, LAST_ACTION,
19+
ERROR_MESSAGE, ERROR_STACKTRACE, ERROR_HASH, ATTACHMENT_NAME, ATTACHMENT_VALUE
20+
}
21+
22+
private final EnumMap<InformationType, String> information = new EnumMap<>(InformationType.class);
23+
24+
private ErrorReportInformation(GitHubErrorBean error,
25+
ApplicationInfoEx appInfo,
26+
ApplicationNamesInfo namesInfo) {
27+
information.put(ERROR_DESCRIPTION, error.getDescription());
28+
29+
information.put(PLUGIN_NAME, error.getPluginName());
30+
information.put(PLUGIN_VERSION, error.getPluginVersion());
31+
32+
information.put(OS_NAME, SystemProperties.getOsName());
33+
information.put(JAVA_VERSION, SystemProperties.getJavaVersion());
34+
information.put(JAVA_VM_VENDOR, SystemProperties.getJavaVmVendor());
35+
36+
information.put(APP_NAME, namesInfo.getProductName());
37+
information.put(APP_FULL_NAME, namesInfo.getFullProductName());
38+
information.put(APP_VERSION_NAME, appInfo.getVersionName());
39+
information.put(IS_EAP, Boolean.toString(appInfo.isEAP()));
40+
information.put(APP_BUILD, appInfo.getBuild().asString());
41+
information.put(APP_VERSION, appInfo.getFullVersion());
42+
43+
information.put(LAST_ACTION, error.getLastAction());
44+
45+
information.put(ERROR_MESSAGE, error.getMessage());
46+
information.put(ERROR_STACKTRACE, error.getStackTrace());
47+
information.put(ERROR_HASH, error.getExceptionHash());
48+
49+
for (Attachment attachment : error.getAttachments()) {
50+
information.put(ATTACHMENT_NAME, attachment.getName());
51+
information.put(ATTACHMENT_VALUE, attachment.getEncodedBytes());
52+
}
53+
54+
}
55+
56+
static ErrorReportInformation getUsersInformation(GitHubErrorBean error,
57+
ApplicationInfoEx appInfo,
58+
ApplicationNamesInfo namesInfo) {
59+
return new ErrorReportInformation(error, appInfo, namesInfo);
60+
}
61+
62+
public String get(InformationType informationType) {
63+
return information.get(informationType);
64+
}
65+
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.intellij.openapi.actionSystem.CommonDataKeys;
1414
import com.intellij.openapi.actionSystem.DataContext;
1515
import com.intellij.openapi.application.ApplicationInfo;
16-
import com.intellij.openapi.application.ApplicationManager;
1716
import com.intellij.openapi.application.ApplicationNamesInfo;
1817
import com.intellij.openapi.application.ex.ApplicationInfoEx;
1918
import com.intellij.openapi.diagnostic.ErrorReportSubmitter;
@@ -28,7 +27,6 @@
2827
import org.jetbrains.research.groups.ml_methods.utils.ArchitectureReloadedBundle;
2928

3029
import java.awt.*;
31-
import java.util.LinkedHashMap;
3230

3331
public class GitHubErrorReporter extends ErrorReportSubmitter {
3432
@Override
@@ -66,9 +64,8 @@ private static boolean doSubmit(final IdeaLoggingEvent event,
6664
bean.setAttachments(((LogMessageEx) data).getIncludedAttachments());
6765
}
6866

69-
LinkedHashMap<String, String> reportValues = IdeaInformationProxy
70-
.getKeyValuePairs(bean,
71-
ApplicationManager.getApplication(),
67+
ErrorReportInformation errorReportInformation = ErrorReportInformation
68+
.getUsersInformation(bean,
7269
(ApplicationInfoEx) ApplicationInfo.getInstance(),
7370
ApplicationNamesInfo.getInstance());
7471

@@ -79,7 +76,7 @@ private static boolean doSubmit(final IdeaLoggingEvent event,
7976
new AnonymousFeedbackTask(project,
8077
ArchitectureReloadedBundle.message("report.error.progress.dialog.text"),
8178
true,
82-
reportValues,
79+
errorReportInformation,
8380
notifyingCallback);
8481
if (project == null) {
8582
task.run(new EmptyProgressIndicator());

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

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/main/resources/ArchitectureReloadedBundle.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,5 @@ target.class.is.not.valid = Target class is not valid anymore
3838
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
41-
git.issue.title = [auto-generated:{0}] {1}
4241
git.issue.text = <a href="{0}">Created issue {1}</a>. Thank you for your feedback!
43-
git.issue.duplicate.text = <a href="{0}">A similar issues was already reported (#{1})</a>. Thank you for your feedback!
42+
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)