add: auto-add the 'duplicated' label
This commit is contained in:
16
pom.xml
16
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>dev.tulis</groupId>
|
<groupId>dev.tulis</groupId>
|
||||||
<artifactId>TuliErrorer</artifactId>
|
<artifactId>TuliErrorer</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.1</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
@ -31,4 +31,18 @@
|
|||||||
<url>https://git.tulisiowice.top/api/packages/Tulis/maven</url>
|
<url>https://git.tulisiowice.top/api/packages/Tulis/maven</url>
|
||||||
</snapshotRepository>
|
</snapshotRepository>
|
||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-core</artifactId>
|
||||||
|
<version>2.19.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.19.2</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -1,60 +1,89 @@
|
|||||||
package dev.tulis.errorer;
|
package dev.tulis.errorer;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
import java.net.http.HttpRequest;
|
import java.net.http.HttpRequest;
|
||||||
import java.net.http.HttpResponse;
|
import java.net.http.HttpResponse;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class Errorer {
|
public class Errorer {
|
||||||
String repoPath;
|
String repoPath;
|
||||||
String token;
|
String token;
|
||||||
int labelId = 1;
|
int labelId = 1;
|
||||||
|
int duplicateId = 2;
|
||||||
|
String assignee = "Tulis";
|
||||||
|
|
||||||
public Errorer(String repoPath, String token) {
|
public Errorer(String repoPath, String token) {
|
||||||
this.repoPath = repoPath;
|
this.repoPath = repoPath;
|
||||||
this.token = token;
|
this.token = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Errorer(String repoPath, String token, int labelId) {
|
public static void main(String[] args) {
|
||||||
this.repoPath = repoPath;
|
try {
|
||||||
this.token = token;
|
int x = 2 / 0;
|
||||||
this.labelId = labelId;
|
} catch (ArithmeticException err) {
|
||||||
|
Errorer errorer = new Errorer("Tulis/TulisiowiceReload", "46290b1371c8d0fb021e559b1bb600f7e5b7691a");
|
||||||
|
errorer.reportException(err, errorer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reportException(Exception e, Object o, String... additionalData) {
|
public void reportException(Exception e, Object o, String... additionalData) {
|
||||||
String stackTrace = getErrorStackTrace(e);
|
String stackTrace = getErrorStackTrace(e);
|
||||||
String className = o.getClass().getName();
|
String className = o.getClass().getName();
|
||||||
|
String errorText = e.getClass().getName() + " in " + className;
|
||||||
|
|
||||||
ZonedDateTime warsawTime = ZonedDateTime.now(ZoneId.of("Europe/Warsaw"));
|
ZonedDateTime warsawTime = ZonedDateTime.now(ZoneId.of("Europe/Warsaw"));
|
||||||
|
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
|
||||||
String formattedTime = warsawTime.format(formatter);
|
String formattedTime = warsawTime.format(formatter);
|
||||||
|
|
||||||
StringBuilder description = new StringBuilder("### Error stackTrace: \n```\n");
|
StringBuilder description = getDescription(e, additionalData, stackTrace);
|
||||||
description.append(stackTrace);
|
|
||||||
description.append("```\n\n");
|
|
||||||
for(String str : additionalData) {
|
|
||||||
description.append(str);
|
|
||||||
if(!additionalData[additionalData.length - 1].equals(str)) description.append(" ");
|
|
||||||
}
|
|
||||||
if(additionalData.length != 0) description.append("\n");
|
|
||||||
description.append("Automatically reported by TuliErrorer");
|
|
||||||
|
|
||||||
try(HttpClient client = HttpClient.newHttpClient()) {
|
try(HttpClient client = HttpClient.newHttpClient()) {
|
||||||
|
boolean isDuplicate = false;
|
||||||
|
|
||||||
|
{
|
||||||
|
HttpRequest request = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create(String.format("https://git.tulisiowice.top/api/v1/repos/%s/issues?q=%s", repoPath, URLEncoder.encode(errorText, StandardCharsets.UTF_8))))
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.header("Authorization", "token " + token)
|
||||||
|
.GET()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
|
String str = response.body();
|
||||||
|
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
|
JsonNode rootNode = mapper.readTree(str);
|
||||||
|
JsonNode emailNode = rootNode.at("/0");
|
||||||
|
if (!emailNode.isMissingNode()) isDuplicate = true;
|
||||||
|
}
|
||||||
|
|
||||||
String json = String.format("""
|
String json = String.format("""
|
||||||
{
|
{
|
||||||
"title": "%s",
|
"title": "%s",
|
||||||
"body": "%s",
|
"body": "%s",
|
||||||
"assignees": ["Tulis"],
|
"assignees": ["%s"],
|
||||||
"labels": [1]
|
"labels": [%s]
|
||||||
}
|
}
|
||||||
""", e.getMessage() + " in " + className + " at " + formattedTime, description);
|
""",
|
||||||
|
String.format("%s %s", errorText, formattedTime),
|
||||||
|
description,
|
||||||
|
assignee,
|
||||||
|
(isDuplicate) ? labelId + ", " + duplicateId : labelId);
|
||||||
|
|
||||||
HttpRequest request = HttpRequest.newBuilder()
|
HttpRequest request = HttpRequest.newBuilder()
|
||||||
.uri(URI.create("https://git.tulisiowice.top/api/v1/repos/" + repoPath + "/issues"))
|
.uri(URI.create("https://git.tulisiowice.top/api/v1/repos/" + repoPath + "/issues"))
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
@ -68,6 +97,21 @@ public class Errorer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static StringBuilder getDescription(Exception e, String[] additionalData, String stackTrace) {
|
||||||
|
StringBuilder description = new StringBuilder(String.format("###%s Error stackTrace: \n```\n", (e.getMessage() == null) ? "" : String.format(" [%s]", e.getMessage())));
|
||||||
|
description.append(stackTrace);
|
||||||
|
description.append("```\n\n");
|
||||||
|
|
||||||
|
for(String str : additionalData) {
|
||||||
|
description.append(str);
|
||||||
|
if(!additionalData[additionalData.length - 1].equals(str)) description.append(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(additionalData.length != 0) description.append("\n");
|
||||||
|
description.append("Automatically reported by TuliErrorer");
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
private String getErrorStackTrace(Exception e) {
|
private String getErrorStackTrace(Exception e) {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
@ -76,6 +120,22 @@ public class Errorer {
|
|||||||
return sw.toString();
|
return sw.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getAssignee() {
|
||||||
|
return assignee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAssignee(String assignee) {
|
||||||
|
this.assignee = assignee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDuplicateId() {
|
||||||
|
return duplicateId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDuplicateId(int duplicateId) {
|
||||||
|
this.duplicateId = duplicateId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getRepoPath() {
|
public String getRepoPath() {
|
||||||
return repoPath;
|
return repoPath;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user