Refactor GerritClientBase class
Extracted the basic ClientBase class from GerritClientBase, enabling
client classes requiring only essential functionalities to inherit from
ClientBase rather than GerritClientBase.
Jira-Id: IT-103
Change-Id: I98b0d52dac17b1ae04fd49ac161a71a692a04e8a
Signed-off-by: Patrizio <patrizio.gelosi@amarulasolutions.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/ClientBase.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/ClientBase.java
new file mode 100644
index 0000000..6774c06
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/ClientBase.java
@@ -0,0 +1,14 @@
+package com.googlesource.gerrit.plugins.chatgpt.client;
+
+import com.google.gson.Gson;
+import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
+
+public abstract class ClientBase {
+ protected final Gson gson = new Gson();
+ protected Configuration config;
+
+ public ClientBase(Configuration config) {
+ this.config = config;
+ }
+
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/chatgpt/ChatGptTools.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/chatgpt/ChatGptTools.java
index 50147b3..a5fed22 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/chatgpt/ChatGptTools.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/chatgpt/ChatGptTools.java
@@ -1,6 +1,6 @@
package com.googlesource.gerrit.plugins.chatgpt.client.chatgpt;
-import com.google.gson.Gson;
+import com.googlesource.gerrit.plugins.chatgpt.client.ClientBase;
import com.googlesource.gerrit.plugins.chatgpt.client.model.chatGpt.ChatGptRequest;
import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
import com.googlesource.gerrit.plugins.chatgpt.utils.FileUtils;
@@ -8,14 +8,11 @@
import java.io.IOException;
import java.io.InputStreamReader;
-class ChatGptTools {
-
- private final Gson gson = new Gson();
- private final Configuration config;
+class ChatGptTools extends ClientBase {
private final boolean isCommentEvent;
public ChatGptTools(Configuration config, Boolean isCommentEvent) {
- this.config = config;
+ super(config);
this.isCommentEvent = isCommentEvent;
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/gerrit/GerritClientBase.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/gerrit/GerritClientBase.java
index 057be7b..51d19ce 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/gerrit/GerritClientBase.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/gerrit/GerritClientBase.java
@@ -1,9 +1,9 @@
package com.googlesource.gerrit.plugins.chatgpt.client.gerrit;
import com.google.common.net.HttpHeaders;
-import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
+import com.googlesource.gerrit.plugins.chatgpt.client.ClientBase;
import com.googlesource.gerrit.plugins.chatgpt.client.FileDiffProcessed;
import com.googlesource.gerrit.plugins.chatgpt.client.HttpClientWithRetry;
import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
@@ -21,15 +21,13 @@
@Slf4j
-public class GerritClientBase {
- protected final Gson gson = new Gson();
+public abstract class GerritClientBase extends ClientBase {
protected final HttpClientWithRetry httpClientWithRetry = new HttpClientWithRetry();
@Getter
protected HashMap<String, FileDiffProcessed> fileDiffsProcessed = new HashMap<>();
- protected Configuration config;
public GerritClientBase(Configuration config) {
- this.config = config;
+ super(config);
}
protected String generateBasicAuth(String username, String password) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/gerrit/GerritClientDetail.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/gerrit/GerritClientDetail.java
index eada99a..cdc5378 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/gerrit/GerritClientDetail.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/gerrit/GerritClientDetail.java
@@ -9,7 +9,7 @@
import java.util.List;
@Slf4j
-public class GerritClientDetail extends GerritClientAccount {
+public class GerritClientDetail extends GerritClientBase {
private final Integer gptAccountId;
public GerritClientDetail(Configuration config, Integer gptAccountId) {