Add ReviewCommitMessages config option

Added option `gptReviewCommitMessages` to verify if the commit message
matches with patchset changes.

Jira-Id: IT-103
Change-Id: I7d7244b7ada7d652e302190269c85f6125385dac
Signed-off-by: Patrizio <patrizio.gelosi@amarulasolutions.com>
diff --git a/README.md b/README.md
index e1986ac..3c1df9a 100644
--- a/README.md
+++ b/README.md
@@ -197,6 +197,8 @@
   your preferred prompt.
 - `gptTemperature`: The default value is 1. What sampling temperature to use, between 0 and 2. Higher values like 0.8
   will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
+- `gptReviewCommitMessages`: The default value is false. When enabled by setting to true, this option also verifies if
+  the commit message matches with the content of the review.
 - `gptStreamOutput`: The default value is true. Whether the response is expected in stream output mode or not.
 - `patchSetReduction`: The default value is false. If set to true, the plugin will attempt to reduce patch content by
   compressing redundant blank lines, tabs, import statements, etc., in order to decrease the token count.
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/GerritClient.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/GerritClient.java
index 205a29e..ce1e28f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/GerritClient.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/GerritClient.java
@@ -49,7 +49,7 @@
         List<String> files = new ArrayList<>();
         for (Map.Entry<String, Map<String, String>> file : map.entrySet()) {
             String filename = file.getKey();
-            if (!filename.equals("/COMMIT_MSG")) {
+            if (!filename.equals("/COMMIT_MSG") || config.getGptReviewCommitMessages()) {
                 Integer size = Integer.valueOf(file.getValue().get("size"));
                 if (size > config.getMaxReviewFileSize()) {
                     log.info("File '{}' not reviewed because its size exceeds the fixed maximum allowable size.",
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/UriResourceLocator.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/UriResourceLocator.java
index 6041726..a541777 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/UriResourceLocator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/client/UriResourceLocator.java
@@ -1,5 +1,9 @@
 package com.googlesource.gerrit.plugins.chatgpt.client;
 
+import java.net.URLEncoder;
+import java.io.UnsupportedEncodingException;
+
+
 public class UriResourceLocator {
 
     private UriResourceLocator() {
@@ -11,7 +15,11 @@
     }
 
     public static String gerritDiffPostfixUri(String filename) {
-        return "/" + filename + "/diff";
+        try {
+            return "/" + URLEncoder.encode(filename, "UTF-8") + "/diff";
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException(e.getCause());
+        }
     }
 
     public static String gerritPatchSetFilesUri(String fullChangeId) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/config/Configuration.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/config/Configuration.java
index 2a000c7..5a3353e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/config/Configuration.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/config/Configuration.java
@@ -14,9 +14,12 @@
     public static final String DEFAULT_GPT_PROMPT = "Act as a Code Review Helper. Review only the \"a\" (lines " +
             "removed) and \"b\" (lines added) items of the following diff, using the lines in the \"ab\" items as " +
             "context. ";
+    public static final String DEFAULT_GPT_COMMIT_MESSAGES_REVIEW_PROMPT = "Also, check if the content of the commit " +
+            "message in the \"/COMMIT_MSG\" item matches with the changes. ";
     public static final String NOT_CONFIGURED_ERROR_MSG = "%s is not configured";
     public static final String KEY_GPT_PROMPT = "gptPrompt";
     private static final String DEFAULT_GPT_TEMPERATURE = "1";
+    private static final boolean DEFAULT_REVIEW_COMMIT_MESSAGES = false;
     private static final boolean DEFAULT_STREAM_OUTPUT = true;
     private static final boolean DEFAULT_GLOBAL_ENABLE = false;
     private static final String DEFAULT_ENABLED_PROJECTS = "";
@@ -32,6 +35,7 @@
     private static final String KEY_GPT_MODEL = "gptModel";
     private static final String KEY_GPT_TEMPERATURE = "gptTemperature";
     private static final String KEY_STREAM_OUTPUT = "gptStreamOutput";
+    private static final String KEY_REVIEW_COMMIT_MESSAGES = "gptReviewCommitMessages";
     private static final String KEY_PROJECT_ENABLE = "isEnabled";
     private static final String KEY_GLOBAL_ENABLE = "globalEnable";
     private static final String KEY_ENABLED_PROJECTS = "enabledProjects";
@@ -76,16 +80,27 @@
     }
 
     public String getGptPrompt() {
+        String prompt;
         if (configsDynamically.get(KEY_GPT_PROMPT) != null) {
-            return configsDynamically.get(KEY_GPT_PROMPT).toString();
+            prompt = configsDynamically.get(KEY_GPT_PROMPT).toString();
         }
-        return getString(KEY_GPT_PROMPT, DEFAULT_GPT_PROMPT);
+        else {
+            prompt = getString(KEY_GPT_PROMPT, DEFAULT_GPT_PROMPT);
+            if (getGptReviewCommitMessages()) {
+                prompt += DEFAULT_GPT_COMMIT_MESSAGES_REVIEW_PROMPT;
+            }
+        }
+        return prompt;
     }
 
     public double getGptTemperature() {
         return Double.parseDouble(getString(KEY_GPT_TEMPERATURE, DEFAULT_GPT_TEMPERATURE));
     }
 
+    public boolean getGptReviewCommitMessages() {
+        return getBoolean(KEY_REVIEW_COMMIT_MESSAGES, DEFAULT_REVIEW_COMMIT_MESSAGES);
+    }
+
     public boolean getGptStreamOutput() {
         return getBoolean(KEY_STREAM_OUTPUT, DEFAULT_STREAM_OUTPUT);
     }