Enhance code conciseness
Boosted the conciseness of the code through the utilization of default
Lombok getters and setters.
Jira-Id: IT-103
Change-Id: I6086732da41bf15f4aa2f5e7d46afe595736d015
Signed-off-by: Patrizio <patrizio.gelosi@amarulasolutions.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java
index 6bbb579..1a5df35 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java
@@ -12,6 +12,7 @@
import com.googlesource.gerrit.plugins.chatgpt.client.model.FileDiffProcessed;
import com.googlesource.gerrit.plugins.chatgpt.client.model.GerritCommentRange;
import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
+import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import java.lang.reflect.Type;
@@ -32,6 +33,7 @@
private List<HashMap<String, Object>> reviewBatches;
private List<JsonObject> commentProperties;
private HashMap<String, FileDiffProcessed> fileDiffsProcessed;
+ @Setter
private boolean isCommentEvent;
@Inject
@@ -62,10 +64,6 @@
gerritClient.postComments(fullChangeId, reviewBatches);
}
- public void setIsCommentEvent(boolean isCommentEvent) {
- this.isCommentEvent = isCommentEvent;
- }
-
private Integer getBatchId(String currentTag) {
try {
return Integer.parseInt(currentTag);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/GerritClientBase.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/GerritClientBase.java
index 884897f..a1534eb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/GerritClientBase.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/GerritClientBase.java
@@ -6,6 +6,7 @@
import com.google.gson.JsonObject;
import com.googlesource.gerrit.plugins.chatgpt.client.model.FileDiffProcessed;
import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
+import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
@@ -22,6 +23,7 @@
public class GerritClientBase {
protected final Gson gson = new Gson();
protected final HttpClientWithRetry httpClientWithRetry = new HttpClientWithRetry();
+ @Getter
protected HashMap<String, FileDiffProcessed> fileDiffsProcessed;
protected Configuration config;
@@ -65,8 +67,4 @@
return gson.fromJson(responseBody, JsonObject.class);
}
- public HashMap<String, FileDiffProcessed> getFileDiffsProcessed() {
- return fileDiffsProcessed;
- }
-
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/GerritClientComments.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/GerritClientComments.java
index 1126572..cb3ad65 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/GerritClientComments.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/GerritClientComments.java
@@ -10,6 +10,7 @@
import com.googlesource.gerrit.plugins.chatgpt.client.model.ChatGptRequestPoint;
import com.googlesource.gerrit.plugins.chatgpt.client.model.FileDiffProcessed;
import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
+import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.entity.ContentType;
@@ -34,6 +35,7 @@
private final Gson gson = new Gson();
private long commentsStartTimestamp;
private String authorUsername;
+ @Getter
protected List<JsonObject> commentProperties;
public GerritClientComments(Configuration config) {
@@ -172,10 +174,6 @@
return requestPoint;
}
- public List<JsonObject> getCommentProperties() {
- return commentProperties;
- }
-
public boolean retrieveLastComments(Event event, String fullChangeId) {
commentsStartTimestamp = event.eventCreatedOn;
CommentAddedEvent commentAddedEvent = (CommentAddedEvent) event;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/OpenAiClient.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/OpenAiClient.java
index 0f5183e..e9a5872 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/OpenAiClient.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/OpenAiClient.java
@@ -8,6 +8,7 @@
import com.googlesource.gerrit.plugins.chatgpt.client.model.ChatCompletionResponse;
import com.googlesource.gerrit.plugins.chatgpt.client.model.ChatCompletionResponseMessage;
import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
+import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.entity.ContentType;
@@ -23,6 +24,7 @@
@Slf4j
@Singleton
public class OpenAiClient {
+ @Getter
private String requestBody;
private final Gson gson = new GsonBuilder()
.disableHtmlEscaping()
@@ -30,10 +32,6 @@
private final HttpClientWithRetry httpClientWithRetry = new HttpClientWithRetry();
private boolean isCommentEvent = false;
- public String getRequestBody() {
- return requestBody;
- }
-
public String ask(Configuration config, String patchSet) throws Exception {
HttpRequest request = createRequest(config, patchSet);
log.debug("ChatGPT request: {}", request.toString());
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/listener/EventListenerHandler.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/listener/EventListenerHandler.java
index df12b59..a5fe208 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/listener/EventListenerHandler.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/listener/EventListenerHandler.java
@@ -14,6 +14,7 @@
import com.googlesource.gerrit.plugins.chatgpt.PatchSetReviewer;
import com.googlesource.gerrit.plugins.chatgpt.client.GerritClient;
import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
+import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import java.net.URLEncoder;
@@ -37,6 +38,7 @@
1, 1, 0L, TimeUnit.MILLISECONDS, queue, threadFactory, handler);
private final GerritClient gerritClient;
private Configuration config;
+ @Getter
private CompletableFuture<Void> latestFuture;
@Inject
@@ -149,14 +151,14 @@
if (!isPatchSetReviewEnabled(patchSetEvent)) {
return;
}
- reviewer.setIsCommentEvent(false);
+ reviewer.setCommentEvent(false);
break;
case "comment-added":
if (!gerritClient.retrieveLastComments(event, fullChangeId)) {
log.info("No comments found for review");
return;
}
- reviewer.setIsCommentEvent(true);
+ reviewer.setCommentEvent(true);
break;
default:
return;
@@ -177,8 +179,4 @@
}, executorService);
}
- public CompletableFuture<Void> getLatestFuture() {
- return latestFuture;
- }
-
}