From 439c8dca623c9f62607928fbfbba492f5d83f394 Mon Sep 17 00:00:00 2001 From: Suraj Kumar Date: Wed, 29 May 2024 14:23:46 +0100 Subject: [PATCH] Add Qodana GHA and fixes --- .github/workflows/qodana_code_quality.yml | 20 ++++++++++++ .../jdi/core/api/AutoModerationRequest.java | 2 +- .../CreateAutoModerationRuleBuilder.java | 2 +- .../bot/utils/chatgpt/ChatGPT.java | 4 +-- .../utils/chatgpt/ChatGPTResponseParser.java | 2 +- qodana.yaml | 31 +++++++++++++++++++ 6 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/qodana_code_quality.yml create mode 100644 qodana.yaml diff --git a/.github/workflows/qodana_code_quality.yml b/.github/workflows/qodana_code_quality.yml new file mode 100644 index 00000000..7d7af59f --- /dev/null +++ b/.github/workflows/qodana_code_quality.yml @@ -0,0 +1,20 @@ +name: Qodana +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + - slash-commands + +jobs: + qodana: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: 'Qodana Scan' + uses: JetBrains/qodana-action@v2024.1 + env: + QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} \ No newline at end of file diff --git a/api/src/main/java/com/javadiscord/jdi/core/api/AutoModerationRequest.java b/api/src/main/java/com/javadiscord/jdi/core/api/AutoModerationRequest.java index b6d30fd8..f47fdc79 100644 --- a/api/src/main/java/com/javadiscord/jdi/core/api/AutoModerationRequest.java +++ b/api/src/main/java/com/javadiscord/jdi/core/api/AutoModerationRequest.java @@ -2,9 +2,9 @@ import java.util.List; +import com.javadiscord.jdi.core.api.builders.CreateAutoModerationRuleBuilder; import com.javadiscord.jdi.core.api.builders.ModifyAutoModerationRuleBuilder; import com.javadiscord.jdi.core.models.auto_moderation.AutoModerationRule; -import com.javadiscord.jdi.core.request.builders.CreateAutoModerationRuleBuilder; import com.javadiscord.jdi.internal.api.auto_moderation.*; public class AutoModerationRequest { diff --git a/api/src/main/java/com/javadiscord/jdi/core/api/builders/CreateAutoModerationRuleBuilder.java b/api/src/main/java/com/javadiscord/jdi/core/api/builders/CreateAutoModerationRuleBuilder.java index 9d64000e..0258c855 100644 --- a/api/src/main/java/com/javadiscord/jdi/core/api/builders/CreateAutoModerationRuleBuilder.java +++ b/api/src/main/java/com/javadiscord/jdi/core/api/builders/CreateAutoModerationRuleBuilder.java @@ -1,4 +1,4 @@ -package com.javadiscord.jdi.core.request.builders; +package com.javadiscord.jdi.core.api.builders; import java.util.List; import java.util.Optional; diff --git a/example/lj-discord-bot/src/main/java/com/javadiscord/bot/utils/chatgpt/ChatGPT.java b/example/lj-discord-bot/src/main/java/com/javadiscord/bot/utils/chatgpt/ChatGPT.java index 59c38324..3ee1fce6 100644 --- a/example/lj-discord-bot/src/main/java/com/javadiscord/bot/utils/chatgpt/ChatGPT.java +++ b/example/lj-discord-bot/src/main/java/com/javadiscord/bot/utils/chatgpt/ChatGPT.java @@ -104,9 +104,9 @@ public Optional ask(String question) { openAiHttpException.statusCode ) ); - } catch (RuntimeException runtimeException) { + } catch (RuntimeException e) { logger.warn( - "There was an error using the OpenAI API: " + runtimeException.getMessage() + "There was an error using the OpenAI API: {}", e.getMessage() ); } return Optional.empty(); diff --git a/example/lj-discord-bot/src/main/java/com/javadiscord/bot/utils/chatgpt/ChatGPTResponseParser.java b/example/lj-discord-bot/src/main/java/com/javadiscord/bot/utils/chatgpt/ChatGPTResponseParser.java index 1b88f643..1095c559 100644 --- a/example/lj-discord-bot/src/main/java/com/javadiscord/bot/utils/chatgpt/ChatGPTResponseParser.java +++ b/example/lj-discord-bot/src/main/java/com/javadiscord/bot/utils/chatgpt/ChatGPTResponseParser.java @@ -15,7 +15,7 @@ private ChatGPTResponseParser() {} public static String[] parse(String response) { String[] partedResponse = new String[] {response}; if (response.length() > RESPONSE_LENGTH_LIMIT) { - logger.debug("Response to parse:\n" + response); + logger.debug("Response to parse:\n{}", response); partedResponse = partitionAiResponse(response); } return partedResponse; diff --git a/qodana.yaml b/qodana.yaml new file mode 100644 index 00000000..ebc500e0 --- /dev/null +++ b/qodana.yaml @@ -0,0 +1,31 @@ +#-------------------------------------------------------------------------------# +# Qodana analysis is configured by qodana.yaml file # +# https://www.jetbrains.com/help/qodana/qodana-yaml.html # +#-------------------------------------------------------------------------------# +version: "1.0" + +#Specify inspection profile for code analysis +profile: + name: qodana.starter + +#Enable inspections +#include: +# - name: + +#Disable inspections +#exclude: +# - name: +# paths: +# - + +projectJDK: 21 #(Applied in CI/CD pipeline) + +#Execute shell command before Qodana execution (Applied in CI/CD pipeline) +#bootstrap: sh ./prepare-qodana.sh + +#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline) +#plugins: +# - id: #(plugin id can be found at https://plugins.jetbrains.com) + +#Specify Qodana linter for analysis (Applied in CI/CD pipeline) +linter: jetbrains/qodana-jvm:latest