88import org .eclipse .egit .github .core .client .GitHubClient ;
99import org .eclipse .egit .github .core .client .PageIterator ;
1010import org .eclipse .egit .github .core .service .IssueService ;
11+ import org .jetbrains .research .groups .ml_methods .error_reporting .ErrorReportInformation .InformationType ;
1112import org .jetbrains .research .groups .ml_methods .utils .ArchitectureReloadedBundle ;
1213
1314import javax .annotation .Nullable ;
1415import 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 " );
0 commit comments