Skip to content

Commit 6796ba7

Browse files
committed
Update prompt to inform label and justification for generated comments
1 parent e956284 commit 6796ba7

1 file changed

Lines changed: 67 additions & 26 deletions

File tree

scripts/comment_generation_bug_reports.py

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
# For that, you might clone the repo locally and inform its path below: https://hg-edge.mozilla.org/mozilla-central
2828
LOCAL_MERCURIAL_PATH = ""
2929
REPORT_DIRECTORY = ""
30-
REPORT_FILENAME_GPT = "generated_comment_gpt.csv"
31-
REPORT_FILENAME_DEEPSEEK = "generated_comment_deepseek.csv"
30+
REPORT_FILENAME_GPT = "filtered_comment_gpt.csv"
31+
REPORT_FILENAME_DEEPSEEK = "filtered_comment_deepseek.csv"
3232

3333
OPEN_API_KEY = ""
3434
OPEN_AI_MODEL = "gpt-4o-mini"
@@ -99,7 +99,8 @@
9999
"filename": "netwerk/streamconv/converters/mozTXTToHTMLConv.cpp",
100100
"start_line": 1211,
101101
"content": "Ensure that the size of `tempString` does not exceed 256 characters. Using `nsAutoStringN<256>` is efficient for small strings, but exceeding the size can lead to buffer issues.",
102-
"coment_type": "code validation"
102+
"label": "code validation"
103+
"label_justification": "Functional - Validation"
103104
}}
104105
]
105106
@@ -128,32 +129,70 @@
128129
\"filename\": \"<file_path>\",
129130
\"start_line\": <line_number>,
130131
\"content\": \"<comment_content>\",
131-
\"comment_type\": \"<comment_type>\"
132+
\"label\": \"<label>\",
133+
\"label_justification\": \"<label_justification>\"
132134
}}
133135
]
134136
```
135137
6. **Content of Comments**:
136-
- Be concise, Comments should be short and to the point.
138+
- Be concise, comments should be short and to the point.
137139
- Provide actionable feedback that would lide the the fixes from the Patch fixing the bug.
138140
- Each comment should focus solely on potential issues introduced by the added '+' lines of code.
139141
- Avoid referencing any external descriptions (like Jira tickets or Patchi fixing the bug). Focus on the Patch introducing the bug itself.
140142
- The comment type could be:
141-
* Functional - Functional defect: Functionality is missing or implemented incorrectly and such defects often require additional code or larger modifications to the existing solution.
142-
* Functional - Logical: Control flow, comparison related, and logical errors.
143-
* Functional - Validation: Validation mistakes or mistakes made when detecting an invalid value are of this class. Any kind of user data sanitization-related comments are in this category, too.
144-
* Functional - Resource: Resource (variables, memory, files, database) initialization, manipulation, and release.
145-
* Functional - Timing: Potential issues due to incorrect thread synchronization.
146-
* Functional - Support: Issues related to support systems and libraries or their configurations.
147-
* Functional - Interface: Mistakes when interacting with other parts of the software such as, existing code library, hardware device, database or operating system.
148-
* Refactoring - Solution approach: Suggestions to adopt an alternate algorithm or data structure.
149-
* Refactoring - Alternate Output: Comments that suggest modifying the error message, toast message, alert, or change what is returned by a function.
150-
* Refactoring - Organization of the code: Refactoring suggestions.
151-
* Refactoring - Naming Convention: Violations of identifier naming conventions.
152-
* Refactoring - Visual Representation: Whitespace, blank lines, code rearrangements, and indentation-related comments.
153-
* Documentation: Suggestions to add/modify comments or documentation to aid code comprehension.
154-
* Discussion - Design discussion: Discussions on design direction, design pattern, and software architecture.
155-
* Discussion - Question: Questions to understand the design or implementation choices.
156-
* Discussion - Praise: Complement for a code.
143+
Categories and Subcategories
144+
1. Readability:
145+
Focus: Making the code easier to read and understand.
146+
Subcategories include:
147+
* Refactoring - Consistency: Uniform coding styles and practices.
148+
* Refactoring - Naming Convention: Clear, descriptive identifiers.
149+
* Refactoring - Readability: General clarity improvements.
150+
* Refactoring - Simplification: Reducing unnecessary complexity.
151+
* Refactoring - Visual Representation: Improving code layout and formatting.
152+
2. Design and Maintainability:
153+
Focus: Improving structure and long-term upkeep.
154+
Subcategories include:
155+
* Discussion - Design discussion: Architectural or structural decisions.
156+
* Functional - Support: Adding or enhancing support functionality.
157+
* Refactoring - Alternate Output: Changing what the code returns or prints.
158+
* Refactoring - Code Duplication: Removing repeated code.
159+
* Refactoring - Code Simplification: Streamlining logic.
160+
* Refactoring - Magic Numbers: Replacing hard-coded values with named constants.
161+
* Refactoring - Organization of the code: Logical structuring of code.
162+
* Refactoring - Solution approach: Rethinking problem-solving approaches.
163+
* Refactoring - Unused Variables: Removing variables not in use.
164+
* Refactoring - Variable Declarations: Improving how variables are declared or initialized.
165+
3. Performance:
166+
Focus: Making the code faster or more efficient.
167+
Subcategories include:
168+
* Functional - Performance: General performance improvements.
169+
* Functional - Performance Optimization: Specific performance-focused refactoring.
170+
* Functional - Performance and Safety: Balancing speed and reliability.
171+
* Functional - Resource: Efficient use of memory, CPU, etc.
172+
* Refactoring - Performance Optimization: Improving performance through code changes.
173+
4. Defect:
174+
Focus: Fixing bugs and potential issues.
175+
Subcategories include:
176+
* Functional - Conditional Compilation
177+
* Functional - Consistency and Thread Safety
178+
* Functional - Error Handling
179+
* Functional - Exception Handling
180+
* Functional - Initialization
181+
* Functional - Interface
182+
* Functional - Lambda Usage
183+
* Functional - Logical
184+
* Functional - Null Handling
185+
* Functional - Security
186+
* Functional - Serialization
187+
* Functional - Syntax
188+
* Functional - Timing
189+
* Functional - Type Safety
190+
* Functional - Validation
191+
5. Other:
192+
Use only if none of the above apply:
193+
Subcategories include:
194+
* None of the above
195+
* Does not apply
157196
- Keep It Focused: Limit your comments to the issues that could lead to problems identified by the Jira ticket and are directly related to the changes made in the Patch fixing the bug.
158197
7. **Limit the Comments**: Write as little amount of comments possible.
159198
@@ -173,7 +212,8 @@
173212
\"filename\": \"netwerk/streamconv/converters/mozTXTToHTMLConv.cpp\",
174213
\"start_line\": 1211,
175214
\"content\": \"The lack of input validation in this line could lead to an unexpected crash. Consider validating `tempString` length before using it.\",
176-
\"comment_type\": \"code validation\"
215+
\"label\": \"Defect\",
216+
\"label_justification\": \"Functional - Validation\"
177217
}}
178218
]
179219
```
@@ -300,8 +340,7 @@ def generate_code_review_comments(
300340
return None
301341

302342
llm = ChatOpenAI(
303-
model_name=OPEN_AI_MODEL,
304-
temperature=TEMPERATURE,
343+
model_name=OPEN_AI_MODEL, temperature=TEMPERATURE, openai_api_key=OPEN_API_KEY
305344
)
306345

307346
summarization_chain = LLMChain(
@@ -384,7 +423,8 @@ def save_output_comments(
384423
"Filename",
385424
"Start Line",
386425
"Comment Content",
387-
"Comment Type",
426+
"Label",
427+
"Justification",
388428
]
389429

390430
if len(comments) > 0:
@@ -415,7 +455,8 @@ def save_output_comments(
415455
"Filename": comment.get("filename", ""),
416456
"Start Line": comment.get("start_line", ""),
417457
"Comment Content": comment.get("content", ""),
418-
"Comment Type": comment.get("comment_type", ""),
458+
"Label": comment.get("label", ""),
459+
"Justification": comment.get("label_justification", ""),
419460
}
420461
)
421462
print(f"CSV file has been successfully written to {output_csv_path}.")

0 commit comments

Comments
 (0)