Intelligent code review method and system
Through intelligent code review methods and systems, the code review process is automated, the code review efficiency and quality problems are solved, and the rapid and standardized review results are achieved, and the code quality is significantly improved.
Patent Information
- Application Number
- CN202510343191.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-21
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2045-03-21
AI Technical Summary
During the software development process, code review requires a comprehensive evaluation of logic, structure, performance and security, which leads to the technical leaders facing huge time and energy investment pressure, especially in scenarios where high frequency submissions or high module complexity, where subjectivity and omission risks are present.
Through intelligent code review methods and systems, the developer's trigger mechanism in code management tools is used to automatically call the backend interface for code review. The system can classify submitted codes, split them into a single submitted code for review, and provide fast and standardized review results through intelligent scoring and automatic generation of review opinions.
It significantly improves the efficiency and quality of code review, reduces the work burden of technical leaders, reduces the risk of subjectivity and omissions, and ensures the improvement of code quality.
Smart Images

Figure CN119848881A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of program testing, and in particular to a method and system for intelligent code review. Background Art
[0002] In the current software development process, after developers write code based on the requirements document and complete the functional implementation, the technical manager usually needs to conduct a quality review of the submitted code. This review process is designed to ensure that the code complies with the team's established coding standards and design principles, and eliminate potential security risks. However, since code review requires a comprehensive assessment of logic, structure, performance, and security, especially in scenarios with high frequency submissions or high module complexity, technical managers often face huge pressure to invest time and energy, which may affect overall development efficiency.
[0003] In addition, when the technical manager is not familiar enough with certain modules, it may be difficult to deeply evaluate the business logic or key technical implementation of the code, resulting in a certain degree of subjectivity or omission risk in the evaluation results. In this case, code review may not only reduce the reliability of overall quality control, but also affect the development progress. Therefore, how to use intelligent tools and automation technology to assist the code review process, reduce the workload of the technical manager, and improve the review efficiency has become an important topic in the optimization of modern software development processes. Summary of the invention
[0004] The present application provides a method and system for intelligent code review, which can improve the efficiency of code review.
[0005] In a first aspect of the present application, a method for intelligent code review is provided, the method comprising: A project binding trigger mechanism based on the developer's need to conduct code review in the code management tool, so that the code management tool can automatically call the background interface of the intelligent code review system after receiving the code pushed by the user's specified branch; Obtaining the submitted local code, and automatically calling the background interface according to the trigger mechanism, wherein the local code includes the incremental code or the full code submitted by the developer; If it is determined that the type of the local code is the incremental code, the local code is filtered, and the submission information corresponding to the target code that meets the filtering condition is written into the cache to wait for the scheduled task to execute the review task; When executing the scheduled task, the submission information is retrieved from the cache, and the target code is split into individual submission codes according to the submission information; Scoring each submitted code to obtain a code score, and providing review opinions on the submitted code; The average scores of the multiple code scores are calculated to obtain a comprehensive score corresponding to the target code.
[0006] On the basis of the above technical solution, preferably, after obtaining the submitted local code and automatically calling the background interface according to the trigger mechanism, the method further includes: If it is determined that the type of the local code is full code, obtaining a source file of the local code; Filtering target files that need to be security scanned from the source files; Parsing the syntax tree of the target file, and recursively obtaining target attributes in the target file; Check whether the fully qualified name of the target attribute contains a preset suffix, and if it is determined that the fully qualified name contains the preset suffix, perform a full scan on the target file; Based on the result of the full scan, a method-level risk review is performed on the target code; According to the review result of the method-level risk review of the target code, the review result is output, and the review result includes whether there is a risk or there is no risk.
[0007] Based on the above technical solution, preferably, after taking out the submission information from the cache and splitting the target code into a single submission code when executing the scheduled task, the method further includes: Using the developer's submission ID to call a related interface from the code management tool to obtain the modified content for the target code; Traversing the modified contents to search for multiple modified files for each of the submitted codes; By determining whether the file type of the modified file is a file type that requires code review, the modified files that do not require code review are filtered out to obtain a difference file; Filter invalid characters in the difference file to obtain a filtered file; The filter file is scored and review comments are given, and the score and review comments for the filter file are output in Markdown format.
[0008] On the basis of the above technical solution, preferably, after scoring the filter file and giving review opinions, and outputting the score and review opinions for the filter file in Markdown format, the method further includes: The file scores obtained by scoring each of the filtered files are sorted in order of high and low scores; According to the sorting results, determining scores for a preset number of files with the lowest scores; Re-evaluating the filtered files corresponding to the preset number of file scores with the lowest scores to obtain a second review opinion; Output the secondary review opinion.
[0009] Based on the above technical solution, preferably, before scoring each submitted code to obtain a code score and providing review opinions for the submitted code, the method further includes: Collecting open source code from the developer's internal code base; Preprocessing the open source code to obtain a processed code; The processing code is sequentially length-segmented, character string-normalized, and indexed to obtain a plurality of code data blocks; Generating a corresponding vector embedding for each of the code data blocks to obtain a first vector embedding; The first vector is embedded and stored together with the code data block into a vector data block.
[0010] On the basis of the above technical solution, preferably, scoring each submitted code to obtain a code score and providing review opinions for the submitted code further includes: For the submitted code, generate a corresponding vector embedding to obtain a second vector embedding; Performing a similarity search in the vector database by embedding the vector, and calculating the cosine similarity between the second vector embedding and each of the first vector embeddings; Querying multiple cosine similarities whose cosine similarities exceed a preset similarity, and determining similarity vector embeddings corresponding to the cosine similarities whose cosine similarities exceed the preset similarity; Determine the similar data block corresponding to the embedding of the similar vector; Using the similar data blocks as context information and the submitted code as input, generating review comments; The context information is provided with background information related to the submitted code, and combined with the private domain knowledge of the developer's enterprise, semantic understanding and problem identification are performed on the content of the submitted code, including identification of code structure, readability and naming conventions, and optimization suggestions are given to obtain the review opinion.
[0011] On the basis of the above technical solution, preferably, the step of scoring each submitted code to obtain a code score and providing review opinions for the submitted code specifically includes: Determine multiple review levels for preset code reviews, including function level, file level, and system level; Determining a weight value of each of the similar data blocks for each of the review levels; According to the multiple weight values of each review level, an average is calculated to obtain a dynamic weight value of the review level; For the submitted code, generating a corresponding level score according to the review criteria corresponding to the review level; The code score is calculated based on the dynamic weight values corresponding to each review level and the level score.
[0012] In a second aspect of the present application, a system for intelligent code review is provided, the system comprising an acquisition module, a processing module and an output module, wherein: The acquisition module is used to bind a trigger mechanism based on the project that the developer needs to conduct code review in the code management tool, so that the code management tool can automatically call the background interface of the intelligent code review system after receiving the code pushed by the user-specified branch; The acquisition module is used to acquire the submitted local code and automatically call the background interface according to the trigger mechanism, wherein the local code includes the incremental code or the full code submitted by the developer; The processing module is used to filter the local code if it is determined that the type of the local code is the incremental code, and write the submission information corresponding to the target code that meets the filtering condition into the cache to wait for the scheduled task to execute the review task; The processing module is used to retrieve the submission information from the cache when executing the scheduled task, and split the target code into individual submission codes according to the submission information; The processing module is used to score each submitted code, obtain a code score, and give review opinions on the submitted code; The output module is used to calculate the average score of the multiple code scores to obtain the comprehensive score corresponding to the target code.
[0013] On the basis of the above technical solution, preferably, the acquisition module is used to acquire the source file of the local code if it is determined that the type of the local code is full code; The processing module is used to filter out target files that need to be security scanned from the source files; The acquisition module is used to parse the syntax tree of the target file and recursively acquire the target attributes in the target file; The acquisition module is used to check whether the fully qualified name of the target attribute contains a preset suffix, and if it is determined that the fully qualified name contains the preset suffix, perform a full scan on the target file; The processing module is used to perform a method-level risk review on the target code based on the result of the full scan; The output module is used to output the review result according to the review result of the method-level risk review of the target code, and the review result includes whether there is a risk or there is no risk.
[0014] Based on the above technical solution, preferably, the processing module is used to call a related interface from the code management tool using the developer's submission ID to obtain the modified content for the target code; The processing module is used to traverse the modified content to search for multiple modified files for each of the submitted codes; The processing module is used to filter out modified files that do not require code review by determining whether the file type of the modified file is a file type that requires code review, and obtain a difference file; The processing module is used to filter invalid characters in the difference file to obtain a filtered file; The processing module is used to score the filter file and give review opinions, and output the score and review opinions for the filter file in Markdown format.
[0015] On the basis of the above technical solution, preferably, the processing module is used to sort the file scores obtained by scoring each of the filtered files in order of high and low scores; The processing module is used to determine scores of a preset number of files with the lowest scores according to the sorting results; The processing module is used to re-evaluate the filtered files corresponding to the preset number of file scores with the lowest scores to obtain secondary review opinions; The output module is used to output the secondary review opinion.
[0016] Based on the above technical solution, preferably, the acquisition module is used to collect the open source code of the developer's internal code library; The processing module is used to pre-process the open source code to obtain a processed code; The processing module is used to sequentially perform length segmentation, string normalization and index construction on the processing code to obtain multiple code data blocks; The processing module is used to generate a corresponding vector embedding for each of the code data blocks to obtain a first vector embedding; The processing module is used to embed the first vector and store it together with the code data block into a vector data block.
[0017] On the basis of the above technical solution, preferably, the processing module is used to generate a corresponding vector embedding for the submitted code to obtain a second vector embedding; The processing module is used to perform a similarity search in the vector database by embedding the vector, and calculate the cosine similarity between the second vector embedding and each of the first vector embeddings; The processing module is used to query multiple cosine similarities that exceed a preset similarity, and determine similarity vector embeddings corresponding to the cosine similarities that exceed the preset similarity; The processing module is used to determine the similar data block corresponding to the embedding of the similar vector; The processing module is used to use the similar data block as context information and the submitted code as input to generate review comments; The processing module is used to provide background information related to the submitted code in the context information, and combine the private domain knowledge of the developer enterprise to perform semantic understanding and problem identification on the content of the submitted code, including identifying code structure, readability and naming conventions, and providing optimization suggestions to obtain the review opinion.
[0018] Based on the above technical solution, preferably, the processing module is used to determine multiple review levels of preset code review, including function level, file level and system level; The processing module is used to determine the weight value of each of the similar data blocks for each of the review levels; The processing module is used to calculate the average value according to the multiple weight values of each review level to obtain the dynamic weight value of the review level; The processing module is used to generate a corresponding level score for the submitted code according to the review criteria corresponding to the review level; The processing module is used to calculate the code score according to the dynamic weight value and level score corresponding to each review level.
[0019] In the third aspect of the present application, an electronic device is provided, including a processor, a memory, a user interface and a network interface, the memory is used to store instructions, the user interface and the network interface are both used to communicate with other devices, and the processor is used to execute the instructions stored in the memory so that the electronic device executes any one of the methods described above.
[0020] In a fourth aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores instructions, and when the instructions are executed, any of the methods described above is executed.
[0021] In summary, one or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages: 1. This application uses a binding trigger mechanism to automatically call the background interface when the developer submits the code in the code management tool. At the same time, the classification of incremental code and full code and the centralized processing of submission information using scheduled tasks break down complex code review tasks into fine-grained individual submission codes for step-by-step analysis, which helps to improve the accuracy of the review. In addition, through intelligent scoring and automatic generation of review opinions, combined with comprehensive statistics of multiple scores, fast and standardized review results are provided, avoiding the subjectivity and omissions of manual review, thereby significantly improving the efficiency and quality of code review.
[0022] 2. By automatically processing the modified content of the submitted code, we can filter out the files that need to be reviewed and filter out invalid characters, thereby simplifying the review content and improving efficiency. Through intelligent scoring and standardized Markdown format output of review comments, we can quickly generate clear and structured feedback to help developers understand the review results more intuitively.
[0023] 3. Through a secondary review of low-scoring files, we further focus on high-risk or complex issues that may exist in the code, ensuring that key issues receive more in-depth analysis and optimization suggestions. This effectively improves the comprehensiveness and accuracy of code reviews, avoids missing potential issues, and optimizes resource utilization, focusing on files that need the most attention, thereby improving code quality and team collaboration efficiency.
[0024] 4. By building a vectorized model and similarity matching mechanism for the internal code base of the enterprise, the submitted code is associated with the contextual information of the historical code and open source code to provide accurate semantic background support. Combined with private domain knowledge, it can more accurately identify structural problems, lack of readability, and irregular naming in the code, and give targeted optimization suggestions. It effectively improves the intelligence and accuracy of code review, enhances the adaptability to complex code scenarios, and reduces the subjectivity and omission risk of review, thereby significantly improving code quality and development efficiency.
[0025] 5. By introducing multi-level review dimensions at the function level, file level, and system level, and adjusting the importance of each level according to the dynamic weight value, we ensure that the review results can comprehensively reflect the quality of the local details of the code and the overall architecture. Through the hierarchical scoring mechanism, more comprehensive and accurate code scores can be generated, while making the review process more targeted and adaptable. It effectively improves the scientificity and objectivity of code reviews, provides developers with more guiding optimization suggestions, and promotes the overall improvement of code quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 It is a flowchart of a method for intelligent code review disclosed in an embodiment of the present application; Figure 2 It is a module schematic diagram of a system for intelligent code review disclosed in an embodiment of the present application; Figure 3 It is a structural schematic diagram of an electronic device disclosed in an embodiment of the present application.
[0027] Explanation of the reference numerals: 201, acquisition module; 202, processing module; 203, output module; 301, processor; 302, communication bus; 303, user interface; 304, network interface; 305, memory. DETAILED DESCRIPTION
[0028] In order to enable technicians in this field to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments.
[0029] In the description of the embodiments of the present application, words such as "for example" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "for example" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "for example" or "for example" is intended to present related concepts in a specific way.
[0030] In the description of the embodiments of the present application, the meaning of the term "multiple" refers to two or more. For example, multiple systems refer to two or more systems, and multiple screen terminals refer to two or more screen terminals. In addition, the terms "first" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance or implicitly indicating the indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. The terms "include", "comprise", "have" and their variations all mean "including but not limited to", unless otherwise specifically emphasized.
[0031] In the current software development process, technical managers usually need to conduct quality reviews on the code submitted by developers to ensure that the code complies with coding standards and design principles and eliminates potential security risks. However, due to the high frequency of submission or the existence of complex modules, technical managers face tremendous time and energy pressure, especially when they are not familiar with certain modules. The review may be subjective or have omission risks, thus affecting the code quality and development progress. Therefore, how to use intelligent tools and automation technology to assist in code review, reduce the burden of technical managers and improve review efficiency has become a key issue in optimizing modern software development processes.
[0032] This embodiment discloses a method for intelligent code review. Figure 1 , including the following steps S110-S160: S110, based on the project binding trigger mechanism that the developer needs to perform code review in the code management tool, the code management tool can automatically call the background interface of the intelligent code review system after receiving the code pushed by the user-specified branch.
[0033] The method for intelligent code review disclosed in the embodiment of the present application is applied to a server, which includes but is not limited to electronic devices such as mobile phones, tablet computers, wearable devices, PCs (Personal Computers), etc., and can also be a background server that runs an intelligent code review method. The server can be implemented as an independent server or a server cluster composed of multiple servers.
[0034] As IT Internet and financial technology companies pay more attention to the DevOps integrated development model, continuously improving software quality has become an important factor in the software delivery process. Based on the requirements of system security and code quality, we hope that after the R&D personnel submit the code, the modified content can be merged into the main branch for online only after passing the code review. In terms of the code review method, the current review methods mainly include automatic code review and manual review. Manual code review and automated code review each have their own advantages and limitations. Manual code review can deeply understand the code logic and put forward constructive opinions, especially when it involves complex business logic or highly creative designs, manual review can better play its advantages. However, manual review takes a long time, and the review standards may vary due to differences in personal experience. In contrast, automated code review such as SonarQube can complete a large number of basic code checks in a short time, such as format consistency, potential bug detection, etc., greatly improving efficiency. Tools such as SonarQube can also run in a continuous integration environment, providing feedback immediately before the code is submitted, which helps to quickly correct problems and ensure that the code meets established standards. However, automated tools may have difficulty identifying deeper design issues or complex logical errors. They usually rely on preset rules and are not as flexible as manual review in handling some special scenarios.
[0035] To this end, a method of intelligent code review disclosed in an embodiment of the present application aims to assist the code review process in the research and development process through intelligent means, help the technical person in charge to complete the code review work more efficiently, and improve the quality of code delivery. Through this method, the review results can be automatically fed back to the DevOps platform as a basis for quality control of task completion. Specifically, when the developer submits the code, the server will automatically conduct a comprehensive review of it, promptly discover and point out potential problems, so that the developer can quickly make corrections. When the technical person in charge conducts the final code merge review, he can refer to the opinions provided by the intelligent review to further enhance the accuracy and efficiency of the review. In addition, based on these review results, testers can also carry out subsequent testing work in a more targeted manner, thereby jointly promoting the improvement of the quality of the entire project.
[0036] According to the code management tools used by the enterprise, such as GitLab, WebHook is configured in the code management tool to bind it to the background interface of the intelligent code review system. The developer selects the project that needs code review in the code management tool and specifies the target branch as the trigger condition. Whenever the user pushes code to the specified branch, WebHook will capture this event and trigger the pre-bound review system interface. After receiving the trigger request, the review system parses the event type to ensure that only Commit type code submission requests are processed. Subsequently, the review system writes the submission information to the cache queue and waits for the scheduling task to execute the review process. Through this automated binding mechanism, the seamless connection between code submission and the review system can be efficiently achieved, ensuring the timeliness of code review and improving development efficiency and code quality.
[0037] S120, obtaining the local code developed and submitted by the developer, and automatically calling the background interface according to the trigger mechanism.
[0038] After completing local code development, developers submit the code to the specified branch through version control tools such as Git, and include necessary comments such as the task ID in the submission information. The WebHook configuration in the code management platform will detect the push event and trigger the bound intelligent code review system backend interface. After receiving the trigger request, the backend interface extracts information such as the submitted branch, submission ID, and modified content from the event data. Subsequently, the API interface provided by the code management platform is called to obtain specific code change files and content. Through this automated process, a full-link trigger mechanism can be implemented from the developer submitting the code to the backend interface call without manual intervention, greatly improving the response efficiency and accuracy of code review.
[0039] Furthermore, in addition to scanning the code quality of the added code, the existing code also needs to be scanned for security, and the scanning results are used as a quality gate for online upgrades to improve the overall code quality. The scanning system mainly includes two parts of logic: parsing whether there are methods for manually operating database connections in the class; and using the large language model capability to scan for database leakage issues in the method dimension for methods that manually operate database connections.
[0040] In one possible implementation, after obtaining the submitted local code and automatically calling the background interface according to the trigger mechanism, the method also includes: if it is determined that the type of the local code is full code, obtaining the source file of the local code; filtering out the target file that needs to be security scanned from the source file; parsing the syntax tree of the target file, and recursively obtaining the target attribute in the target file; checking whether the fully qualified name of the target attribute contains a preset suffix, if it is determined that the fully qualified name contains the preset suffix, performing a full scan on the target file; based on the results of the full scan, performing a method-level risk review on the target code; based on the review results of the method-level risk review on the target code, outputting the review results, the review results including the existence of risk or the absence of risk.
[0041] Specifically, obtain the source files of the code and filter out the files that need to be scanned for security. After pulling the warehouse code to the server temporary directory according to the system warehouse bound by the user in the DevOps R&D and operation integration platform, define the filtering rules according to the company's internal R&D framework. Specifically, if the path of the class file contains the "IF-" prefix or client suffix, such files will not be scanned. Parse the abstract syntax code (AST) of the source file to recursively obtain all internal classes, member variables, imported dependency packages, methods and other properties of the file. Obtaining information about each class facilitates subsequent inspection to see if there is any manual operation of the database connection.
[0042] Check whether there is manual database connection operation in the class. If there is, extract the method information of the specific database operation to handle resource leakage. The specific inspection logic is as follows: Check whether the package suffix of the class contains "Connection", "PreparedStatement", "ResultSet" fields. If it contains, check whether there is an attribute ending with "Connection", "PreparedStatement", "ResultSet" in the fully qualified name of the attribute type of the class. If these two conditions are met at the same time, it can be considered that there is a manual database connection operation in this class, and a full scan is required.
[0043] Use the method body as the backend input to check whether there is a risk of resource leakage. Usually, the model context length is limited. In order to avoid excessive context information affecting the code review, the review is conducted in the method dimension. After detecting that the fully qualified name of the attribute type has a suffix of "Connection", "PreparedStatement", or "ResultSet", the method body using this attribute is parsed as the review input of the large language model.
[0044] After receiving the method body with possible database connection leakage from the full code review service, the backend service performs the code review task. The format of the returned result is as follows: There are two specific formats: Risk: {"fields":"variable name","checkResult":"check failed:`variable name`specific problem description"}. No risk: {"fields":"variable name","checkResult":"check passed: no variable found or no problem"}.
[0045] The results are written to the R&D and operation integration platform. After receiving the results returned by the backend, the full code review service parses the returned results and associates the code review situation with the specific system in the DevOps R&D and operation integration platform, and also serves as a gate indicator in the R&D process. The scan results are sent to the task submitter. After the full code scan is completed, the platform will send an email to notify the specific situation of this scan, so that R&D personnel can handle the scan results in a timely manner.
[0046] S130, if it is determined that the type of the local code is the incremental code, the local code is filtered, and the submission information corresponding to the target code that meets the filtering conditions is written into the cache to wait for the scheduled task to execute the review task.
[0047] After receiving the submission information, the server filters out non-push submission methods based on whether the event type is Commit type, and then writes the submission information that meets the filtering conditions into the cache and waits for the scheduled task to execute the review work.
[0048] In one possible implementation, the local code is filtered, and the submission information corresponding to the target code that meets the filtering conditions is written into the cache waiting for the scheduled task to execute the review task, specifically including: judging whether the event type is a code submission type based on the event type of the local code; if it is determined that the event type is not a code submission type, and the event type is a tag creation type or a branch merge type, filtering the local code; if it is determined that the event type is a code submission type, performing a review of the local code.
[0049] Specifically, after receiving the trigger request, the event type field such as event_type or object_kind is parsed. If the event type is not a code submission type, such as tag creation or branch merging, the specific event type is further determined. If it is a code submission type, that is, a push event, the code review process is entered. Otherwise, the server will enter the screening and processing stage to perform specific processing on non-code submission events.
[0050] For detected non-code commit events, the server filters them based on the event type. If the event type is tag creation, the server extracts tag information such as tag name and associated commits and records them, but does not trigger code review. If the event type is branch merge, the server parses the commit history of the merged source branch and target branch to update the code base status, but also skips the review process. This step ensures that non-code commit events do not trigger unnecessary operations, thereby improving the server's code review efficiency.
[0051] S140, when executing the scheduled task, the submission information is retrieved from the cache, and the target code is split into individual submission codes according to the submission information.
[0052] When executing a scheduled task, the server will retrieve the stored submission information from the cache, where each piece of information contains metadata about the code submission, such as the submission ID, branch name, and author. Next, the server calls the relevant API interface of the code management tool based on the submission ID to obtain the detailed modification content of the corresponding submission. By parsing the submission content, the server splits the target code into individual submissions (i.e., a single Commit), each of which may contain modification records of multiple files. For these modification records, the server analyzes the file types one by one to determine whether they require code review, and filters out file types that do not require review (such as non-code files or configuration files). Finally, the server organizes the screened files and their modifications according to the dimensions of a single Commit, providing data input for subsequent code scoring and review. This process ensures that the review task focuses on valid code and improves review efficiency and accuracy.
[0053] In a possible implementation, after taking out the submission information from the cache when executing the scheduled task and splitting the target code into individual submission codes, the method also includes: using the developer's submission ID to call the relevant interface from the code management tool to obtain the modified content for the target code; traversing the modified content to find multiple modification files for each submission code; filtering out the modified files that do not require code review by determining whether the file type of the modified file is a file type that requires code review to obtain a difference file; filtering out invalid characters in the difference file to obtain a filtered file; scoring the filtered file and giving review comments, and outputting the score and review comments for the filtered file in Markdown format.
[0054] Specifically, the server calls the API of the code management tool (such as GitLab) through the commit ID in the commit information to obtain the modification record corresponding to the commit ID. The information returned by the API usually includes the detailed changes submitted, such as the list of modified files, the specific code snippets of the changes (i.e., difference files or diffs), author information, and the timestamp of the submission. These data provide complete context for subsequent code reviews.
[0055] From the modification records returned by the API interface, the server goes through all the modified files contained in the submitted code one by one. The information of each file includes the file path, file name, file type (such as file extension), and its modified content. By analyzing them one by one, the server can determine which files are valid code files, thus preparing for the review process.
[0056] The server uses a predefined file type whitelist such as .java, .py, and other code file types that support review to filter out files that do not meet the criteria. For example, configuration files such as .yaml, document files such as .md, and binary files such as .png will be excluded. The files retained after screening form a difference file list to ensure that the review is only for code files that actually need attention.
[0057] The content in the difference file may contain a large number of invalid characters used to identify changes, such as plus and minus signs generated by the Git tool. These characters are not helpful for the analysis of large language models and may even increase unnecessary context complexity. The server uses regular expressions or string processing methods to clean up these invalid characters and only retain the actual changes in the code, forming a more concise filter file.
[0058] The server sends each filtered file together with predefined prompts to the large language model for analysis. The prompts usually include review criteria such as code style, performance optimization, security, etc. and output format requirements. After the large language model analyzes the filtered file, it generates scores and review opinions according to the requirements of the prompts, including: code scores, potential problems, recommended improvement measures, etc., and organizes the results in Markdown format for subsequent display and integration. Markdown format output helps to display the review results in a structured manner, such as hierarchical titles, code blocks, and tables, to improve readability.
[0059] S150, scoring each submitted code, obtaining a code score, and providing review comments on the submitted code.
[0060] In a possible implementation, before scoring each submitted code, obtaining a code score, and providing review comments on the submitted code, the method also includes: collecting open source code from the developer's internal enterprise code library; preprocessing the open source code to obtain processed code; performing length segmentation, string normalization, and index construction on the processed code in sequence to obtain multiple code data blocks; generating a corresponding vector embedding for each code data block to obtain a first vector embedding; and storing the first vector embedding and the code data block together in the vector data block.
[0061] Specifically, in enterprise scenarios, there is a lot of private data within the enterprise, such as internal development documents, middleware SDKs, API documents, etc., and code review models are needed to learn and adapt to this type of private data. Traditional model training methods require the preparation of expensive GPU machine clusters, which have high training costs and cannot take effect in real time, and cannot meet the needs of rapid knowledge updates.
[0062] To solve this problem, we use the RAG enhancement method to optimize the large language model of code review. The code review model obtains private domain knowledge in the search engine in real time through retrieval enhancement technology, allowing the code review model to generate code or answer questions based on enterprise knowledge. In addition, the enterprise can update and validate private domain knowledge in real time, allowing the code review model to always generate or answer questions based on the latest private domain knowledge. At the same time, the code review model improves the recall rate of knowledge data through multi-dimensional recall, refined knowledge segmentation and other technologies, and selects the most relevant knowledge through fine sorting strategy and relevance screening strategy to introduce into the context of generation / question and answer, further enhancing the practicality and accuracy of the system.
[0063] The system extracts open source code from the company's internal code base, including code developed and open sourced by the company itself and open source code obtained from third parties. These codes may be included in the public code management platform. When extracting, it is necessary to ensure the copyright compliance of the code and filter out the code related to the current business field to lay the foundation for subsequent analysis.
[0064] The open source code preprocessing step is aimed at cleaning and standardizing the code content. Code cleaning mainly cleans the collected open source code and the company's internal code base. Specific cleaning rules include: filtering files with more than 1,000 lines, filtering data with functions less than 50 lines, filtering data with a letter ratio of less than 25%, filtering out files with a comment ratio greater than 80%, filtering out decompiled data, removing sensitive information in the code, filtering files with a large number of comment lines, etc.
[0065] The AST extraction method uses abstract syntax analysis to parse the methods in the class file and build a method-level code database based on the method. The method body data parsed from the abstract syntax is written into the method-level code database.
[0066] The processed code is further processed for length segmentation, string normalization, and index construction. Because the code data is too long in its original state to fit into the context window of the model, it needs to be divided into smaller segments so that it can be placed in the large model context window after indexing. Specifically, the code file is segmented using the character-based text segmenter CharacterTextSplitter. The specific parameters are: chunksize=1024 and chunkoverlap=128. The segmented code fragments are then string normalized, including using regular expressions to remove extra spaces at both ends of the string, converting all strings to lowercase, and removing special characters in the code fragment. Finally, the normalized code fragments are used to build the index. The storage of specific code data blocks needs to support semantic search across text blocks, so vector embeddings need to be generated for each code data block, and then they are stored together with their vector embeddings. The way to generate vector embeddings for each code data block is the general text vector model, and the generated vector embeddings are stored in the vector database Weaviate.
[0067] In a possible implementation, each submitted code is scored to obtain a code score, and review opinions are given for the submitted code, which specifically includes: generating a corresponding vector embedding for the submitted code to obtain a second vector embedding; performing a similarity search in a vector database through the vector embedding to calculate the cosine similarity between the second vector embedding and each first vector embedding; querying multiple cosine similarities whose cosine similarities exceed a preset similarity, and determining similar vector embeddings corresponding to multiple cosine similarities whose cosine similarities exceed a preset similarity; determining similar data blocks corresponding to similar vector embeddings; using the similar data blocks as context information and the submitted code as input to generate review opinions; providing background information related to the submitted code in the context information, combining the private domain knowledge of the developer's enterprise, performing semantic understanding and problem identification on the content of the submitted code, including identifying code structure, readability and naming conventions, and giving optimization suggestions to obtain review opinions.
[0068] Specifically, for the submitted code, the same general text vector model as in the preprocessing stage is used to generate a vector embedding of the code. This embedding represents the grammatical structure and semantic features of the submitted code, and is used to locate other code snippets with similar semantics in the vector space.
[0069] A similarity search is performed on the second vector embedding of the submitted code, and its cosine similarity with each first vector embedding stored in the vector database is calculated. Cosine similarity reflects the similarity between two code snippets in the semantic space, and the closer the value is to 1, the more similar the code snippets are.
[0070] Items that exceed a preset similarity threshold, such as 0.5, are selected from the calculated cosine similarity. These high-similarity items represent the reference code snippets in the vector database that are most relevant to the submitted code. Based on the selected high-similarity items, the corresponding first vector embedding is determined. These similar vector embeddings store rich contextual information in the database and can serve as an important reference for the current code review.
[0071] We further query code data chunks associated with high similarity vector embeddings. These data chunks are extracted from enterprise code bases or open source code and have high functional, structural, or semantic relevance to the submitted code.
[0072] The filtered similar data blocks are provided to the code review model as context information, and the submitted code is used as the main input. The model combines the context information and the submitted code for comprehensive analysis, and generates review opinions for the current code based on the implementation logic and best practices of the existing code.
[0073] Extract background information directly related to the submitted code function or module from the context information, such as algorithm ideas, design goals or performance optimization measures, and combine the company's private domain knowledge, such as coding standards and business scenarios, to semantically understand and identify problems in the submitted code. This process focuses on evaluating the structural rationality, readability and naming standards of the code to help discover potential problems or room for improvement. Based on the results of the model analysis, combined with context information and private domain knowledge, specific optimization suggestions are given. This includes adjusting code logic, improving variable naming, and improving code efficiency. Finally, the model outputs scores and detailed review comments for the submitted code in Markdown format, providing developers with clear and definite directions for improvement.
[0074] Specifically, the language model is used to perform semantic analysis on the submitted code, identifying the logical structure of the code such as loops, conditional judgments, function calls, etc. and potential problems such as infinite loop risks and duplicated code. Combined with contextual information, it is determined whether the code is consistent with the team standards. For example, it checks whether the naming conventions are met, whether the variable names are descriptive, or whether the code is modular enough to improve maintainability.
[0075] Based on the problems found, we provide optimization suggestions by combining contextual information and private domain knowledge. For example, we modify unclear or lengthy variable names, optimize inefficient code segments, and provide implementation logic suggestions that are more in line with business intent. Finally, we generate a clear Markdown review report, including code scores, problem lists, specific suggestions, etc.
[0076] In one possible implementation, each submitted code is scored to obtain a code score, and review opinions are given for the submitted code, specifically including: determining multiple review levels for preset code reviews, including function level, file level, and system level; determining weight values for each similar data block for each review level; averaging multiple weight values for each review level to obtain a dynamic weight value for the review level; for the submitted code, generating a corresponding level score according to the review criteria corresponding to the review level; and calculating the code score based on the dynamic weight values and level scores corresponding to each review level.
[0077] Specifically, when conducting a code review, it is first necessary to define multiple levels for review in order to refine and refine the review criteria layer by layer. The review levels disclosed in the embodiments of the present application include: function-level review, which evaluates the quality of each function or method, focusing on the readability, functionality, and efficiency of the code. File-level review, which reviews the overall structure and specifications of all the code in a file, including the organization and modularity of the code. System-level review, which evaluates the code quality of the entire system or project, and checks the overall architectural design, maintainability, and scalability of the system.
[0078] In some projects, the three review levels of function level, file level and system level may be the most important and necessary review dimensions, and other levels such as module level and component level are not prioritized. A typical scenario is when the project involves relatively independent functional modules, and the development of these modules is relatively independent, and the overall system architecture is relatively stable. In this case, the review focus is usually on the logical correctness of a single function (function level), the standardization and maintainability of the code in a single file (file level), and the structural rationality of the entire system and the collaboration between modules (system level). In particular, in the development of large-scale Web applications, developers mainly focus on the implementation of a single interface, the organization and structure of the interface file, and the architectural design of the entire application system, and will not pay too much attention to the review of more fine-grained modules or components. In this case, the function level, file level and system level reviews are sufficient to cover the quality assurance requirements of the code, so no other additional review levels are set.
[0079] When conducting code reviews, the scoring criteria for each level are different, so it is necessary to assign appropriate weight values to the review criteria for each level. Similar data blocks such as function complexity, code repetition rate, etc. will have different impacts at different review levels. For example, a function-level review can focus on the performance and logical clarity of the code, while a file-level review may pay more attention to the structure and specifications of the code. According to the degree of influence of the data block, a weight value is assigned to each level, so that the impact of different review dimensions on the final score is more accurate.
[0080] For each review level, a dynamic weight value can be calculated based on the specific weight value. This dynamic weight value is not statically fixed, but dynamically adjusted according to the specific code submission. For example, if a submission involves more function-level changes, the function-level weight can be appropriately increased. By calculating the weighted average of each weight value, the final dynamic weight value of each review level is obtained, thereby ensuring the flexibility and accuracy of the review.
[0081] During the review process, hierarchical scores are generated for the standards of each level. For example, for function-level reviews, you can check the execution efficiency, logical clarity, naming conventions, etc. of the function; for file-level reviews, you can check whether the code complies with the overall structural specifications of the project and whether the comments are sufficient; system-level reviews involve the rationality of the architecture design, the degree of coupling between modules, etc. Each review level has specific scoring criteria, and reviewers score the code based on these criteria.
[0082] Finally, the final code score is obtained by comprehensively calculating the score of each review level and its dynamic weight value. Specifically, code score = function-level score × function-level dynamic weight + file-level score × file-level dynamic weight + system-level score × system-level dynamic weight. In this way, the scores of different levels will have a corresponding impact on the final score according to their weights, thereby ensuring the comprehensiveness and accuracy of the review results.
[0083] S160, calculating the average scores of multiple code ratings to obtain a comprehensive score corresponding to the target code.
[0084] After scoring each file in a single submission, the server generates a score list, with each score corresponding to the modification score of the file. All file scores are traversed, added up and divided by the number of files to calculate the average score of all files. This score represents the overall performance of the entire submission in terms of modification quality. The calculated average score is used as the comprehensive score of the target code and recorded in the review report, with corresponding explanations and data support so that developers can understand the overall quality situation.
[0085] In a possible implementation, after scoring the filtered files and providing review opinions, and outputting the scores and review opinions for the filtered files in Markdown format, the method also includes: sorting the file scores obtained by scoring each filtered file in order of high and low scores; determining a preset number of file scores with the lowest scores based on the sorting results; re-reviewing the filtered files corresponding to the preset number of file scores with the lowest scores to obtain secondary review opinions; and outputting the secondary review opinions.
[0086] Specifically, the results of scoring all filtered files are collected and the scores are sorted from high to low. The score list is sorted using a sorting algorithm (such as quick sort or a built-in sorting function), while retaining the association information between the score and the corresponding file. According to a preset number (such as the three lowest-scoring files), multiple files with the lowest scores are selected from the sorted score list, and the identification information of these files is recorded for further operations.
[0087] For the files with the lowest scores, the large language model or other review modules are re-called for in-depth review. In the second review, the possible problems in the files are further analyzed by combining contextual information, enterprise private domain knowledge and problem types. The model outputs more detailed and specific improvement suggestions, such as code logic errors, potential security issues or unreasonable designs. The results of the second review are output in Markdown format, providing improvement suggestions for low-scoring files, and attaching specific sample code when necessary. The generated content includes: the name of the second review file, problem description, optimization suggestions and comprehensive improvement plan.
[0088] By adopting the technical solution disclosed in the embodiment of the present application, based on the binding trigger mechanism, when the developer submits the code in the code management tool, the server can automatically call the background interface. At the same time, the server uses scheduled tasks to centrally process the submission information, breaking down the complex code review tasks into fine-grained individual submission codes for step-by-step analysis, which helps to improve the accuracy of the review. In addition, the server provides fast and standardized review results through intelligent scoring and automatic generation of review opinions, combined with comprehensive statistics of multiple scores, avoiding the subjectivity and omissions of manual review, thereby significantly improving the efficiency and quality of code review.
[0089] This embodiment also discloses a system for intelligent code review. Figure 2 The system includes an acquisition module 201, a processing module 202 and an output module 203, wherein: The acquisition module 201 is used to bind the trigger mechanism based on the project that the developer needs to review in the code management tool, so that the code management tool can automatically call the background interface of the intelligent code review system after receiving the code pushed by the user-specified branch.
[0090] The acquisition module 201 is used to acquire the submitted local code and automatically call the background interface according to the trigger mechanism, wherein the local code includes the incremental code or the full code submitted by the developer.
[0091] Processing module 202 is used to filter the local code if it is determined that the type of the local code is incremental code, and write the submission information corresponding to the target code that meets the filtering conditions into the cache to wait for the scheduled task to execute the review task.
[0092] The processing module 202 is used to retrieve the submission information from the cache when executing the scheduled task, and split the target code into individual submission codes according to the submission information.
[0093] The processing module 202 is used to score each submitted code, obtain a code score, and provide review opinions for the submitted code.
[0094] The output module 203 is used to calculate the average score of multiple code ratings to obtain a comprehensive score corresponding to the target code.
[0095] In a possible implementation, the acquisition module 201 is configured to acquire a source file of the local code if it is determined that the type of the local code is full code.
[0096] The processing module 202 is used to filter out target files that need to be security scanned from source files.
[0097] The acquisition module 201 is used to parse the syntax tree of the target file and recursively acquire the target attributes in the target file.
[0098] The acquisition module 201 is used to check whether the fully qualified name of the target attribute contains a preset suffix. If it is determined that the fully qualified name contains the preset suffix, a full scan is performed on the target file.
[0099] The processing module 202 is used to perform a method-level risk review on the target code based on the result of the full scan.
[0100] The output module 203 is used to output the review result according to the review result of the method-level risk review of the target code, and the review result includes whether there is a risk or there is no risk.
[0101] In a possible implementation, the processing module 202 is used to call a related interface from a code management tool using the developer's submission ID to obtain the modified content for the target code.
[0102] The processing module 202 is used to traverse the modified content to search for multiple modified files for each submitted code.
[0103] The processing module 202 is used to filter out the modified files that do not require code review by determining whether the file type of the modified file is a file type that requires code review, and obtain a difference file.
[0104] The processing module 202 is used to filter invalid characters in the difference file to obtain a filtered file.
[0105] The processing module 202 is used to score the filtered file and give review comments, and output the score and review comments for the filtered file in Markdown format.
[0106] In a possible implementation, the processing module 202 is configured to sort the file scores obtained by scoring each filtered file in order of high and low scores.
[0107] The processing module 202 is used to determine a preset number of scores of files with the lowest scores according to the sorting results.
[0108] The processing module 202 is used to re-evaluate the filtered files corresponding to a preset number of file scores with the lowest scores to obtain secondary review opinions.
[0109] The output module 203 is used to output the secondary review opinions.
[0110] In a possible implementation, the acquisition module 201 is used to collect open source codes from the developer's internal code base.
[0111] The processing module 202 is used to pre-process the open source code to obtain a processed code.
[0112] The processing module 202 is used to perform length segmentation, string normalization and index construction on the processing code in sequence to obtain multiple code data blocks.
[0113] The processing module 202 is used to generate a corresponding vector embedding for each code data block to obtain a first vector embedding.
[0114] The processing module 202 is configured to embed the first vector and store 305 it together with the code data block into the vector data block.
[0115] In a possible implementation, the processing module 202 is configured to generate a corresponding vector embedding for the submitted code to obtain a second vector embedding.
[0116] The processing module 202 is used to perform similarity search in the vector database through vector embedding, and calculate the cosine similarity between the second vector embedding and each first vector embedding.
[0117] The processing module 202 is used to query multiple cosine similarities whose cosine similarities exceed a preset similarity, and determine similarity vector embeddings corresponding to the multiple cosine similarities whose cosine similarities exceed the preset similarity.
[0118] The processing module 202 is used to determine similar data blocks corresponding to similar vector embeddings.
[0119] The processing module 202 is used to generate review comments by taking similar data blocks as context information and the submitted code as input.
[0120] The processing module 202 is used to provide background information related to the submitted code in the context information, and combine the private domain knowledge of the developer enterprise to perform semantic understanding and problem identification on the content of the submitted code, including identifying the code structure, readability and naming conventions, and giving optimization suggestions to obtain review opinions.
[0121] In a possible implementation, the processing module 202 is used to determine multiple review levels of preset code reviews, including function level, file level, and system level.
[0122] The processing module 202 is used to determine the weight value of each similar data block for each review level.
[0123] The processing module 202 is used to calculate the average value according to the multiple weight values of each review level to obtain the dynamic weight value of the review level.
[0124] The processing module 202 is used to generate corresponding level scores for the submitted code according to the review criteria corresponding to the review level.
[0125] The processing module 202 is used to calculate the code score according to the dynamic weight value and level score corresponding to each review level.
[0126] It should be noted that: when the system provided in the above embodiment realizes its functions, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the system and method embodiments provided in the above embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0127] This embodiment also discloses an electronic device, referring to Figure 3 The electronic device may include: at least one processor 301 , at least one communication bus 302 , a user interface 303 , a network interface 304 , and at least one memory 305 .
[0128] The communication bus 302 is used to realize the connection and communication between these components.
[0129] The user interface 303 may include a display screen (Display) and a camera (Camera). Optionally, the user interface 303 may also include a standard wired interface and a wireless interface.
[0130] The network interface 304 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).
[0131] Among them, the processor 301 may include one or more processing cores. The processor 301 uses various interfaces and lines to connect various parts in the entire server, and executes various functions of the server and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory 305, and calling data stored in the memory 305. Optionally, the processor 301 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 301 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 301, and it can be implemented separately through a chip.
[0132] Among them, the memory 305 may include a random access memory (RAM) or a read-only memory (Read-Only Memory). Optionally, the memory includes a non-transitory computer-readable storage medium. The memory 305 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 305 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 305 may also be at least one storage device located away from the aforementioned processor 301. The memory 305 as a computer storage medium may include an operating system, a network communication module, a user interface 303 module, and an application program of a method for intelligent code review.
[0133] In the electronic device shown in FIG. 3 , the user interface 303 is mainly used to provide an input interface for the user and obtain data input by the user; and the processor 301 can be used to call an application program storing a method of intelligent code review in the memory 305. When executed by one or more processors 301, the electronic device executes one or more methods in the above-mentioned embodiments.
[0134] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required for the present application.
[0135] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0136] In the several embodiments provided in this application, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some service interfaces, and the indirect coupling or communication connection of devices or units can be electrical or other forms.
[0137] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0138] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0139] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a memory 305 and includes several instructions for a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned memory 305 includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk.
[0140] The present application also discloses a computer-readable storage medium, wherein the computer-readable storage medium stores instructions. When executed by one or more processors 301, the electronic device executes one or more of the methods described in the above embodiments.
[0141] The above is only an exemplary embodiment of the present disclosure, and the scope of the present disclosure cannot be limited thereto. That is, any equivalent changes and modifications made according to the teachings of the present disclosure are still within the scope of the present disclosure. After considering the disclosure of the specification and the truth of practice, it will be easy for those skilled in the art to think of other embodiments of the present disclosure. This application is intended to cover any modification, use or adaptation of the present disclosure, which follows the general principles of the present disclosure and includes common knowledge or customary technical means in the technical field that are not recorded in the present disclosure. The description and examples are regarded as exemplary only, and the scope and spirit of the present disclosure are defined by the claims.
Claims
1. A method for intelligent code review, characterized in that: The method comprises: A project binding trigger mechanism based on the developer's need to conduct code review in the code management tool, so that the code management tool can automatically call the background interface of the intelligent code review system after receiving the code pushed by the user's specified branch; Obtaining the submitted local code, and automatically calling the background interface according to the trigger mechanism, wherein the local code includes the incremental code or the full code submitted by the developer; If it is determined that the type of the local code is the incremental code, the local code is filtered, and the submission information corresponding to the target code that meets the filtering condition is written into the cache to wait for the scheduled task to execute the review task; When executing the scheduled task, the submission information is retrieved from the cache, and the target code is split into individual submission codes according to the submission information; Scoring each submitted code to obtain a code score, and providing review opinions on the submitted code; The average scores of the multiple code scores are calculated to obtain a comprehensive score corresponding to the target code.
2. The method of intelligent code review according to claim 1, characterized in that: After obtaining the submitted local code and automatically calling the background interface according to the trigger mechanism, the method further includes: If it is determined that the type of the local code is full code, obtaining a source file of the local code; Filtering target files that need to be security scanned from the source files; Parsing the syntax tree of the target file, and recursively obtaining target attributes in the target file; Check whether the fully qualified name of the target attribute contains a preset suffix, and if it is determined that the fully qualified name contains the preset suffix, perform a full scan on the target file; Based on the result of the full scan, a method-level risk review is performed on the target code; According to the review result of the method-level risk review of the target code, the review result is output, and the review result includes whether there is a risk or there is no risk.
3. The method of intelligent code review according to claim 1, characterized in that: After taking out the submission information from the cache and splitting the target code into individual submission codes when executing the scheduled task, the method further includes: Using the developer's submission ID to call a related interface from the code management tool to obtain the modified content for the target code; Traversing the modified contents to search for multiple modified files for each of the submitted codes; By determining whether the file type of the modified file is a file type that requires code review, the modified files that do not require code review are filtered out to obtain a difference file; Filter invalid characters in the difference file to obtain a filtered file; The filter file is scored and review comments are given, and the score and review comments for the filter file are output in Markdown format.
4. The method of intelligent code review according to claim 3, characterized in that: After scoring the filter file and providing review opinions, and outputting the score and review opinions for the filter file in Markdown format, the method further includes: The file scores obtained by scoring each of the filtered files are sorted in order of high and low scores; According to the sorting results, determining scores for a preset number of files with the lowest scores; Re-evaluating the filtered files corresponding to the preset number of file scores with the lowest scores to obtain a second review opinion; Output the secondary review opinion.
5. The method of intelligent code review according to claim 1, characterized in that: Before scoring each submitted code to obtain a code score and providing review opinions for the submitted code, the method further includes: Collecting open source code from the developer's internal code base; Preprocessing the open source code to obtain a processed code; The processing code is sequentially length-segmented, character string-normalized, and indexed to obtain a plurality of code data blocks; Generating a corresponding vector embedding for each of the code data blocks to obtain a first vector embedding; The first vector is embedded and stored together with the code data block into a vector data block.
6. The method of intelligent code review according to claim 5, characterized in that: The step of scoring each submitted code to obtain a code score and providing review opinions for the submitted code specifically includes: For the submitted code, generate a corresponding vector embedding to obtain a second vector embedding; Performing a similarity search in the vector database by embedding the vector, and calculating the cosine similarity between the second vector embedding and each of the first vector embeddings; Querying multiple cosine similarities whose cosine similarities exceed a preset similarity, and determining similarity vector embeddings corresponding to the cosine similarities whose cosine similarities exceed the preset similarity; Determine the similar data block corresponding to the embedding of the similar vector; Using the similar data blocks as context information and the submitted code as input, generating review comments; The context information is provided with background information related to the submitted code, and combined with the private domain knowledge of the developer's enterprise, semantic understanding and problem identification are performed on the content of the submitted code, including identification of code structure, readability and naming conventions, and optimization suggestions are given to obtain the review opinion.
7. The method of intelligent code review according to claim 6, characterized in that: The step of scoring each submitted code to obtain a code score and providing review opinions for the submitted code specifically includes: Determine multiple review levels for preset code reviews, including function level, file level, and system level; Determining a weight value of each of the similar data blocks for each of the review levels; According to the multiple weight values of each review level, an average is calculated to obtain a dynamic weight value of the review level; For the submitted code, generating a corresponding level score according to the review criteria corresponding to the review level; The code score is calculated based on the dynamic weight values corresponding to each review level and the level score.
8. An intelligent code review system, characterized in that: The system comprises an acquisition module (201), a processing module (202) and an output module (203), wherein: The acquisition module (201) is used to bind a trigger mechanism based on the project that the developer needs to conduct code review in the code management tool, so that the code management tool can automatically call the background interface of the intelligent code review system after receiving the code pushed by the user-specified branch; The acquisition module (201) is used to acquire the submitted local code and automatically call the background interface according to the trigger mechanism, wherein the local code includes the incremental code or the full code submitted by the developer; The processing module (202) is used to filter the local code if it is determined that the type of the local code is the incremental code, and write the submission information corresponding to the target code that meets the filtering condition into the cache to wait for the scheduled task to execute the review task; The processing module (202) is used to retrieve the submission information from the cache when executing the scheduled task, and split the target code into individual submission codes according to the submission information; The processing module (202) is used to score each submitted code, obtain a code score, and provide review opinions for the submitted code; The output module (203) is used to calculate the average score of the multiple code scores to obtain the comprehensive score corresponding to the target code.
9. An electronic device, characterized in that: The electronic device comprises a processor (301), a communication bus (302), a user interface (303), a network interface (304) and a memory (305), wherein the memory (305) is used to store instructions, the user interface (303) and the network interface (304) are both used to communicate with other devices, the communication bus (302) is used to realize connection and communication between components in the electronic device, and the processor (301) is used to execute the instructions stored in the memory (305) so that the electronic device executes the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed, the method according to any one of claims 1 to 7 is executed.
Citation Information
Patent Citations
Code statistical method and device based on Git
CN116009946A
Code review method, system and equipment based on merge request increment and medium
CN117609057A
Code review model training and code review method, device and equipment
CN119669034A
Intelligent collaborative project management
US20200394588A1
Cited By
Intelligent code change recognition system, method and device based on large language model and medium
CN120596354A
Method and device for realizing intelligent quality valve in demand submission process, equipment and medium
CN120610686A
Methods, devices, equipment, and media for implementing intelligent quality valves in the demand submission process.
CN120610686B
