-
Notifications
You must be signed in to change notification settings - Fork 104
Developed error handler that help user to create new bug report #552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
VitaliyBoyko
merged 7 commits into
magento:4.0.0-develop
from
bohdan-harniuk:error-handler-development
Apr 19, 2021
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6d3af78
Developed error handler that help user to create new bug report
bohdan-harniuk 24006f7
Merge branch '4.0.0-develop' of github.com:magento/magento2-phpstorm-…
bohdan-harniuk 17a23b1
Merge branch '4.0.0-develop' into error-handler-development
bohdan-harniuk c5bf017
Merge branch '4.0.0-develop' into error-handler-development
9246d8f
Merge branch '4.0.0-develop' of github.com:magento/magento2-phpstorm-…
bohdan-harniuk ef14231
Merge branch 'error-handler-development' of github.com:sora1004/magen…
bohdan-harniuk 4728871
Code refactoring after CR
bohdan-harniuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
resources/fileTemplates/code/GitHub New Bug Issue Body Template.txt.ft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
**Describe the bug** (*) | ||
|
||
${BUG_DESCRIPTION} | ||
|
||
``` | ||
${STACK_TRACE} | ||
``` | ||
|
||
**To Reproduce** (*) | ||
|
||
Steps to reproduce the behavior: | ||
1. Go to '...' | ||
2. Click on '....' | ||
3. Scroll down to '....' | ||
4. See error | ||
|
||
**Expected behavior** (*) | ||
|
||
A clear and concise description of what you expected to happen. | ||
|
||
**Screenshots** | ||
|
||
If applicable, add screenshots to help explain your problem. | ||
|
||
**Please complete the following information:** (*) | ||
|
||
- OS: [e.g. MacOS or Ubuntu Linux 20.04] | ||
- PhpStorm/Intellij version: [e.g. 2019.3.3] | ||
- Plugin Version: [e.g. 1.0.0] | ||
|
||
**Additional context** | ||
|
||
Add any other context about the problem here. |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/com/magento/idea/magento2plugin/project/diagnostic/DefaultErrorReportSubmitter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
package com.magento.idea.magento2plugin.project.diagnostic; | ||
|
||
import com.intellij.ide.BrowserUtil; | ||
import com.intellij.ide.DataManager; | ||
import com.intellij.openapi.actionSystem.CommonDataKeys; | ||
import com.intellij.openapi.actionSystem.DataContext; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.diagnostic.ErrorReportSubmitter; | ||
import com.intellij.openapi.diagnostic.IdeaLoggingEvent; | ||
import com.intellij.openapi.diagnostic.SubmittedReportInfo; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.util.NlsActions; | ||
import com.intellij.util.Consumer; | ||
import com.magento.idea.magento2plugin.bundles.CommonBundle; | ||
import com.magento.idea.magento2plugin.project.diagnostic.github.GitHubNewIssueBodyBuilderUtil; | ||
import com.magento.idea.magento2plugin.project.diagnostic.github.GitHubNewIssueUrlBuilderUtil; | ||
import java.awt.Component; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import javax.swing.JOptionPane; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class DefaultErrorReportSubmitter extends ErrorReportSubmitter { | ||
|
||
private static final String DEFAULT_ISSUE_TITLE = "Bug Report %date"; | ||
private static final String DEFAULT_ISSUE_DESCRIPTION | ||
= "A clear and concise description of what the bug is."; | ||
private final CommonBundle commonBundle; | ||
|
||
/** | ||
* Default error report submitter. | ||
*/ | ||
public DefaultErrorReportSubmitter() { | ||
super(); | ||
commonBundle = new CommonBundle(); | ||
} | ||
|
||
/** | ||
* Open GitHub link with creation of the new bug report issue. | ||
* | ||
* @param events IdeaLoggingEvent[] | ||
* @param additionalInfo String | ||
* @param parentComponent Component | ||
* @param consumer Consumer | ||
* | ||
* @return boolean | ||
*/ | ||
@Override | ||
public boolean submit( | ||
final @NotNull IdeaLoggingEvent[] events, | ||
final @Nullable String additionalInfo, | ||
final @NotNull Component parentComponent, | ||
final @NotNull Consumer<? super SubmittedReportInfo> consumer | ||
) { | ||
final DataContext context = DataManager.getInstance().getDataContext(parentComponent); | ||
final Project project = CommonDataKeys.PROJECT.getData(context); | ||
|
||
if (project == null) { | ||
return false; | ||
} | ||
final StringBuilder stackTrace = new StringBuilder(); | ||
|
||
for (final IdeaLoggingEvent event : events) { | ||
stackTrace.append(event.getThrowableText()).append("\r\n"); | ||
} | ||
|
||
final String bugReportBody = GitHubNewIssueBodyBuilderUtil.buildNewBugReportBody( | ||
project, | ||
additionalInfo == null ? DEFAULT_ISSUE_DESCRIPTION : additionalInfo, | ||
stackTrace.toString() | ||
); | ||
|
||
BrowserUtil.browse( | ||
GitHubNewIssueUrlBuilderUtil.buildNewBugIssueUrl( | ||
getDefaultIssueTitle(), | ||
bugReportBody | ||
) | ||
); | ||
|
||
ApplicationManager.getApplication().invokeLater(() -> { | ||
JOptionPane.showMessageDialog( | ||
parentComponent, | ||
commonBundle.message("common.diagnostic.reportSubmittedMessage"), | ||
commonBundle.message("common.diagnostic.reportSubmittedTitle"), | ||
JOptionPane.INFORMATION_MESSAGE | ||
); | ||
consumer.consume( | ||
new SubmittedReportInfo(SubmittedReportInfo.SubmissionStatus.NEW_ISSUE) | ||
); | ||
}); | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public @NlsActions.ActionText @NotNull String getReportActionText() { | ||
return commonBundle.message("common.diagnostic.reportButtonText"); | ||
} | ||
|
||
/** | ||
* Get default bug issue title. | ||
* | ||
* @return String | ||
*/ | ||
private String getDefaultIssueTitle() { | ||
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd"); | ||
|
||
return DEFAULT_ISSUE_TITLE.replace("%date", formatter.format(LocalDateTime.now())); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
.../magento/idea/magento2plugin/project/diagnostic/github/GitHubNewIssueBodyBuilderUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
package com.magento.idea.magento2plugin.project.diagnostic.github; | ||
|
||
import com.intellij.ide.fileTemplates.FileTemplate; | ||
import com.intellij.ide.fileTemplates.FileTemplateManager; | ||
import com.intellij.openapi.project.Project; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public final class GitHubNewIssueBodyBuilderUtil { | ||
|
||
private static final String BUR_REPORT_TEMPLATE = "GitHub New Bug Issue Body Template"; | ||
|
||
private GitHubNewIssueBodyBuilderUtil() {} | ||
|
||
/** | ||
* Build BUG report body. | ||
* | ||
* @param project Project | ||
* @param bugDescription String | ||
* @param stackTrace String | ||
* | ||
* @return String | ||
*/ | ||
public static String buildNewBugReportBody( | ||
final @NotNull Project project, | ||
final @NotNull String bugDescription, | ||
final @NotNull String stackTrace | ||
) { | ||
final FileTemplateManager templateManager = FileTemplateManager.getInstance(project); | ||
final FileTemplate errorReportTemplate = | ||
templateManager.getCodeTemplate(BUR_REPORT_TEMPLATE); | ||
|
||
final Properties properties = new Properties(); | ||
properties.setProperty("BUG_DESCRIPTION", bugDescription); | ||
properties.setProperty("STACK_TRACE", stackTrace); | ||
|
||
try { | ||
return errorReportTemplate.getText(properties); | ||
} catch (IOException exception) { | ||
return ""; | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...m/magento/idea/magento2plugin/project/diagnostic/github/GitHubNewIssueUrlBuilderUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
package com.magento.idea.magento2plugin.project.diagnostic.github; | ||
|
||
import java.net.URLEncoder; | ||
import java.nio.charset.StandardCharsets; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public final class GitHubNewIssueUrlBuilderUtil { | ||
|
||
private static final String NEW_BUG_ISSUE_BASE_URL = "https://github.com/magento/" | ||
+ "magento2-phpstorm-plugin/issues/new" | ||
+ "?assignees=&labels=bug&template=bug_report.md"; | ||
|
||
private GitHubNewIssueUrlBuilderUtil() {} | ||
|
||
/** | ||
* Build new issue url (template -> bug_report). | ||
* | ||
* @param title String | ||
* @param body String | ||
* | ||
* @return String | ||
*/ | ||
public static String buildNewBugIssueUrl( | ||
final @NotNull String title, | ||
final @NotNull String body | ||
) { | ||
final String encodedTitle = URLEncoder.encode(title, StandardCharsets.UTF_8); | ||
final String encodedBody = URLEncoder.encode(body, StandardCharsets.UTF_8); | ||
|
||
return NEW_BUG_ISSUE_BASE_URL | ||
.concat("&title=" + encodedTitle) | ||
.concat("&body=" + encodedBody); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done