Skip to content

Commit 19a1a36

Browse files
authored
Merge pull request #653 from SeeSharpSoft/main
Release 3.2.3
2 parents d705a95 + d2155b8 commit 19a1a36

File tree

4 files changed

+74
-7
lines changed

4 files changed

+74
-7
lines changed

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
3.2.3
2+
Nov 05, 2023
3+
4+
NEW: Prevent github issue submitter spam
5+
FIX: Improve issue duplicate finder
6+
17
3.2.2
28
Oct 14, 2023
39

build.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ var final DEFAULT_VERSION = '2022.2.1' //'LATEST-EAP-SNAPSHOT' //
7575
var idea_version = System.getenv().getOrDefault('IDEA_VERSION', DEFAULT_VERSION)
7676
var build_version = idea_version == EAP_VERSION ? EAP_BUILD : idea_version.substring(2, 4) + idea_version.charAt(5) // extract e.g. '221' from '2022.1.1'
7777

78-
version '3.2.2-' + build_version
78+
version '3.2.3-' + build_version
7979

8080
apply plugin: 'org.jetbrains.intellij'
8181
intellij {
@@ -96,10 +96,8 @@ patchPluginXml {
9696
sinceBuild = build_version
9797

9898
changeNotes = """<pre style="font-family: sans-serif">
99-
FIX: NullPointerException: Cannot invoke "getSelectedColumn()" because "tblEditor" is null #519
100-
FIX: IllegalStateException: Attempt to modify PSI for non-committed Document! #516
101-
FIX: StringIndexOutOfBoundsException: begin 0, end -1, length 5995 #511
102-
FIX: ArrayIndexOutOfBoundsException: 12 >= 12 #482
99+
NEW: Prevent github issue submitter spam
100+
FIX: Improve issue duplicate finder
103101
</pre>"""
104102
}
105103
publishPlugin {

src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvGithubIssueSubmitter.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
import java.awt.*;
2626
import java.io.IOException;
2727
import java.util.Collections;
28+
import java.util.concurrent.Executors;
29+
import java.util.concurrent.ScheduledExecutorService;
30+
import java.util.concurrent.ScheduledFuture;
31+
import java.util.concurrent.TimeUnit;
2832

2933
public class CsvGithubIssueSubmitter extends ErrorReportSubmitter {
3034

@@ -34,6 +38,9 @@ public class CsvGithubIssueSubmitter extends ErrorReportSubmitter {
3438
public static final String GIT_REPO = "intellij-csv-validator";
3539
public static final GHRepositoryPath GITHUB_FULL_PATH = new GHRepositoryPath(GIT_USER, GIT_REPO);
3640

41+
private static ScheduledFuture recentlySentReport = null;
42+
private static ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
43+
3744
private static class CsvGithubSubmitException extends RuntimeException {
3845
CsvGithubSubmitException(Throwable exception) {
3946
super(exception);
@@ -47,7 +54,9 @@ public String getReportActionText() {
4754
}
4855

4956
@Override
50-
public boolean submit(IdeaLoggingEvent @NotNull [] events, @Nullable String additionalInfo, @NotNull Component parentComponent, @NotNull Consumer<? super SubmittedReportInfo> consumer) {
57+
public synchronized boolean submit(IdeaLoggingEvent @NotNull [] events, @Nullable String additionalInfo, @NotNull Component parentComponent, @NotNull Consumer<? super SubmittedReportInfo> consumer) {
58+
if (reportWasRecentlySent()) return true;
59+
5160
final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);
5261
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
5362

@@ -56,9 +65,19 @@ public boolean submit(IdeaLoggingEvent @NotNull [] events, @Nullable String addi
5665
return false;
5766
}
5867
}
68+
69+
reportWasSent();
5970
return true;
6071
}
6172

73+
protected void reportWasSent() {
74+
recentlySentReport = executorService.schedule(() -> { recentlySentReport = null; }, 15, TimeUnit.MINUTES);
75+
}
76+
77+
protected boolean reportWasRecentlySent() {
78+
return recentlySentReport != null;
79+
}
80+
6281
protected boolean submit(IdeaLoggingEvent event, String additionalInfo, Project project, Consumer<? super SubmittedReportInfo> consumer) {
6382
GithubAuthenticationManager githubAuthManager = GithubAuthenticationManager.getInstance();
6483
if (!githubAuthManager.ensureHasAccounts(project)) {
@@ -172,7 +191,8 @@ protected int getIssueTitleCutIndex(String throwableTextArg) {
172191
protected String getIssueTitle(IdeaLoggingEvent event) {
173192
String throwableText = event.getThrowableText();
174193
int index = getIssueTitleCutIndex(throwableText);
175-
return "[Automated Report] " + event.getThrowableText().substring(0, index);
194+
String issueTitle = throwableText.substring(0, index).replaceAll("@[0-9a-fA-F]+", "");
195+
return "[Automated Report] " + issueTitle;
176196
}
177197

178198
protected String getIssueDetails(IdeaLoggingEvent event, String additionalInfo) {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package net.seesharpsoft.intellij.plugins.csv;
2+
3+
import com.intellij.openapi.diagnostic.IdeaLoggingEvent;
4+
import com.intellij.testFramework.UsefulTestCase;
5+
6+
import java.io.PrintStream;
7+
import java.io.PrintWriter;
8+
9+
public class CsvGithubIssueSubmitterTest extends UsefulTestCase {
10+
11+
// for accessing protected methods during test
12+
class CsvGithubIssueSubmitterSubClass extends CsvGithubIssueSubmitter {
13+
}
14+
15+
class DummyException extends Throwable {
16+
public DummyException(String message) {
17+
super(message);
18+
}
19+
20+
public void printStackTrace(PrintStream stream) {
21+
stream.println(this.getMessage());
22+
}
23+
24+
public void printStackTrace(PrintWriter writer) {
25+
writer.println(this.getMessage());
26+
}
27+
}
28+
29+
private CsvGithubIssueSubmitterSubClass classUnderTest = new CsvGithubIssueSubmitterSubClass();
30+
31+
public void testGetIssueTitle() {
32+
assertEquals("[Automated Report] Test", classUnderTest.getIssueTitle(new IdeaLoggingEvent("Test", new DummyException("Test"))));
33+
assertEquals("[Automated Report] Unhandled exception in [CoroutineName(com.intellij.openapi.fileEditor.impl.PsiAwareFileEditorManagerImpl), StandaloneCoroutine{Cancelling}, Dispatchers.Default]", classUnderTest.getIssueTitle(new IdeaLoggingEvent("Test", new DummyException("Unhandled exception in [CoroutineName(com.intellij.openapi.fileEditor.impl.PsiAwareFileEditorManagerImpl), StandaloneCoroutine{Cancelling}@5cfe3e69, Dispatchers.Default]"))));
34+
assertEquals("[Automated Report] An invalid state was detected that occurs if the key's equals or hashCode was modified while it resided in the cache. This violation of the Map contract can lead to non-deterministic behavior (key: com.intellij.psi.impl.ElementBase$ElementIconRequest, key type: ElementIconRequest, node type: PSMS, cache type: SSMS).",
35+
classUnderTest.getIssueTitle(new IdeaLoggingEvent("", new DummyException("An invalid state was detected that occurs if the key's equals or hashCode was modified while it resided in the cache. This violation of the Map contract can lead to non-deterministic behavior (key: com.intellij.psi.impl.ElementBase$ElementIconRequest@e2330a, key type: ElementIconRequest, node type: PSMS, cache type: SSMS)."))));
36+
}
37+
38+
public void testRecentSent() {
39+
assertEquals(false, classUnderTest.reportWasRecentlySent());
40+
classUnderTest.reportWasSent();
41+
assertEquals(true, classUnderTest.reportWasRecentlySent());
42+
}
43+
}

0 commit comments

Comments
 (0)