Modified `review_last` command functionality
The `review_last` command no longer triggers vote casting or updates for
Patch Sets. This change is made because `review_last` is designed to
prompt ChatGPT to vote based solely on the latest Patch Set, whereas
votes are meant to reflect the entire Change Set.
Jira-Id: IT-103
Change-Id: If5ff56ee624fb8de61f761da85226991ef6eac20
Signed-off-by: Patrizio <patrizio.gelosi@amarulasolutions.com>
diff --git a/README.md b/README.md
index 176bcef..02fcc5b 100644
--- a/README.md
+++ b/README.md
@@ -163,9 +163,11 @@
## Commands
-- `/review`: when used in a comment directed at ChatGPT on any Change Set, triggers a review of the full Change Set.
+- `/review`: when used in a comment directed at ChatGPT on any Change Set, triggers a review of the full Change Set. A
+ vote is cast on the Change Set if the voting feature is enabled and the ChatGPT Gerrit user is authorized to vote on
+ it.
- `/review_last`: when used in a comment directed at ChatGPT on any Change Set, triggers a review of the last Patch Set
- of the Change Set.
+ of the Change Set. Unlike `/review`, this command does not result in casting or updating votes.
## Testing
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/DynamicSettings.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/DynamicSettings.java
index 97c9c6f..24ab123 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/DynamicSettings.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/DynamicSettings.java
@@ -19,4 +19,9 @@
private Integer votingMaxScore;
private Boolean forcedReview = false;
private Boolean forcedReviewChangeSet = false;
+
+ public Boolean getForcedReviewLastPatchSet() {
+ return forcedReview && !forcedReviewChangeSet;
+ }
+
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/chatgpt/ChatGptClient.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/chatgpt/ChatGptClient.java
index 5151a0b..5f406b7 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/chatgpt/ChatGptClient.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/chatgpt/ChatGptClient.java
@@ -124,7 +124,7 @@
.build();
List<ChatGptRequest.Message> messages = List.of(systemMessage, userMessage);
- ChatGptRequest tools = chatGptTools.retrieveTools();
+ ChatGptRequest tools = chatGptTools.retrieveTools(changeId);
ChatGptRequest chatGptRequest = ChatGptRequest.builder()
.model(config.getGptModel())
.messages(messages)
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 a5fed22..5839ecc 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,9 +1,11 @@
package com.googlesource.gerrit.plugins.chatgpt.client.chatgpt;
+import com.googlesource.gerrit.plugins.chatgpt.DynamicSettings;
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;
+import com.googlesource.gerrit.plugins.chatgpt.utils.SingletonManager;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -16,14 +18,15 @@
this.isCommentEvent = isCommentEvent;
}
- public ChatGptRequest retrieveTools() {
+ public ChatGptRequest retrieveTools(String changeId) {
ChatGptRequest tools;
try (InputStreamReader reader = FileUtils.getInputStreamReader("Config/tools.json")) {
tools = gson.fromJson(reader, ChatGptRequest.class);
} catch (IOException e) {
throw new RuntimeException("Failed to load ChatGPT request tools", e);
}
- if (!config.isVotingEnabled() || isCommentEvent) {
+ DynamicSettings dynamicSettings = SingletonManager.getInstance(DynamicSettings.class, changeId);
+ if (!config.isVotingEnabled() || isCommentEvent || dynamicSettings.getForcedReviewLastPatchSet()) {
removeScoreFromTools(tools);
}
return tools;