Skip to content

Commit 376660a

Browse files
Merge branch '4.0.0-develop' into adjust-php-class-types-builder
2 parents 65acd5b + 33defc4 commit 376660a

File tree

5 files changed

+173
-17
lines changed

5 files changed

+173
-17
lines changed

resources/META-INF/plugin.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@
270270
<internalFileTemplate name="Magento Delete Entity By Id Command"/>
271271
<internalFileTemplate name="Magento Entity Edit Action Controller Class"/>
272272
<internalFileTemplate name="Magento Entity Delete Controller Class"/>
273-
<internalFileTemplate name="Magento Web Api XML"/>
274-
<internalFileTemplate name="Web Api Interface"/>
273+
<internalFileTemplate name="Magento Web API XML"/>
274+
<internalFileTemplate name="Web API Interface"/>
275275

276276
<defaultLiveTemplates file="/liveTemplates/MagentoPWA.xml"/>
277277

resources/fileTemplates/code/GitHub New Bug Issue Body Template.txt.ft

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ If applicable, add screenshots to help explain your problem.
2424

2525
**Please complete the following information:** (*)
2626

27-
- OS: [e.g. MacOS or Ubuntu Linux 20.04]
28-
- PhpStorm/Intellij version: [e.g. 2019.3.3]
29-
- Plugin Version: [e.g. 1.0.0]
27+
#set($os = "#if(${OS_VERSION})${OS_VERSION}#else[e.g. MacOS or Ubuntu Linux 20.04]#end")
28+
#set($intellijVersion = "#if(${INTELLIJ_VERSION})${INTELLIJ_VERSION}#else[e.g. 2019.3.3]#end")
29+
#set($pluginVersion = "#if(${PLUGIN_VERSION})${PLUGIN_VERSION}#else[e.g. 1.0.0]#end")
30+
- OS: $os
31+
- PhpStorm/Intellij version: $intellijVersion
32+
- Plugin Version: $pluginVersion
3033

3134
**Additional context**
3235

src/com/magento/idea/magento2plugin/project/diagnostic/DefaultErrorReportSubmitter.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.intellij.openapi.util.NlsActions;
1818
import com.intellij.util.Consumer;
1919
import com.magento.idea.magento2plugin.bundles.CommonBundle;
20-
import com.magento.idea.magento2plugin.project.diagnostic.github.GitHubNewIssueBodyBuilderUtil;
2120
import com.magento.idea.magento2plugin.project.diagnostic.github.GitHubNewIssueUrlBuilderUtil;
2221
import java.awt.Component;
2322
import java.time.LocalDateTime;
@@ -70,16 +69,12 @@ public boolean submit(
7069
stackTrace.append(event.getThrowableText()).append("\r\n");
7170
}
7271

73-
final String bugReportBody = GitHubNewIssueBodyBuilderUtil.buildNewBugReportBody(
74-
project,
75-
additionalInfo == null ? DEFAULT_ISSUE_DESCRIPTION : additionalInfo,
76-
stackTrace.toString()
77-
);
78-
7972
BrowserUtil.browse(
8073
GitHubNewIssueUrlBuilderUtil.buildNewBugIssueUrl(
8174
getDefaultIssueTitle(),
82-
bugReportBody
75+
additionalInfo == null ? DEFAULT_ISSUE_DESCRIPTION : additionalInfo,
76+
stackTrace.toString(),
77+
project
8378
)
8479
);
8580

src/com/magento/idea/magento2plugin/project/diagnostic/github/GitHubNewIssueBodyBuilderUtil.java

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@
77

88
import com.intellij.ide.fileTemplates.FileTemplate;
99
import com.intellij.ide.fileTemplates.FileTemplateManager;
10+
import com.intellij.ide.plugins.IdeaPluginDescriptor;
11+
import com.intellij.ide.plugins.PluginManagerCore;
12+
import com.intellij.openapi.application.ApplicationInfo;
13+
import com.intellij.openapi.extensions.PluginId;
1014
import com.intellij.openapi.project.Project;
15+
import com.intellij.openapi.util.SystemInfo;
1116
import java.io.IOException;
17+
import java.net.URLDecoder;
18+
import java.net.URLEncoder;
19+
import java.nio.charset.StandardCharsets;
1220
import java.util.Properties;
1321
import org.jetbrains.annotations.NotNull;
1422

@@ -24,10 +32,44 @@ private GitHubNewIssueBodyBuilderUtil() {}
2432
* @param project Project
2533
* @param bugDescription String
2634
* @param stackTrace String
35+
* @param maxAllowedBodyLength int
2736
*
2837
* @return String
2938
*/
3039
public static String buildNewBugReportBody(
40+
final @NotNull Project project,
41+
final @NotNull String bugDescription,
42+
final @NotNull String stackTrace,
43+
final int maxAllowedBodyLength
44+
) {
45+
final int maxAllowedStackTraceLength = getMaxAllowedStackTraceLength(
46+
project,
47+
bugDescription,
48+
maxAllowedBodyLength
49+
);
50+
51+
if (encode(stackTrace).length() <= maxAllowedStackTraceLength) {
52+
return buildTemplate(project, bugDescription, stackTrace);
53+
}
54+
55+
final String cutStackTrace = encode(stackTrace).substring(
56+
0,
57+
maxAllowedStackTraceLength - 1
58+
);
59+
60+
return buildTemplate(project, bugDescription, decode(cutStackTrace));
61+
}
62+
63+
/**
64+
* Build bug report body template.
65+
*
66+
* @param project Project
67+
* @param bugDescription String
68+
* @param stackTrace String
69+
*
70+
* @return String
71+
*/
72+
private static String buildTemplate(
3173
final @NotNull Project project,
3274
final @NotNull String bugDescription,
3375
final @NotNull String stackTrace
@@ -39,11 +81,85 @@ public static String buildNewBugReportBody(
3981
final Properties properties = new Properties();
4082
properties.setProperty("BUG_DESCRIPTION", bugDescription);
4183
properties.setProperty("STACK_TRACE", stackTrace);
84+
properties.setProperty("OS_VERSION", getOsVersion());
85+
properties.setProperty("INTELLIJ_VERSION", getIntellijVersion());
86+
properties.setProperty("PLUGIN_VERSION", getPluginVersion());
4287

4388
try {
4489
return errorReportTemplate.getText(properties);
4590
} catch (IOException exception) {
4691
return "";
4792
}
4893
}
94+
95+
/**
96+
* Get max allowed stacktrace length.
97+
*
98+
* @param project Project
99+
* @param bugDescription String
100+
* @param maxAllowedBodyLength String
101+
*
102+
* @return int
103+
*/
104+
private static int getMaxAllowedStackTraceLength(
105+
final @NotNull Project project,
106+
final @NotNull String bugDescription,
107+
final int maxAllowedBodyLength
108+
) {
109+
final String builtTemplateWithoutStackTrace = buildTemplate(project, bugDescription, "");
110+
111+
return maxAllowedBodyLength - encode(builtTemplateWithoutStackTrace).length();
112+
}
113+
114+
/**
115+
* Encode string to be used in URI.
116+
*
117+
* @param value String
118+
*
119+
* @return String
120+
*/
121+
private static String encode(final @NotNull String value) {
122+
return URLEncoder.encode(value, StandardCharsets.UTF_8);
123+
}
124+
125+
/**
126+
* Decode string that was encoded to be used in URI.
127+
*
128+
* @param value String
129+
*
130+
* @return String
131+
*/
132+
private static String decode(final @NotNull String value) {
133+
return URLDecoder.decode(value, StandardCharsets.UTF_8);
134+
}
135+
136+
/**
137+
* Get OS version.
138+
*
139+
* @return String
140+
*/
141+
private static String getOsVersion() {
142+
return SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION;
143+
}
144+
145+
/**
146+
* Get Intellij Idea version.
147+
*
148+
* @return String
149+
*/
150+
private static String getIntellijVersion() {
151+
return ApplicationInfo.getInstance().getFullVersion();
152+
}
153+
154+
/**
155+
* Get plugin version.
156+
*
157+
* @return String
158+
*/
159+
private static String getPluginVersion() {
160+
final IdeaPluginDescriptor magento2pluginDescriptor =
161+
PluginManagerCore.getPlugin(PluginId.getId("com.magento.idea.magento2plugin"));
162+
163+
return magento2pluginDescriptor == null ? null : magento2pluginDescriptor.getVersion();
164+
}
49165
}

src/com/magento/idea/magento2plugin/project/diagnostic/github/GitHubNewIssueUrlBuilderUtil.java

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package com.magento.idea.magento2plugin.project.diagnostic.github;
77

8+
import com.intellij.openapi.project.Project;
89
import java.net.URLEncoder;
910
import java.nio.charset.StandardCharsets;
1011
import org.jetbrains.annotations.NotNull;
@@ -14,26 +15,67 @@ public final class GitHubNewIssueUrlBuilderUtil {
1415
private static final String NEW_BUG_ISSUE_BASE_URL = "https://github.com/magento/"
1516
+ "magento2-phpstorm-plugin/issues/new"
1617
+ "?assignees=&labels=bug&template=bug_report.md";
18+
private static final String URI_PARAMS_PART = "&title=%title&body=%body";
19+
private static final int MAX_URI_LENGTH = 8000;
1720

1821
private GitHubNewIssueUrlBuilderUtil() {}
1922

2023
/**
2124
* Build new issue url (template -> bug_report).
2225
*
2326
* @param title String
24-
* @param body String
27+
* @param bugDescription String
28+
* @param stackTrace String
29+
* @param project Project
2530
*
2631
* @return String
2732
*/
2833
public static String buildNewBugIssueUrl(
34+
final @NotNull String title,
35+
final @NotNull String bugDescription,
36+
final @NotNull String stackTrace,
37+
final @NotNull Project project
38+
) {
39+
final String bugReportBody = GitHubNewIssueBodyBuilderUtil.buildNewBugReportBody(
40+
project,
41+
bugDescription,
42+
stackTrace,
43+
getAllowedBodyLength(title)
44+
);
45+
46+
return formatNewBugIssueUrl(title, bugReportBody);
47+
}
48+
49+
/**
50+
* Format URL with encoded url parameters.
51+
*
52+
* @param title String
53+
* @param body String
54+
*
55+
* @return String
56+
*/
57+
private static String formatNewBugIssueUrl(
2958
final @NotNull String title,
3059
final @NotNull String body
3160
) {
3261
final String encodedTitle = URLEncoder.encode(title, StandardCharsets.UTF_8);
3362
final String encodedBody = URLEncoder.encode(body, StandardCharsets.UTF_8);
3463

35-
return NEW_BUG_ISSUE_BASE_URL
36-
.concat("&title=" + encodedTitle)
37-
.concat("&body=" + encodedBody);
64+
final String paramsPart = URI_PARAMS_PART
65+
.replace("%title", encodedTitle)
66+
.replace("%body", encodedBody);
67+
68+
return NEW_BUG_ISSUE_BASE_URL.concat(paramsPart);
69+
}
70+
71+
/**
72+
* Calculate max allowed body length.
73+
*
74+
* @param title String
75+
*
76+
* @return int
77+
*/
78+
private static int getAllowedBodyLength(final @NotNull String title) {
79+
return MAX_URI_LENGTH - formatNewBugIssueUrl(title, "").length();
3880
}
3981
}

0 commit comments

Comments
 (0)