1111import org .jetbrains .research .groups .ml_methods .utils .ArchitectureReloadedBundle ;
1212
1313import javax .annotation .Nullable ;
14- import java .io .IOException ;
1514import java .util .*;
1615import java .util .Map .Entry ;
1716
1817/**
1918 * Provides functionality to create and send GitHub issues when an exception is thrown by a plugin.
2019 */
2120class 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 }
0 commit comments