Refactor Configuration class

- Organized class constants into meaningful groups, each accompanied by
explanatory comments.
- Updated several constants and methods to more descriptive names for
enhanced clarity.

Jira-Id: IT-103
Change-Id: I5ad2cb0062f91601094ac773bbbc04a53092fa3d
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 0d333fa..38a1590 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java
@@ -43,7 +43,8 @@
             log.info("No file to review has been found in the PatchSet");
             return;
         }
-        config.configureDynamically(Configuration.KEY_GPT_USER_PROMPT, gerritClient.getUserRequests(fullChangeId));
+        config.configureDynamically(Configuration.KEY_GPT_REQUEST_USER_PROMPT,
+                gerritClient.getUserRequests(fullChangeId));
         config.configureDynamically(Configuration.KEY_COMMENT_PROPERTIES_SIZE, commentProperties.size());
 
         String reviewReply = getReviewReply(config, fullChangeId, patchSet);
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 924e289..6f28cdd 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
@@ -15,30 +15,18 @@
 
 @Slf4j
 public class Configuration {
-    public static final String OPENAI_DOMAIN = "https://api.openai.com";
-    public static final String DEFAULT_GPT_MODEL = "gpt-3.5-turbo";
-    public static final String NOT_CONFIGURED_ERROR_MSG = "%s is not configured";
-    public static final String KEY_GPT_SYSTEM_PROMPT = "gptSystemPrompt";
-    public static final String KEY_GPT_USER_PROMPT = "gptUserPrompt";
-    public static final String KEY_COMMENT_PROPERTIES_SIZE = "commentPropertiesSize";
     public static final String ENABLED_USERS_ALL = "ALL";
     public static final String ENABLED_GROUPS_ALL = "ALL";
     public static final String ENABLED_TOPICS_ALL = "ALL";
     public static final String SPACE = " ";
     public static final String DOT_SPACE = ". ";
-    public static String DEFAULT_GPT_SYSTEM_PROMPT;
-    public static String DEFAULT_GPT_SYSTEM_PROMPT_INSTRUCTIONS;
-    public static String DEFAULT_GPT_USER_PROMPT;
-    public static String DEFAULT_GPT_USER_PROMPT_JSON;
-    public static String DEFAULT_GPT_CUSTOM_USER_PROMPT_JSON;
-    public static String DEFAULT_GPT_USER_PROMPT_JSON_2;
-    public static String DEFAULT_GPT_USER_PROMPT_JSON_ENFORCE_RESPONSE_CHECK;
-    public static String DEFAULT_GPT_CUSTOM_USER_PROMPT_1;
-    public static String DEFAULT_GPT_CUSTOM_USER_PROMPT_2;
-    public static String DEFAULT_GPT_COMMIT_MESSAGES_REVIEW_USER_PROMPT;
+    public static final String NOT_CONFIGURED_ERROR_MSG = "%s is not configured";
 
+    // Default Config values
+    public static final String OPENAI_DOMAIN = "https://api.openai.com";
+    public static final String DEFAULT_GPT_MODEL = "gpt-3.5-turbo";
     private static final String DEFAULT_GPT_TEMPERATURE = "1";
-    private static final boolean DEFAULT_REVIEW_PATCHSET = true;
+    private static final boolean DEFAULT_REVIEW_PATCH_SET = true;
     private static final boolean DEFAULT_REVIEW_COMMIT_MESSAGES = false;
     private static final boolean DEFAULT_FULL_FILE_REVIEW = true;
     private static final boolean DEFAULT_STREAM_OUTPUT = false;
@@ -81,6 +69,11 @@
     private static final boolean DEFAULT_PROJECT_ENABLE = false;
     private static final int DEFAULT_MAX_REVIEW_LINES = 1000;
     private static final int DEFAULT_MAX_REVIEW_FILE_SIZE = 10000;
+
+    // Config setting keys
+    public static final String KEY_GPT_SYSTEM_PROMPT = "gptSystemPrompt";
+    public static final String KEY_GPT_REQUEST_USER_PROMPT = "gptRequestUserPrompt";
+    public static final String KEY_COMMENT_PROPERTIES_SIZE = "commentPropertiesSize";
     private static final String KEY_GPT_TOKEN = "gptToken";
     private static final String KEY_GERRIT_AUTH_BASE_URL = "gerritAuthBaseUrl";
     private static final String KEY_GERRIT_USERNAME = "gerritUserName";
@@ -90,7 +83,7 @@
     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_REVIEW_PATCHSET = "gptReviewPatchSet";
+    private static final String KEY_REVIEW_PATCH_SET = "gptReviewPatchSet";
     private static final String KEY_FULL_FILE_REVIEW = "gptFullFileReview";
     private static final String KEY_PROJECT_ENABLE = "isEnabled";
     private static final String KEY_GLOBAL_ENABLE = "globalEnable";
@@ -104,6 +97,19 @@
     private static final String KEY_MAX_REVIEW_LINES = "maxReviewLines";
     private static final String KEY_MAX_REVIEW_FILE_SIZE = "maxReviewFileSize";
     private static final String KEY_ENABLED_FILE_EXTENSIONS = "enabledFileExtensions";
+
+    // Prompt constants loaded from JSON file
+    public static String DEFAULT_GPT_SYSTEM_PROMPT;
+    public static String DEFAULT_GPT_SYSTEM_PROMPT_INSTRUCTIONS;
+    public static String DEFAULT_GPT_REVIEW_USER_PROMPT;
+    public static String DEFAULT_GPT_JSON_USER_PROMPT;
+    public static String DEFAULT_GPT_REQUEST_JSON_USER_PROMPT;
+    public static String DEFAULT_GPT_JSON_USER_PROMPT_2;
+    public static String DEFAULT_GPT_JSON_USER_PROMPT_ENFORCE_RESPONSE_CHECK;
+    public static String DEFAULT_GPT_REQUEST_USER_PROMPT_1;
+    public static String DEFAULT_GPT_REQUEST_USER_PROMPT_2;
+    public static String DEFAULT_GPT_COMMIT_MESSAGES_REVIEW_USER_PROMPT;
+
     private final Map<String, Object> configsDynamically = Maps.newHashMap();
     private final PluginConfig globalConfig;
     private final PluginConfig projectConfig;
@@ -118,15 +124,15 @@
         return DEFAULT_GPT_SYSTEM_PROMPT + DOT_SPACE + DEFAULT_GPT_SYSTEM_PROMPT_INSTRUCTIONS;
     }
 
-    public static String getReviewUserPrompt() {
-        return DEFAULT_GPT_USER_PROMPT_JSON + DOT_SPACE + DEFAULT_GPT_USER_PROMPT_JSON_2;
+    public static String getPatchSetReviewUserPrompt() {
+        return DEFAULT_GPT_JSON_USER_PROMPT + DOT_SPACE + DEFAULT_GPT_JSON_USER_PROMPT_2;
     }
 
-    public String getCommentUserPrompt() {
-        return DEFAULT_GPT_USER_PROMPT_JSON + SPACE +
-                DEFAULT_GPT_CUSTOM_USER_PROMPT_JSON + DOT_SPACE +
-                DEFAULT_GPT_USER_PROMPT_JSON_2 + SPACE +
-                String.format(DEFAULT_GPT_USER_PROMPT_JSON_ENFORCE_RESPONSE_CHECK,
+    public String getCommentRequestUserPrompt() {
+        return DEFAULT_GPT_JSON_USER_PROMPT + SPACE +
+                DEFAULT_GPT_REQUEST_JSON_USER_PROMPT + DOT_SPACE +
+                DEFAULT_GPT_JSON_USER_PROMPT_2 + SPACE +
+                String.format(DEFAULT_GPT_JSON_USER_PROMPT_ENFORCE_RESPONSE_CHECK,
                     configsDynamically.get(KEY_COMMENT_PROPERTIES_SIZE));
     }
 
@@ -170,20 +176,20 @@
 
     public String getGptUserPrompt(String patchSet) {
         List<String> prompt = new ArrayList<>();
-        String gptUserPrompt = configsDynamically.get(KEY_GPT_USER_PROMPT).toString();
-        if (gptUserPrompt != null && !gptUserPrompt.isEmpty()) {
-            log.debug("ConfigsDynamically value found: {}", gptUserPrompt);
+        String gptRequestUserPrompt = configsDynamically.get(KEY_GPT_REQUEST_USER_PROMPT).toString();
+        if (gptRequestUserPrompt != null && !gptRequestUserPrompt.isEmpty()) {
+            log.debug("ConfigsDynamically value found: {}", gptRequestUserPrompt);
             prompt.addAll(Arrays.asList(
-                    DEFAULT_GPT_CUSTOM_USER_PROMPT_1,
+                    DEFAULT_GPT_REQUEST_USER_PROMPT_1,
                     patchSet,
-                    DEFAULT_GPT_CUSTOM_USER_PROMPT_2,
-                    gptUserPrompt,
-                    getCommentUserPrompt()
+                    DEFAULT_GPT_REQUEST_USER_PROMPT_2,
+                    gptRequestUserPrompt,
+                    getCommentRequestUserPrompt()
             ));
         }
         else {
-            prompt.add(getString(KEY_GPT_USER_PROMPT, DEFAULT_GPT_USER_PROMPT));
-            prompt.add(getReviewUserPrompt());
+            prompt.add(DEFAULT_GPT_REVIEW_USER_PROMPT);
+            prompt.add(getPatchSetReviewUserPrompt());
             if (getGptReviewCommitMessages()) {
                 prompt.add(DEFAULT_GPT_COMMIT_MESSAGES_REVIEW_USER_PROMPT);
             }
@@ -197,7 +203,7 @@
     }
 
     public boolean getGptReviewPatchSet() {
-        return getBoolean(KEY_REVIEW_PATCHSET, DEFAULT_REVIEW_PATCHSET);
+        return getBoolean(KEY_REVIEW_PATCH_SET, DEFAULT_REVIEW_PATCH_SET);
     }
 
     public boolean getGptReviewCommitMessages() {
diff --git a/src/main/resources/Config/prompts.json b/src/main/resources/Config/prompts.json
index 3ceafbd..0711f17 100644
--- a/src/main/resources/Config/prompts.json
+++ b/src/main/resources/Config/prompts.json
@@ -1,12 +1,12 @@
 {
   "DEFAULT_GPT_SYSTEM_PROMPT": "Act as a PatchSet Reviewer",
   "DEFAULT_GPT_SYSTEM_PROMPT_INSTRUCTIONS": "I will provide you with PatchSet Diffs for various files in a JSON format. Each changed file's content will be detailed in the \"content\" field of the JSON object. In this \"content\", the \"a\" items are the lines removed, the \"b\" items are the lines added, and the \"ab\" items are the unchanged lines. In your response, avoid explicitly referring to the \"a\", \"b\", and other fields from the JSON object. Instead, use more intuitive terms like \"new lines\" for additions, \"removed lines\" for deletions, and \"unchanged lines\" for the parts that haven't been altered.",
-  "DEFAULT_GPT_USER_PROMPT": "Focus your review on the \"a\" and \"b\" items, but use the \"ab\" items as context to understand the changes better. Provide insights on any potential issues you foresee and suggestions for improvements if necessary, with an emphasis on identifying and addressing concerns rather than highlighting positive aspects.",
-  "DEFAULT_GPT_USER_PROMPT_JSON": "Each reply must be formatted as an individual object within an array in the key `replies`. The object will always contain the string field `reply`",
-  "DEFAULT_GPT_CUSTOM_USER_PROMPT_JSON": "along with the key `id`, which corresponds to the `id` value from the related request in the request JSON array",
-  "DEFAULT_GPT_USER_PROMPT_JSON_2": "Also return back the field `changeId` provided in the corresponding request. For replies that are specific to a certain part of the code, the object must additionally include the keys `filename`, `lineNumber`, and `codeSnippet` to precisely identify the relevant code section.",
-  "DEFAULT_GPT_USER_PROMPT_JSON_ENFORCE_RESPONSE_CHECK": "Make sure that the array in `replies` contains exactly %d element(s), one for each request.",
-  "DEFAULT_GPT_CUSTOM_USER_PROMPT_1": "I have some requests about the following PatchSet Diff:",
-  "DEFAULT_GPT_CUSTOM_USER_PROMPT_2": "My requests are given in a JSON-formatted array:",
+  "DEFAULT_GPT_REVIEW_USER_PROMPT": "Focus your review on the \"a\" and \"b\" items, but use the \"ab\" items as context to understand the changes better. Provide insights on any potential issues you foresee and suggestions for improvements if necessary, with an emphasis on identifying and addressing concerns rather than highlighting positive aspects.",
+  "DEFAULT_GPT_JSON_USER_PROMPT": "Each reply must be formatted as an individual object within an array in the key `replies`. The object will always contain the string field `reply`",
+  "DEFAULT_GPT_REQUEST_JSON_USER_PROMPT": "along with the key `id`, which corresponds to the `id` value from the related request in the request JSON array",
+  "DEFAULT_GPT_JSON_USER_PROMPT_2": "Also return back the field `changeId` provided in the corresponding request. For replies that are specific to a certain part of the code, the object must additionally include the keys `filename`, `lineNumber`, and `codeSnippet` to precisely identify the relevant code section.",
+  "DEFAULT_GPT_JSON_USER_PROMPT_ENFORCE_RESPONSE_CHECK": "Make sure that the array in `replies` contains exactly %d element(s), one for each request.",
+  "DEFAULT_GPT_REQUEST_USER_PROMPT_1": "I have some requests about the following PatchSet Diff:",
+  "DEFAULT_GPT_REQUEST_USER_PROMPT_2": "My requests are given in a JSON-formatted array:",
   "DEFAULT_GPT_COMMIT_MESSAGES_REVIEW_USER_PROMPT": "Also, perform a check on the commit message of the PatchSet. The commit message is provided in the \"content\" field of \"/COMMIT_MSG\" in the same way as the file changes. Ensure that the commit message accurately and succinctly describes the changes made, and verify if it matches the nature and scope of the changes in the PatchSet."
 }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTest.java b/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTest.java
index 512d3bd..430bf0c 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTest.java
@@ -216,8 +216,8 @@
                 "__files/chatGptExpectedResponseStreamed.json")));
         expectedSystemPrompt = Configuration.getDefaultSystemPrompt();
         reviewUserPrompt = String.join("\n", Arrays.asList(
-                Configuration.DEFAULT_GPT_USER_PROMPT,
-                Configuration.getReviewUserPrompt(),
+                Configuration.DEFAULT_GPT_REVIEW_USER_PROMPT,
+                Configuration.getPatchSetReviewUserPrompt(),
                 Configuration.DEFAULT_GPT_COMMIT_MESSAGES_REVIEW_USER_PROMPT,
                 diffContent
         ));
@@ -376,11 +376,11 @@
         future.get();
 
         String commentUserPrompt = String.join("\n", Arrays.asList(
-                Configuration.DEFAULT_GPT_CUSTOM_USER_PROMPT_1,
+                Configuration.DEFAULT_GPT_REQUEST_USER_PROMPT_1,
                 diffContent,
-                Configuration.DEFAULT_GPT_CUSTOM_USER_PROMPT_2,
+                Configuration.DEFAULT_GPT_REQUEST_USER_PROMPT_2,
                 REVIEW_TAG_COMMENTS,
-                config.getCommentUserPrompt()
+                config.getCommentRequestUserPrompt()
         ));
         RequestPatternBuilder requestPatternBuilder = WireMock.postRequestedFor(
                 WireMock.urlEqualTo(gerritSetReviewUri(buildFullChangeId(PROJECT_NAME, BRANCH_NAME, CHANGE_ID))));