commit 3e36a4fd34018bdb72817a3e48b37e7e474e3806 Author: Tulis <79586741+Tulis12@users.noreply.github.com> Date: Fri Aug 1 21:55:59 2025 +0200 add: auto-add the 'duplicated' label diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..7bc07ec --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Environment-dependent path to Maven home directory +/mavenHomeManager.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a28d378 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..57543a0 --- /dev/null +++ b/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + + dev.tulis + TuliErrorer + 1.0-SNAPSHOT + + + 21 + 21 + UTF-8 + + + + + gitea + https://git.tulisiowice.top/api/packages/Tulis/maven + + + + + + gitea + https://git.tulisiowice.top/api/packages/Tulis/maven + + + gitea + https://git.tulisiowice.top/api/packages/Tulis/maven + + + \ No newline at end of file diff --git a/src/main/java/dev/tulis/errorer/Errorer.java b/src/main/java/dev/tulis/errorer/Errorer.java new file mode 100644 index 0000000..f70e251 --- /dev/null +++ b/src/main/java/dev/tulis/errorer/Errorer.java @@ -0,0 +1,102 @@ +package dev.tulis.errorer; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +public class Errorer { + String repoPath; + String token; + int labelId = 1; + + public Errorer(String repoPath, String token) { + this.repoPath = repoPath; + this.token = token; + } + + public Errorer(String repoPath, String token, int labelId) { + this.repoPath = repoPath; + this.token = token; + this.labelId = labelId; + } + + public void reportException(Exception e, Object o, String... additionalData) { + String stackTrace = getErrorStackTrace(e); + String className = o.getClass().getName(); + + ZonedDateTime warsawTime = ZonedDateTime.now(ZoneId.of("Europe/Warsaw")); + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z"); + String formattedTime = warsawTime.format(formatter); + + StringBuilder description = new StringBuilder("### Error stackTrace: \n```\n"); + 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()) { + String json = String.format(""" + { + "title": "%s", + "body": "%s", + "assignees": ["Tulis"], + "labels": [1] + } + """, e.getMessage() + " in " + className + " at " + formattedTime, description); + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("https://git.tulisiowice.top/api/v1/repos/" + repoPath + "/issues")) + .header("Content-Type", "application/json") + .header("Authorization", "token " + token) + .POST(HttpRequest.BodyPublishers.ofString(json)) + .build(); + + client.send(request, HttpResponse.BodyHandlers.ofString()); + } catch (IOException | InterruptedException ex) { + throw new RuntimeException(ex); + } + } + + private String getErrorStackTrace(Exception e) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + e.printStackTrace(pw); + + return sw.toString(); + } + + public String getRepoPath() { + return repoPath; + } + + public void setRepoPath(String repoPath) { + this.repoPath = repoPath; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public int getLabelId() { + return labelId; + } + + public void setLabelId(int labelId) { + this.labelId = labelId; + } +} \ No newline at end of file