A method and system for generating a code review comment for a change code

By using IDEA plugins and backend service modules to extract and store code context information during code review, and combining this with a large language model to generate code review comments, the problem of lacking context information in existing technologies is solved, improving the intelligence and efficiency of code review, and ensuring data security.

CN122363747APending Publication Date: 2026-07-10TRAVELSKY TECHNOLOGY LIMITED

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
TRAVELSKY TECHNOLOGY LIMITED
Filing Date
2026-03-09
Publication Date
2026-07-10

AI Technical Summary

Technical Problem

Existing technologies lack the ability to automatically acquire and utilize structured contextual information about changed code during code reviews, resulting in inefficient and low-quality code reviews.

Method used

The submitted source code is parsed by the IDEA plugin module, abstracted into an abstract syntax tree, and the context information is extracted and stored in the database. The backend service module queries and constructs prompt words to guide the large language model to generate code review comments.

Benefits of technology

It enables the automatic generation of code review comments, improves the intelligence level of code review, enhances context understanding, improves review efficiency, and ensures data security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122363747A_ABST
    Figure CN122363747A_ABST
Patent Text Reader

Abstract

This application discloses a method and system for generating code review comments on modified code, belonging to the field of computer technology. The method includes: parsing the submitted source code through an IDEA plugin module to abstract the modified file into an abstract syntax tree; extracting information from the abstract syntax tree to obtain extracted information, which includes: the package name, class name, class comments, signatures, comments, and field declarations of other unmodified methods in the class; storing the context information of the modified code obtained from the extracted information into a database; querying the context information through a backend service module and constructing prompt words based on the context information; and guiding a large language model to generate code review comments through the prompt words. This generation method can automatically generate code review comments, thereby improving the intelligence level of code review.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of computer technology, and specifically relates to a method and system for generating code review comments on modified code. Background Technology

[0002] Modern software development commonly employs version control systems for code review processes to ensure code quality. However, as systems become larger and more complex, traditional manual reviews become inefficient. Large language models (such as DeepSeek and Qwen Coder) demonstrate powerful capabilities in code generation and analysis, potentially aiding in automated code review. However, existing technologies have a key drawback: the interfaces provided by version control systems (such as Bitbucket) typically only retrieve changed code snippets (diff), failing to provide the complete code context (such as related classes, methods, and variable definitions). This makes it difficult for reviewers or the model to understand the dependencies between changes, impacting review quality.

[0003] Research indicates that insufficient contextual understanding is one of the main challenges of code review. Optimal AI's practical experience points out that "the biggest challenge is contextual understanding, requiring a model that can view code change sets and actually place them in context." While large models like Gemini have larger context windows, they cannot function effectively if the input lacks relevant background information. Another study also emphasizes that code review assistants should possess context-aware capabilities, utilizing project information such as code differences and source files to generate more accurate recommendations. In other words, modern automated reviews need to effectively supplement the class-level and project-level context associated with changed code to improve the accuracy and efficiency of the review.

[0004] Currently, some auxiliary code review tools (such as static scanning and Lint tools) can check for security vulnerabilities and coding standards, but they rely on complete code files and have difficulty automatically obtaining contextual information for incremental PR changes. Generally, developers or reviewers need to manually switch to relevant files or query historical commits to obtain background information, which is labor-intensive and error-prone.

[0005] In summary, current technology lacks an efficient means to automatically acquire and utilize the structured context (such as class-level information and abstract syntax trees) of changed code during PR reviews and use it as review input for large models, thereby improving the intelligence level of code reviews.

[0006] In summary, the problem to be solved is how to provide a method for generating code review comments that can automatically generate code review comments in order to improve the intelligence level of code review. Summary of the Invention

[0007] To address the aforementioned issues, this application provides a method, system, storage medium, and electronic device for generating code review comments on modified code, which can automatically generate code review comments to improve the intelligence level of code review.

[0008] In a first aspect, embodiments of this application provide a method for generating code review comments on modified code, the method comprising: The submitted source code is parsed using the IDEA plugin module to abstract the changed files into an abstract syntax tree, and information is extracted from the abstract syntax tree to obtain extracted information, which includes: the package name, class name, class comments, signatures, comments, and field declarations of other unmodified methods in the class. The context information of the modified code obtained from the extracted information is stored in the database; The context information is queried through the backend service module, and prompt words are constructed based on the context information; The prompts guide a large language model to generate code review comments.

[0009] Optionally, querying the context information through the backend service module includes: Obtained based on the new PR request; Based on the new PR request, determine the class name and package path corresponding to each change file; Based on the class name and package path corresponding to each change file, determine the corresponding class name and PR submitter; Using the corresponding class name and PR submitter as keys, retrieve the relevant context information from the database.

[0010] Optionally, determining the class name and package path corresponding to each changed file based on the new PR request includes: In response to a new PR request, the backend service module automatically retrieves the list of changed files and difference information in this PR; The backend service module parses the difference information to obtain the parsing results; Based on the parsing results, the class name and package path corresponding to each change file are determined.

[0011] Optionally, constructing prompt words based on the context information includes: Obtain the context information and the change code; The prompt word is constructed based on the context information and the modified code. The format of the prompt word includes: system instructions, general coding standards, modified code snippets, and context code of the associated class.

[0012] Optionally, storing the context information of the modified code obtained from the extracted information into a database includes: Obtain the context information from the extracted information; The context information is processed in a structured manner to obtain the corresponding structured text, which includes: JSON text and structured text; Obtain the index key corresponding to the structured text; The structured text and the index key are stored in the database, wherein the class name and user information are used as the index key.

[0013] Secondly, embodiments of this application provide a system for generating code review comments on modified code, the system comprising: The IDEA plugin module is used to parse the submitted source code, abstract the changed files into an abstract syntax tree, and extract information from the abstract syntax tree to obtain extracted information, which includes: the package name, class name, class comments, signatures, comments, and field declarations of other unmodified methods in the class. A storage module is used to store the context information of the change code obtained from the extracted information into a database; The backend service module is used to query the context information and construct prompt words based on the context information; The generation module is used to guide a large language model to generate code review comments based on the prompt words.

[0014] Optionally, the backend service module is specifically used for: Obtained based on the new PR request; Based on the new PR request, determine the class name and package path corresponding to each change file; Based on the class name and package path corresponding to each change file, determine the corresponding class name and PR submitter; Using the corresponding class name and PR submitter as keys, retrieve the relevant context information from the database.

[0015] Optionally, the backend service module is specifically used for: In response to a new PR request, the backend service module automatically retrieves the list of changed files and difference information in this PR; The backend service module parses the difference information to obtain the parsing results; Based on the parsing results, the class name and package path corresponding to each change file are determined.

[0016] Thirdly, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method of the first aspect.

[0017] Fourthly, an electronic device is provided, including a memory and a processor, wherein the memory stores executable code, and the processor executes the executable code to implement the method of the first aspect.

[0018] Compared with the prior art, this application has the following advantages: It can automatically generate code review comments to improve the intelligence level of code review.

[0019] Other features and advantages of this application will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the application. The objectives and other advantages of this application may be realized and obtained by means of the structures pointed out in the description, claims and drawings. Attached Figure Description

[0020] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0021] Figure 1 A flowchart illustrating a method for generating code review comments for modified code according to an embodiment of this application is shown; Figure 2 This diagram illustrates the overall architecture of a system for generating code review comments for modified code according to an embodiment of this application. Figure 3 A schematic diagram of the structure of a code review opinion generation system 300 for modified code according to an embodiment of this application is shown. Detailed Implementation

[0022] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0023] This application provides a method and system for generating code review comments on modified code, a computer-readable medium, and an electronic device, which will be described below with reference to the accompanying drawings.

[0024] The generation method provided in this application proposes a solution that combines IDEA plugins and backend services to automatically collect code context and link it with a large model for review, so as to automatically generate code review comments and improve the intelligence level of code review.

[0025] Please refer to Figure 1 It illustrates a flowchart of a method for generating code review comments for modified code provided in some embodiments of this application, such as... Figure 1 As shown, the method for generating code review comments on code changes may include the following steps: Step S101: The submitted source code is parsed through the IDEA plugin module to abstract the changed files into an abstract syntax tree, and information is extracted from the abstract syntax tree to obtain the extracted information, which includes: the package name, class name, class comments, signatures, comments, and field declarations of other unmodified methods in the class.

[0026] It should be noted that the IDEA plugin is an integrated development environment (IDE) plugin.

[0027] IntelliJ IDEA Integrated Development Environment: An integrated development tool (IDEA) developed by JetBrains, which supports the development of multiple languages ​​such as Java.

[0028] IDEA plugins: Extensions that run in the IDEA environment to enhance IDEA functionality, such as analyzing code context and static analysis.

[0029] Class: A basic structural type in object-oriented programming, used to encapsulate a group of object instances that have the same attributes and behaviors.

[0030] Abstract Syntax Tree (AST): An abstract tree-like representation of the syntax structure of source code, used to represent the structured hierarchy of code, with each node corresponding to a syntax element of the source code.

[0031] Code context: Surrounding code information related to the current code snippet, including other methods, field declarations, comments, etc. in the same class, used to supplement the semantic environment of the changed code.

[0032] Step S102: Store the context information of the change code obtained from the extracted information into the database.

[0033] It should be noted that the database is a system used to store structured data, and in this embodiment of the application, it is used to save the code context information extracted from the IDEA plugin.

[0034] In one example, the context information of the changed code obtained from the extracted information is stored in the database, including the following steps: Extract contextual information from the extracted information; The context information is processed in a structured manner to obtain the corresponding structured text, which includes JSON text and structured text. Retrieve the index key corresponding to the structured text; The structured text and its index keys are stored in the database, where class names and user information are used as index keys.

[0035] Step S103: Query context information through the backend service module and construct prompt words based on the context information.

[0036] It should be noted that the backend service is a software component running on the server side, responsible for accepting PR review requests, obtaining changed code and context, calling the LLM, and returning the review results.

[0037] In one example, querying context information via a backend service module includes the following steps: Obtained based on the new PR request; The class name and package path corresponding to each change file are determined based on the new PR request; Based on the class name and package path corresponding to each change file, determine the corresponding class name and PR submitter; Use the corresponding class name and PR submitter as keys to retrieve the relevant context information from the database.

[0038] It should be noted that a pull request (PR) is an operation on a version control platform where developers submit code changes and request that they be merged into the target codebase.

[0039] Cue words: Text input that provides guidance and context to a large language model to guide it in generating the desired output.

[0040] Step S104: Guide the large language model to generate code review comments using prompt words.

[0041] It should be noted that the large-scale language model is a large-scale natural language processing model based on neural networks, such as Qwen Coder, which can be used for tasks such as code generation and review. In the generation method provided in the embodiments of this application, it is deployed on a local server.

[0042] In one example, determining the class name and package path for each changed file based on a new PR request includes the following steps: In response to a new PR request, the backend service module automatically retrieves the list of changed files and difference information in this PR; The backend service module parses the difference information to obtain the parsing results; Based on the parsing results, the class name and package path corresponding to each change file are determined.

[0043] In one example, constructing prompts based on contextual information includes the following steps: Obtain context information and retrieve the changed code; Based on contextual information and modified code, a prompt word is generated. The format of the prompt word includes: system instructions, general coding standards, modified code snippets, and context code of the associated class.

[0044] like Figure 2 The diagram shows the overall architecture of a system for generating code review comments on modified code according to an embodiment of this application. Figure 2 This demonstrates the relationship between the IDEA plugin, database, backend service, and LLM inference module.

[0045] like Figure 2 As shown, the generation system mainly includes: an IDEA plugin module, a database module, a backend service module for code review, and a large language model inference module deployed on a local server. These modules work together to automatically extract the class-level context of the PR-changed code, and the local large language model performs intelligent review of the changed code.

[0046] The detailed descriptions of each of the above modules are as follows: The IDEA plugin module runs within the developer's IDEA environment and is triggered when the developer successfully commits code within IDEA. The plugin parses the committed source code using IDEA's APIs (such as the Program Structure Interface, PSI), abstracting the changed files into an Abstract Syntax Tree (AST). From this AST, it extracts the complete class structure and related members containing the methods containing the changed statements. Extracted information includes: the package name, class name, class comments, signatures and comments of other unchanged methods, field declarations, etc. The plugin then structures this context information (e.g., JSON text, structured text) and stores it in a database, using the class name and user information as index keys. This process ensures that the latest class-level context information is persistently saved with each code commit.

[0047] The database module stores the context information extracted by the IDEA plugin. Its table structure includes fields such as project ID, classpath, class name, timestamp, and context content. The database can be either relational or document-oriented for easy querying and updating. Whenever the IDEA plugin detects a subsequent change commit for the same class, it updates the corresponding context record to ensure that the context in the database always reflects the latest code baseline.

[0048] Backend service module: Deployed on the company's internal server and integrated with version control systems (such as Bitbucket). When a new PR request is generated (e.g., notified via a WebHook event), the backend service automatically retrieves the list of changed files and specific differences in this PR. The backend first parses the difference information, determines the class name and package path corresponding to each changed file, and then queries the database for the corresponding context information using the class name and PR submitter as keys. The retrieved context, together with the changed code, is used to construct a prompt word for a large language model: the prompt word format includes system instructions, general coding standards, changed code snippets, and context code of the associated classes, guiding the model to generate code review comments. The backend service calls the locally deployed large language model inference module (such as Qwen Coder) and submits the prompt word to the model for inference. The review feedback returned by the model (such as code quality suggestions, potential vulnerability warnings, etc.) is received and formatted by the backend service, and can then be directly returned to the PR interface or pushed to the developers as comments.

[0049] It should be noted that version control systems are tools or platforms used to manage software source code versions, such as GitLab and Bitbucket.

[0050] It should be noted that, as Figure 1 The functional modules shown work together through communication via a local area network or internal network.

[0051] In practical applications, the code extraction process is as follows: Step a1: Developer submission triggers; Step a2: The IDEA plugin analyzes and stores the context; Step a3: The backend service receives the PR event; Step a4: Merge the context and call LLM.

[0052] The above steps are described in sequence as follows: Step b1: The developer completes code editing and commits the changes in IDEA.

[0053] Step b2: The IDEA plugin captures the commit event, uses the IDEA API to parse the file containing the changed code, and converts it into an AST structure. The plugin locates the change node in the AST, extracts the complete structural information of the class containing the change, including the signatures and comments of all members of the class, fields, inheritance information, etc. (class-level context), and saves it to the database.

[0054] Step b3: After receiving the PR creation or update notification from the version control system, the backend service retrieves the change list and difference content in this PR.

[0055] Step b4: For each changed file, the backend extracts the class name and package path involved based on the differences and queries the database for the context information of that class.

[0056] Step b5: The backend concatenates the change code (diff) with the retrieved context information to form a prompt word, and organizes the input content according to the preset template (instruction word).

[0057] Step b6: The backend calls the locally deployed LLM service to submit the prompt words to the model and obtain review suggestions.

[0058] Step b7: The backend associates the suggestions output by the model with the original changes and returns them to the PR page or the developer for reference.

[0059] Through the above implementation process, the code context, which was originally impossible to obtain automatically, is collected and utilized in advance, enabling LLM to conduct reviews based on structured abstraction (AST) and class-level context, significantly improving review quality and efficiency. The generation method provided in this application also supports configuration management: the depth of context extraction can be specified (e.g., extracting only all members of the same class, or further extracting information from related classes) as well as the PR triggering timing (e.g., automatically triggered when a PR is created or with each update). Furthermore, since LLM is deployed on a local server, it meets enterprises' needs for code privacy and security.

[0060] In a specific application scenario, the method for generating code review opinions on modified code provided in this application embodiment includes the following steps: Step c1: Extracting the context of the IDEA plugin: The IDEA plugin module listens for successful code commit events in IDEA. When a developer commits changes to a remote code repository through IDEA, the plugin triggers the following steps: Step c11: Get the list of changed files: Call the IDEA API to get the paths of all source files involved in this commit.

[0061] Step c12: Analyze and locate changes: Perform AST parsing on each source file using IDEA's Program Structure Interface (PSI) to generate the corresponding Abstract Syntax Tree. Traverse the AST to find nodes containing modified lines of code, and determine the class and method to which that node belongs.

[0062] Step c13: Extract Class-Level Context: Obtain all member information of the class containing the change node (which may be a Java class, Kotlin class, etc.), including: class comments, field declarations and comments, signatures and comments of all methods, etc. Related inner classes or base classes can also be extracted to a certain extent. For large classes, some implementation logic can be ignored, retaining only the signature and key comments.

[0063] Step c14: Structured Storage: Organize the extracted information into structured data (e.g., JSON format, structured text), recording the project identifier, fully qualified class name, extraction timestamp and content summary, and submitter user information. Call the database interface to write this record to the database by class name or file path; if a record for the same class already exists, update its content; otherwise, create a new record.

[0064] Example 1: Suppose a developer modifies the `createUser()` method in the `UserService.java` class. The plugin detects this change, parses the AST of the `UserService` class, extracts the signatures and comments of other methods such as `getUser()` and `deleteUser()`, as well as the definition of the member variable `userRepository`, and stores the complete definition of `UserService` in the database, including the aforementioned context information. In this way, even if the PR only contains changes to the `createUser()` method during review, the model can still obtain the overall design intent and other method information of the `UserService` class.

[0065] Step c2: PR triggering and backend processing, the specific implementation process is as follows: Step c21: PR Trigger: When a new PR is submitted or updated, the version control platform (Bitbucket) notifies the backend service via a webhook. After receiving the request, the service calls the corresponding API to obtain metadata such as the PR number, submitter, and branch being changed.

[0066] Step c22: Obtain Change Differences: The backend uses the interface provided by the version control system to obtain the list of change files and the content of the differences in the PR (usually in Git diff format). These differences are parsed to determine the path of each change file and the specific location of the changes.

[0067] Step c23: Query Context: The backend iterates through all modified files, mapping the file paths to the fully qualified class names in languages ​​such as Java / Kotlin. For each class name, it queries the database for the corresponding context record. If the record exists, it retrieves the previously stored class-level context information (such as method lists, class annotations, etc.); if the record is missing, it marks the class context as empty.

[0068] Step c24: Generate Prompt Text: Concatenate the acquired change code and context information according to a pre-designed Prompt template. For example, you can first provide the model with a system instruction: "You are a code review assistant. Please provide review comments based on the following context and code changes." Then, insert the context code of the relevant class and the diff fragment of this PR in sequence. In this synthesized prompt text, the context code appears first (to help the model understand the background), followed by the change content to guide the model in making suggestions regarding the differences.

[0069] Step c25: Invoke the local LLM: The backend calls the interface of the LLM inference service (such as QwenCoder) deployed on the local area network via the network, submits the above prompt words, and receives the output generated by the model. Because the context information has been supplemented in advance, the model can understand the meaning of the changed business, and thus generate accurate review feedback.

[0070] Step c26: Output Results: The backend performs necessary formatting and filtering on the feedback text returned by the model (such as adding comment tags, category importance, etc.) and associates it with the PR before sending it to the developers or project maintainers. For example, the feedback content can be added as a comment next to the specific line of code on the PR page, or the developers can be notified via message.

[0071] Example 2: In another PR, the developer modified both the OrderController and OrderService classes. The backend service performs context queries on these two classes sequentially. For OrderController, it retrieves the complete class definition and its method context from the database; the same applies to OrderService. Suppose the developer modifies the processOrder() method of OrderService and calls this method in OrderController. The suggestion will include the associated context of the OrderService and OrderController classes, as well as the diff changes between the two classes. After seeing the call relationship between the two classes, the model can provide cross-class review suggestions such as "Note the order status synchronization," demonstrating the value of class-level context.

[0072] Step c3: System Deployment and Interaction: The hardware portion of the entire system includes developer workstations (running IDEA and installing plugins) and internally deployed servers (running backend services, databases, and LLM inference). The software portion, in addition to the aforementioned modules, includes configuration management services and security verification modules: the plugin's communication with the backend can utilize a secure REST API, and database permissions can be set to protect sensitive code. For multi-language projects, the plugin logic can be extended to support AST parsing for different languages; similar syntax tree tools can also be used for non-Java languages. The entire process is transparent to ordinary developers and reviewers, requiring no manual operation. Simply ensure the IDEA plugin is running correctly when submitting code, and the system will automatically complete context extraction and review.

[0073] The generation method provided in this application, by introducing a class-level structured context extraction mechanism, solves the problem of insufficient contextual information in PR review in the prior art. Specific advantages include: Enhanced contextual understanding: Incorporating relevant class and method information into review prompts allows LLMs to refer to the complete background when handling code changes, thereby reducing the risk of misjudgment due to lack of context.

[0074] Improving review efficiency: Automated processes reduce the time developers spend manually gathering background information, making reviews faster and more comprehensive. The Optimal AI case study also demonstrates that fully utilizing context can significantly improve code review speed.

[0075] Structured storage is reusable: The context is stored in the database in a structured form, which can be reused for subsequent review and analysis, facilitating continuous optimization and statistics.

[0076] Data security is controllable: The use of locally deployed large-scale language models and internal network services avoids the risk of code being transferred to external services, meeting enterprise security requirements.

[0077] Easy integration and expansion: Each module in the solution is designed independently and can be seamlessly integrated with existing project workflows (such as Bitbucket and IDEA). For different programming languages, it is only necessary to adapt the corresponding AST parser in the IDEA plugin and backend respectively.

[0078] In the generation method provided in the embodiments of this application, there may also be the following alternative solutions, as detailed below: If, for special reasons, the IDEA plugin is not used to obtain the context, the above system can still provide alternative solutions on the backend. For example, project code can be cloned directly from the version control system on the backend, an AST can be built on the target branch, and the context can be extracted. However, this method requires additional code synchronization and parsing overhead. The key to the embodiments of this application is to combine context extraction with the development environment, obtaining the latest context immediately during the development phase. Another alternative is to use cloud models such as DeepSeek for review during PR, but this involves the risk of code leakage and network latency. This solution prioritizes the use of local models to ensure security and reduce latency.

[0079] The generation method provided in this application embodiment can be replaced by the following alternative methods to achieve the same function: Plugin triggering methods: In addition to being triggered by IDEA commits, it can also support context extraction when pushing or merging code; or extract relevant context in batches when creating code branches.

[0080] Context granularity: If a class-level context is not used, a method-level or file-level context can also be selected. For example, only comments and call stack information directly related to the modified function can be extracted, but this implementation will increase the processing frequency and may affect efficiency.

[0081] Context retrieval source: Instead of the IDEA plugin approach, you can use static analysis tools (such as ANTLR or a dedicated parser) to build the AST and extract context information from the version control system in real time on the backend. Although the process is more centralized, it increases the server load.

[0082] Large model types: In addition to using "Qwen Coder", other locally deployed models (such as open source versions such as GPT4all, Llama2, Gemini, etc.) can also be used; or cloud APIs can be used when security requirements are not high. The choice of large model should be flexibly replaced according to actual needs and security policies.

[0083] Storage medium: The database can be replaced with a key-value store or caching system (such as Redis) to store the context and improve query efficiency; the context can also be integrated into the version control repository's additional metadata for management.

[0084] The code review comment generation method for modified code provided in this application can automatically generate code review comments, thereby improving the intelligence level of code review. Furthermore, the generation method provided in this application, based on intelligent PR code review context acquisition and utilization using a large model, effectively improves upon the limitations of existing technologies in the code review process.

[0085] In the above embodiments, a method for generating code review comments on modified code is provided. Correspondingly, this application also provides a system for generating code review comments on modified code. The system for generating code review comments on modified code provided in this application can implement the above-described method for generating code review comments on modified code. This system for generating code review comments on modified code can be implemented through software, hardware, or a combination of both. For example, the system for generating code review comments on modified code may include integrated or separate functional modules or units to perform the corresponding steps in the above methods.

[0086] Please refer to Figure 3 This illustration shows a schematic diagram of a code review opinion generation system for modified code provided by some embodiments of this application. Since the system embodiments are basically similar to the method embodiments, the description is relatively simple; relevant details can be found in the description of the method embodiments. The system embodiments described below are merely illustrative.

[0087] like Figure 3 As shown, the code review comment generation system 300 for changing code may include: IDEA plugin module 301 is used to parse the submitted source code to abstract the changed files into an abstract syntax tree, and to extract information from the abstract syntax tree to obtain the extracted information, which includes: the package name, class name, class comments, signatures, comments, and field declarations of other unmodified methods in the class. Storage module 302 is used to store the context information of the change code obtained from the extracted information into the database; Backend service module 303 is used to query context information and construct prompts based on the context information; Module 304 is used to guide a large language model to generate code review comments using prompt words.

[0088] In some embodiments of this application, the backend service module 303 is specifically used for: Obtained based on the new PR request; The class name and package path corresponding to each change file are determined based on the new PR request; Based on the class name and package path corresponding to each change file, determine the corresponding class name and PR submitter; Use the corresponding class name and PR submitter as keys to retrieve the relevant context information from the database.

[0089] In some embodiments of this application, the backend service module 303 is specifically used for: In response to a new PR request, the backend service module automatically retrieves the list of changed files and difference information in this PR; The backend service module parses the difference information to obtain the parsing results; Based on the parsing results, the class name and package path corresponding to each change file are determined.

[0090] In some embodiments of this application, the backend service module 303 is specifically used for: Obtain context information and retrieve the changed code; Based on contextual information and modified code, a prompt word is generated. The format of the prompt word includes: system instructions, general coding standards, modified code snippets, and context code of the associated class.

[0091] In some embodiments of this application, the storage module 302 is specifically used for: Extract contextual information from the extracted information; The context information is processed in a structured manner to obtain the corresponding structured text, which includes JSON text and structured text. Retrieve the index key corresponding to the structured text; The structured text and its index keys are stored in the database, where class names and user information are used as index keys.

[0092] According to another embodiment, a computer-readable storage medium is also provided, on which a computer program is stored, which, when executed in a computer, causes the computer to execute a method for generating code review opinions on the aforementioned modified code.

[0093] According to another embodiment, an electronic device is also provided, including a memory and a processor, wherein executable code is stored in the memory, and when the processor executes the executable code, it implements the method for generating code review opinions on the aforementioned modified code.

[0094] Those skilled in the art will recognize that, in one or more of the examples above, the functions described in this application can be implemented using hardware, software, firmware, or any combination thereof. When implemented in software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or code on a computer-readable medium.

[0095] Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A method for generating code review comments on code changes, characterized in that, The method includes: The submitted source code is parsed using the IDEA plugin module to abstract the changed files into an abstract syntax tree, and information is extracted from the abstract syntax tree to obtain extracted information, which includes: the package name, class name, class comments, signatures, comments, and field declarations of other unmodified methods in the class. The context information of the modified code obtained from the extracted information is stored in the database; The context information is queried through the backend service module, and prompt words are constructed based on the context information; The prompts guide a large language model to generate code review comments.

2. The generation method according to claim 1, characterized in that, The step of querying the context information through the backend service module includes: Obtained based on the new PR request; Based on the new PR request, determine the class name and package path corresponding to each change file; Based on the class name and package path corresponding to each change file, determine the corresponding class name and PR submitter; Using the corresponding class name and PR submitter as keys, retrieve the relevant context information from the database.

3. The generation method according to claim 2, characterized in that, The process of determining the class name and package path corresponding to each changed file based on the new PR request includes: In response to a new PR request, the backend service module automatically retrieves the list of changed files and difference information in this PR; The backend service module parses the difference information to obtain the parsing results; Based on the parsing results, the class name and package path corresponding to each change file are determined.

4. The generation method according to claim 2, characterized in that, The construction of prompt words based on the context information includes: Obtain the context information and the change code; The prompt word is constructed based on the context information and the modified code. The format of the prompt word includes: system instructions, general coding standards, modified code snippets, and context code of the associated class.

5. The generation method according to claim 1, characterized in that, The step of storing the context information of the modified code obtained from the extracted information into the database includes: Obtain the context information from the extracted information; The context information is processed in a structured manner to obtain the corresponding structured text, which includes: JSON text and structured text; Obtain the index key corresponding to the structured text; The structured text and the index key are stored in the database, wherein the class name and user information are used as the index key.

6. A system for generating code review comments on modified code, characterized in that, The system includes: The IDEA plugin module is used to parse the submitted source code, abstract the changed files into an abstract syntax tree, and extract information from the abstract syntax tree to obtain extracted information, which includes: the package name, class name, class comments, signatures, comments, and field declarations of other unmodified methods in the class. A storage module is used to store the context information of the change code obtained from the extracted information into a database; The backend service module is used to query the context information and construct prompt words based on the context information; The generation module is used to guide a large language model to generate code review comments based on the prompt words.

7. The generation system according to claim 6, characterized in that, The backend service module is specifically used for: Obtained based on the new PR request; Based on the new PR request, determine the class name and package path corresponding to each change file; Based on the class name and package path corresponding to each change file, determine the corresponding class name and PR submitter; Using the corresponding class name and PR submitter as keys, retrieve the relevant context information from the database.

8. The generation system according to claim 7, characterized in that, The backend service module is specifically used for: In response to a new PR request, the backend service module automatically retrieves the list of changed files and difference information in this PR; The backend service module parses the difference information to obtain the parsing results; Based on the parsing results, the class name and package path corresponding to each change file are determined.

9. A computer-readable storage medium, characterized in that, It contains a computer program that, when executed in a computer, causes the computer to perform the method described in any one of claims 1 to 5.

10. An electronic device, characterized in that, The method includes a memory and a processor, wherein the memory stores executable code, and the processor executes the executable code to implement the method according to any one of claims 1 to 5.