Code review method, system and electronic device

Through deep learning models identifying error code segments and generating error description text in combination with natural language processing, the problem of accuracy and inefficiency of existing code review methods is solved, and more efficient and accurate code review is achieved.

CN119739612APending Publication Date: 2025-04-01HUAWEI MARINE NETWORKS CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202510245218.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-04
Publication Date
2025-04-01

AI Technical Summary

Technical Problem

The existing code review methods are inaccurate and inefficient, and cannot meet the needs of fast iteration and high-quality code.

Method used

The deep learning model is used to identify the error code segment, and the error description text is generated through the natural language processing model, and the review results are displayed in combination with the interactive interface to generate modification suggestions and code comments.

Benefits of technology

It improves the accuracy of code review, reduces misjudgment and omissions of manual review, shortens code review time, and saves the development team's time and human resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119739612A_ABST
    Figure CN119739612A_ABST
Patent Text Reader

Abstract

The present application relates to the field of data processing technology, and provides a code review method, system and electronic device. The method includes: obtaining the code to be reviewed; determining the code review rules that match the code to be reviewed; using a first review model to identify the error code segments that do not comply with the code review rules in the code to be reviewed; wherein the first review model is a deep learning model; using a second review model to generate an error description text corresponding to the error code segment; wherein the second review model is a natural language processing model; displaying the review results on an interactive interface, the review results including the error code segment and the error description text. The technical solution of the present application can solve the current technical problems of low accuracy and efficiency of code review.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a code review method, system and electronic device. Background Art

[0002] In the context of increasingly complex and rapid iterations of software development, ensuring code quality has become one of the core issues in software development. Modern software projects are often large-scale, involving many developers working together, increasing dependencies between code modules, and the rapid changes in market and user needs also require development teams to deliver new features and updates at a higher speed.

[0003] In this case, low-quality code may lead to degraded system performance, increased maintenance costs, and even security vulnerabilities, thus affecting product reliability and user experience. With the popularity of concepts such as agile development, continuous integration (CI), and continuous delivery (CD), development teams need to maintain high code quality while developing quickly. However, the current code review methods are not accurate and efficient. Summary of the invention

[0004] The embodiments of the present application provide a code review method, system and electronic device to solve the current technical problems of low accuracy and efficiency of code review.

[0005] In order to achieve the above objectives, in a first aspect, an embodiment of the present application provides a code review method, the method comprising: Obtain the code to be reviewed; determine the code review rules that match the code to be reviewed; use the first review model to identify the erroneous code segments that do not comply with the code review rules in the code to be reviewed; wherein the first review model is a deep learning model; use the second review model to generate error description text corresponding to the error code segment; wherein the second review model is a natural language processing model; display the review results on the interactive interface, the review results including the error code segment and the error description text.

[0006] The code review method provided in the embodiment of the present application uses a deep learning model to identify error code segments and generates corresponding error description texts through a natural language processing model. In this way, through intelligent code review technology, potential problems and errors in the code can be more accurately identified, thereby reducing the misjudgments and omissions that may be caused by manual review, improving the accuracy of code review, and improving the quality and reliability of the software. In addition, this automated review method can also shorten the time required for traditional code review, saving time and human resources of the development team.

[0007] In one implementation, the method further includes: using the first review model to generate modification suggestions and modification examples corresponding to the error code segment; wherein the modification suggestions and modification examples comply with the code review rules; using the second review model to generate code comments corresponding to the modification examples; and the review results include the modification suggestions, modification examples, and code comments. With this implementation, specific and practical correction suggestions can be generated for the error code segment, which is conducive to helping developers quickly correct errors.

[0008] In one implementation, determining the code review rules that match the code to be reviewed includes: using a rule matching model to determine the code review rules based on the attribute information of the code to be reviewed; wherein the attribute information includes at least one of a programming language, a framework, an auxiliary library, and a system dependency; and adjusting the code review rules according to user preference information. Using this implementation, the code review rules are determined based on the attribute information of the code to be reviewed, which can ensure that the code review rules are more in line with the characteristics of the code to be reviewed, reduce the interference of the syntax that does not match the characteristics of the code to be reviewed on the code review, and thus improve the accuracy of the code review. In addition, the embodiment of the present application adjusts the code review rules according to the developer's preference information, so that the adjusted code review rules are more in line with the developer's development habits.

[0009] In one implementation, after determining the code review rules that the code to be reviewed matches, the method further includes: using the rule matching model to adjust in real time at least one of the code review rules, the model parameters of the first review model, and the model parameters of the second review model according to the operation data generated during the operation of the code to be reviewed. With this implementation, the embodiment of the present application dynamically adjusts the code review rules and the parameters of the first review module and the second review model according to the real-time operation data, which can ensure that the code review process is more in line with the actual application scenario, thereby obtaining a better code review result.

[0010] In one implementation, the method further includes: displaying a feedback area on the interactive interface; receiving feedback information input by the user through the feedback area; and updating at least one of the first review model, the second review model, and the rule matching model based on the feedback information. This implementation is conducive to further improving the review accuracy and user experience.

[0011] In one implementation, the method further includes: in response to modification instruction information for the error code segment input by the user through the interactive interface, modifying the error code segment in the code to be reviewed; and applying the modified code to be reviewed to the project corresponding to the code to be reviewed. This implementation avoids manual modification of project files, reduces the workload of developers, and improves development efficiency.

[0012] In one implementation, the method further includes: obtaining a first training set, and using the first training set to train a first review model and a second review model; wherein the first training set is constructed based on first historical code data, and the first historical code data includes historical codes and historical repair records corresponding to the historical codes; obtaining a second training set, and using the second training set to train a rule matching model; wherein the second training set is constructed based on second historical code data, and the second historical code data includes historical codes and historical operation data generated during the operation of the historical codes. By adopting this implementation, the accuracy of code review can be improved by training the first review model, the second review model, and the rule matching model.

[0013] In one implementation, the method further includes: integrating the trained first review model, the second review model, the rule matching model and the interactive interface to obtain a code review system. By adopting this implementation, multiple models are integrated into the code review system, and a consistent interface and security policy can be provided through the code review system, which is conducive to better completing complex code review tasks.

[0014] On the second aspect, the present application also provides a code review system, including: a code input module for obtaining the code to be reviewed; an intelligent analysis module for using a first review model to identify erroneous code segments that do not comply with code review rules in the code to be reviewed; and, using a second review model, generating error description text corresponding to the erroneous code segments; wherein the first review model is a deep learning model and the second review model is a natural language processing model; an interactive interface for displaying the review results, the review results including erroneous code segments and error description texts.

[0015] In one implementation, the code review system also includes: a real-time monitoring module for monitoring the operating data generated by the code to be reviewed during its operation; a rule matching module for determining the code review rules that match the code to be reviewed; and, based on the operating data, adjusting the code review rules, the model parameters of the first review model, and the model parameters of the second review model in real time.

[0016] In the third aspect, the present application also provides a code review method, including: for multiple edge devices of the communication network system, deploy at least one edge computing device that is communicatively connected to each edge device; in the edge computing device, deploy a code review system as described in the second aspect and any implementation method; divide the task to be reviewed into multiple subtasks, and assign each subtask to one or more edge computing devices; in the edge computing device, use the code review system to review the code to be reviewed corresponding to the subtask, obtain the sub-review result corresponding to the subtask, and share the sub-review result to other edge computing devices; use the central server of the communication network system to summarize the sub-review results to obtain the target review result corresponding to the task to be reviewed.

[0017] The code review method shown in the embodiment of the present application is based on a distributed system architecture, deploys a code review system on each edge computing device, splits the code review task into multiple subtasks, and completes the code review by having each edge computing device execute the subtasks separately, which can reduce the computing pressure of the central server and improve the efficiency of code review. Therefore, the embodiment of the present application can solve the problem that the current code review method usually requires the code to be sent to the central server, and the central server completes the code review uniformly, resulting in low code review efficiency.

[0018] In a fourth aspect, the present application also provides an electronic device, comprising a memory and a processor; the memory and the processor are coupled; the memory is used to store computer program code, the computer program code comprises computer instructions, and when the processor executes the computer instructions, the electronic device executes the code review method as described in the first aspect and any implementation method, and the third aspect and any implementation method.

[0019] In the fifth aspect, the present application also provides a computer-readable storage medium, which stores a computer program or instruction. When the computer program or instruction runs on a computer, the computer executes the code review method in the first aspect and any implementation method, and the third aspect and any implementation method mentioned above.

[0020] In the sixth aspect, the present application also provides a computer program product, which includes: a computer program or instructions, which, when the computer program or instructions are run on a computer, enable the computer to execute the code review method in the first aspect and any implementation method, and the third aspect and any implementation method mentioned above.

[0021] It can be understood that the beneficial effects that can be achieved by the technical solutions provided in the second aspect and the fourth to sixth aspects provided above can refer to the beneficial effects in the first aspect and any optional implementation method thereof, the third aspect and any implementation method thereof, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the embodiments are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0023] Figure 1 is a flow chart of the code review method provided by an embodiment of the present application; Figure 2 is another flow chart of the code review method provided by an embodiment of the present application; Figure 3It is a flowchart of model training in the code review method provided in an embodiment of the present application; Figure 4 is a schematic diagram of a service activation device based on user intention provided in an embodiment of the present application; Figure 5 This is another flow chart of the code review method provided in the embodiment of the present application. DETAILED DESCRIPTION

[0024] The technical solutions in the embodiments of the present application will be described clearly below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments of the present application, other embodiments obtained by ordinary technicians in this field without making creative work all belong to the protection scope of the present application.

[0025] In the following, the terms "first", "second", etc. are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first", "second", etc. may explicitly or implicitly include one or more of the features. In the description of this application, unless otherwise specified, "plurality" means two or more.

[0026] In addition, in the present application, directional terms such as "upper", "lower", "inner" and "outer" are defined relative to the orientation of the components schematically placed in the drawings. It should be understood that these directional terms are relative concepts. They are used for relative description and clarification, and they can change accordingly according to the changes in the orientation of the components placed in the drawings.

[0027] The following first describes the application scenarios of the embodiments of the present application.

[0028] In the context of increasingly complex and rapid iterations of software development, ensuring code quality has become one of the core issues in software development. Modern software projects are often large-scale, involving many developers working together, increasing dependencies between code modules, and the rapid changes in market and user needs also require development teams to deliver new features and updates at a higher speed.

[0029] In this case, low-quality code may lead to degraded system performance, increased maintenance costs, and even security vulnerabilities, thus affecting product reliability and user experience. With the popularity of concepts such as agile development, continuous integration (CI), and continuous delivery (CD), development teams need to maintain high code quality while developing quickly.

[0030] The existing code review methods are as follows: 1. Static analysis tool detection method. This method can only perform static analysis on the code and cannot discover possible problems in dynamic behavior, such as detecting errors caused by specific data input. At the same time, the tool only detects the code in the test process and cannot cover all possible runtime paths, and cannot guarantee the quality of code review.

[0031] 2. Manual inspection method. This method requires a lot of time for manual review, and the review results may be affected by the reviewer's experience and subjective judgment, which reduces the efficiency and quality of code review. At the same time, the object of manual code review is test cases, not all code paths, and it cannot cover all possible runtime paths, and the quality of code review cannot be guaranteed.

[0032] 3. Dynamic analysis tool detection method: When the dynamic analysis tool reviews the code, it mainly focuses on the behavior of the code at runtime (such as performance, resource usage, or logical errors, etc.). Other code errors cannot be reviewed, such as spelling errors, resulting in low accuracy of code review. At the same time, dynamic analysis usually requires additional runtime overhead, which may affect program performance.

[0033] In summary, the current code review and feedback efficiency is low, and the accuracy of code review is poor, which cannot meet the needs of users. It is especially not suitable for scenarios such as the communications field that require high code review efficiency.

[0034] In order to solve the problem of low accuracy and efficiency of current code review methods, this application proposes a code review method that is applied to electronic devices such as servers, workstations, and PCs.

[0035] Figure 1 It is a flow chart of the code review method provided in the embodiment of the present application.

[0036] like Figure 1 As shown, the method includes the following steps S11-S15: S11: Get the code to be reviewed.

[0037] In step S11, the electronic device obtains a code to be reviewed.

[0038] For example, the code to be reviewed is as follows: #Example input code to be reviewed (Python) input_code=”” def add(a,b); return a+b def substract(a,b); return ab .

[0039] It is understandable that the above code to be reviewed is only an exemplary code segment. In actual application scenarios, the code to be reviewed may include source code or project files submitted by users (source code in languages ​​such as python, java, C++), source code text data (parsed code file content), etc. For example, the code to be reviewed may be project code using the Spring framework and Java programming language.

[0040] S12: Determine the code review rules that match the code to be reviewed.

[0041] In step S12, the electronic device may determine the code review rules that the code to be reviewed matches according to the type of the code to be reviewed, etc. For example, for the code to be reviewed using the Spring framework and the Java programming language, the electronic device may determine the rules for reviewing the Spring framework and Java syntax as the code review rules that the code to be reviewed matches.

[0042] In addition, in the process of determining the code review rules, the electronic device may also refer to historical review records. If the historical review records consider a certain code to be a code that needs to be improved, and give the corresponding modification suggestions or modification results for this code, then the corresponding code review rules can be determined based on the modification suggestions or modification results of this code.

[0043] S13: Using the first review model, identifying erroneous code segments that do not comply with code review rules in the code to be reviewed.

[0044] In step S13, the electronic device uses the first review model to determine whether the code structure and pattern of the code to be reviewed conform to the code review rules, and then identifies the error code segment that does not conform to the code review rules as the code segment that needs to be improved. In addition, the first review model can also be used to determine the location information of the error code segment, so that the developer can accurately locate the error code segment in the code to be reviewed.

[0045] Among them, the first review model is a deep learning model, such as a convolutional neural network (CNN), a recurrent neural network (RNN) model, a Transformer model, etc.

[0046] S14: Generate an error description text corresponding to the error code segment using the second review model.

[0047] In step S14, the electronic device generates an error description text corresponding to the error code segment using the second review model, wherein the second review model is a natural language processing model, such as a bidirectional encoder representations from transformers (BERT) model, a generative pre-trained transformer (GPT) model, etc.

[0048] Furthermore, the second review model can also be used to assist in identifying erroneous code segments. For example, before step S13, the second review model can parse the text content such as code comments, variable names, function names, and development documents of the code to be reviewed to understand the business logic and developer intentions. In this way, when the first review model identifies erroneous code segments, it can also use business logic and developer intentions as identification basis, further improving the accuracy of code review.

[0049] S15: Display the review result on the interactive interface.

[0050] In step S15, after the electronic device obtains the review results using the aforementioned first review model and the second review model, it can display the review results on the interactive interface, including the error code segment and the corresponding error description text. In addition, the review results displayed on the interactive interface can also include information such as the location of the error code segment, which can be obtained using the first review model.

[0051] The code review method provided in the embodiment of the present application uses a deep learning model to identify error code segments and generates corresponding error description texts through a natural language processing model. In this way, through intelligent code review technology, potential problems and errors in the code can be more accurately identified, thereby reducing the misjudgments and omissions that may be caused by manual review, improving the accuracy of code review, and improving the quality and reliability of the software. In addition, this automated review method can also shorten the time required for traditional code review, saving time and human resources of the development team.

[0052] Figure 2 This is another flow chart of the code review method provided in the embodiment of the present application.

[0053] like Figure 2 As shown, the method includes the following steps S201-S211: S201: Obtain the code to be reviewed.

[0054] The description of step 201 can be found in the aforementioned step S11, which will not be repeated here.

[0055] S202: Determine code review rules based on the attribute information of the code to be reviewed by using the rule matching model.

[0056] In step S202, the electronic device can read the historical review records of the first review model, and then refer to the historical review records to determine the code review rules based on one or more of the features used by the code to be reviewed, such as the programming language (such as Python) and framework (such as TensorFlow, PyTorch), auxiliary libraries (such as NumPy, Pandas) or system dependencies (such as CUDA, cuDNN).

[0057] The embodiment of the present application determines the code review rules through the attribute information of the code to be reviewed, which can ensure that the code review rules are more in line with the characteristics of the code to be reviewed, reduce the interference of the grammar that does not conform to the characteristics of the code to be reviewed on the code review, and thus improve the accuracy of the code review.

[0058] In some embodiments, after step S202, at least one of the following steps S203 and S204 may be executed, or step S205 may be executed directly.

[0059] S203: Adjust code review rules according to user preference information.

[0060] In step S203, the electronic device can dynamically adjust the code review rules according to the developer's preference information, so that the adjusted code review rules are more in line with the developer's development habits. For example, if the user prefers to use camelCase naming to name variables, the electronic device can adjust the code review rules to limit variable names that conform to camelCase naming to conform to the code review rules.

[0061] In addition, electronic devices can dynamically adjust code review rules based on actual development needs.

[0062] S204: Using the rule matching model, according to the operation data generated during the operation of the code to be reviewed, at least one of the code review rules, the model parameters of the first review model, and the model parameters of the second review model is adjusted in real time.

[0063] In step S204, during the operation of the code to be reviewed, the electronic device can obtain real-time operation data, and then dynamically adjust the code review rules according to the real-time operation data, and can also dynamically adjust the model parameters of the first review model and the second review model.

[0064] For example, if the CPU usage reaches 90% during the running of the code to be reviewed, there may be nested loops, repeated calculations, etc. At this time, the electronic device can adjust the code review rules and consider that the code segment with nested loops and repeated calculations does not comply with the code review rules and is an error code segment.

[0065] It should be noted that the error code segment identified based on the code review rules in the embodiment of the present application may refer to the code with errors or the code that needs to be optimized. For example, the code with nested loops may not have errors, but it can be optimized by using matrix operations to reduce the amount of operations. Therefore, such code can also be defined as an error code segment that does not comply with the code review rules by adjusting the code review rules.

[0066] The embodiment of the present application dynamically adjusts the code review rules and the parameters of the first review model and the second review model according to real-time operation data, which can ensure that the code review process is more in line with the actual application scenario, thereby obtaining better code review results.

[0067] S205: Using the first review model, identifying error code segments that do not comply with code review rules in the code to be reviewed.

[0068] The description of step 205 can be found in the aforementioned step S13 and will not be repeated here.

[0069] S206: Generate modification suggestions and modification examples corresponding to the erroneous code segment using the first review model.

[0070] In step S206, after the electronic device identifies the erroneous code segment using the first review model, it can also use the first review model to generate modification suggestions and modification examples for the code that needs to be improved. The modification suggestions and modification examples must comply with the aforementioned code review rules.

[0071] For example, if the code review rules limit variable names to be named using lower camel case, then if the error code segment contains a variable name UserName named using upper camel case, the modification suggestion may be to modify the function name based on lower camel case, and the modification example may be userName.

[0072] S207: Generate an error description text corresponding to the error code segment using the second review model.

[0073] The description of step 207 can be found in the aforementioned step S14 and will not be repeated here.

[0074] S208: Generate code comments corresponding to the modification examples using the second review model.

[0075] In step S208, after the electronic device generates the modification example using the first review model, it can also use the second review model to generate corresponding code comments for the modification example. For example, the electronic device can generate the following code comments for the code example and the error cause of the error code segment: "CamelCase: the first letter of the first word is lowercase, and the first letters of subsequent words are uppercase".

[0076] The embodiment of the present application can identify the erroneous code segment in the code to be reviewed through steps S205-S208, and can also generate specific and practical correction suggestions for the erroneous code segment, which is helpful to help developers quickly correct errors.

[0077] S209: Display the review results on the interactive interface.

[0078] The description of step 209 can be found in the aforementioned step S15 and will not be repeated here.

[0079] Among them, based on the content generated in the aforementioned steps S206 and S208, the review results may include modification suggestions, modification examples, and code comments in addition to the error code segment and error description text.

[0080] In addition, the electronic device can also generate an inspection report based on the inspection results.

[0081] S210: In response to modification instruction information for the erroneous code segment input by the user through the interactive interface, modify the erroneous code segment in the code to be reviewed.

[0082] In step S210, the error code segment displayed on the interactive interface is an editable code segment, so that the user can directly modify the error code segment displayed on the interactive interface to obtain an improved code segment. Specifically, after receiving the modification instruction information input by the user through the interactive interface, the electronic device can modify the code to be reviewed. The modification information can be the user's modification operation on the error code segment, or it can be the modification opinion entered in text form. For example, for the variable name UserName in the error code segment, the modification information can be the user's modification operation on the variable name UserName, or it can be an instruction entered in text form to "change U to u".

[0083] S211: Apply the modified code to be reviewed to the project corresponding to the code to be reviewed.

[0084] In step S211, the electronic device directly applies the modified code to be reviewed to the corresponding project, so that the project can be published to a test environment or a production environment to facilitate subsequent operations on the project.

[0085] The embodiment of the present application can receive modification instruction information on the interactive interface, and then modify the code to be reviewed and apply it to the project, avoiding manual modification of project files, reducing the workload of developers, and improving development efficiency.

[0086] In some embodiments, after step S211, the following steps S212-S214 may be performed.

[0087] S212: Displaying a feedback area on the interactive interface.

[0088] S213: receiving feedback information input by the user through the feedback area.

[0089] S214: Based on the feedback information, update at least one of the first review model, the second review model, and the rule matching model.

[0090] In steps S212-S214, the interactive interface may also display a feedback area, which is used to receive feedback information input by the user, which may specifically include user satisfaction, opinions and suggestions on the code review system, as well as problems such as misreporting and missing reports during the code review process. In this way, the electronic device may optimize at least one of the first review model, the second review model, and the rule matching model based on the feedback information input by the user, so as to further improve the review accuracy and improve the user experience.

[0091] For example, in some embodiments, the interactive interface may display the following review results: +---------------------------+ | Code review interface | +---------------------------+ | 1. List of code issues | | - Question 1 (Type: Logical Error) | | - Question 2 (Type: Performance Question) | | - Issue 3 (Type: Non-compliant) | +---------------------------+ | 2. Problem details | | -Question ID: 1 | | -Problem description: A logical judgment branch is missing in the conditional judgment| | - Problem location: Line34, Function foo() | +---------------------------+ | 3.AI modification suggestions| | - Suggestion 1: Add missing logic branches | | - Suggested code: | | if (condition) { | | / / Original code| |} else { | | / / New code| +---------------------------+ | 4. Verification and Application | | - Code preview: | | if (condition) { | | / / Original code| |} else { | | / / New code| | - [Apply Modifications] | +---------------------------+ | 5. Feedback and Adjustment| | -Satisfaction: [High] [Medium] [Low] | | -Feedback: [text input box] | +---------------------------+ The above embodiment provides an interactive interface for displaying the review results.

[0092] As shown in the above embodiment, the review results displayed on the interactive interface include five areas: code problem list, problem details, modification suggestions, verification and application, feedback and adjustment. Among them, the code problem list area may include problems and problem types that occur in the code to be reviewed. The problem details area may include the problem ID of the error code segment, the error description text (that is, the problem description in the above embodiment), and the error code segment location (that is, the problem location in the above embodiment). The repair suggestion area may include modification suggestions and sample code (suggested code in the above embodiment). The verification and application area can be used to receive modification indication information input by the user and display preview information of the improved error code segment. The feedback and adjustment area is used to receive user satisfaction and opinion and suggestion information. It can be understood that the embodiment of the present application only takes the above five areas as an example to exemplify the review results displayed on the interactive interface. In other embodiments, the review results displayed on the interactive interface may include more or fewer areas, and the present application does not limit this.

[0093] In some embodiments, before executing the steps of the aforementioned code review method, a first review model, a second review model, and a rule matching model for reviewing the code may also be pre-trained.

[0094] Figure 3 It is a flowchart of model training in the code review method provided in an embodiment of the present application.

[0095] like Figure 3 As shown, model training includes the following steps S31-S33: S31: Obtain a first training set, and use the first training set to train a first review model and a second review model.

[0096] In step S31, in order to improve the code review accuracy of the first review model and the second review model, the electronic device may train the first review model and the second review model.

[0097] In this step, first, the electronic device obtains a first training set for model training. The first training set is constructed based on the first historical code data. The first historical code data includes historical codes such as historical open source projects, and syntax errors and code smells (such as complex conditional statements, non-standard naming, etc.) may be annotated in the historical codes. In addition, the first historical code data also includes historical repair records corresponding to the historical codes, which may specifically include historical repair records corresponding to the aforementioned annotated content in the historical codes. In order to expand the scope of application of the first review model and the second review model so that they can review various different codes, the historical codes may include multiple programming languages, project types, and complexity levels.

[0098] In addition, before constructing the first training set based on the first historical code data, the electronic device may also perform data cleaning on the first historical code data, remove duplicate codes, samples with inconsistent formatting, and desensitize sensitive data in the first historical code data.

[0099] In addition, the electronic device may also perform data preprocessing on the first historical code data. Specifically, the data preprocessing may include word segmentation and encoding. In the word segmentation step, the electronic device may use a word segmenter to segment the code in the data set based on characters, subwords, or specific grammatical structures. In the encoding step, the electronic device may convert the code after word segmentation processing into a numerical vector that can be understood by the model, including position encoding and possible syntax tree representation.

[0100] In addition, the electronic device may also perform data enhancement on the first historical code data, such as by transforming the code, such as renaming variables and adjusting the structure, to enhance the training data set and obtain more training data.

[0101] In this step, secondly, the electronic device trains the first review model and the second review model using the first training set. Specifically, the electronic device can use a supervised learning framework to optimize the model parameters of the first review model and the second review model to complete the model training. Among them, the optimization goal includes minimizing the prediction error (such as cross entropy loss), and the optimization method includes grid search, random search or Bayesian optimization and other technologies.

[0102] In addition, the electronic device can continuously collect new training sets and regularly use the new training sets to train the first review model and the second review model. The electronic device can also regularly perform benchmark tests to evaluate the code inspection speed, accuracy, and resource consumption, and adjust the model structure, parameters, or preprocessing steps of the first review model and the second review model based on the test results. In this way, continuous optimization and continuous learning of each model in the code review system can be achieved.

[0103] S32: Obtain a second training set, and use the second training set to train a rule matching model.

[0104] In step S32, in order to enable the rule matching model to match the review rules that are more suitable for the code to be reviewed, the electronic device may train the rule matching model.

[0105] In this step, first, the electronic device obtains a second training set for model training. The second training set is constructed based on second historical code data, and the second historical code data includes historical codes such as historical open source projects, and also includes historical operation data generated during the operation of the historical code. In some embodiments, the historical code included in the second historical code data is the same as the historical code included in the first historical code data.

[0106] In this step, secondly, the electronic device uses the second training set to train the rule matching model. The specific training method can be found in the aforementioned step S31 and will not be described again here.

[0107] The embodiment of the present application can improve the accuracy of code review by training the first review model, the second review model and the rule matching model.

[0108] In some embodiments, step S32 may further include the following step S33: S33: Integrate the trained first review model, the second review model, the rule matching model and the interactive interface to obtain a code review system.

[0109] In step S33, after the model training is completed, the electronic device packages the first review model, the second review model and the dependencies of the two models into a container (Doker) and integrates them into the intelligent analysis module. The rule matching model is integrated into the rule matching module. The intelligent analysis module, the rule matching module and the interactive interface are integrated into a unified framework to obtain an integrated code review system. After that, the electronic device can use the integrated code review system to perform code review work.

[0110] At the same time, the electronic device can determine the RESTful interface or gRPC interface that supports remote calls in the intelligent analysis module. In this way, other electronic devices can remotely call the intelligent analysis module based on the RESTful interface or gRPC interface, and use the first review model and the second review model in the intelligent analysis module to perform code review operations.

[0111] In addition, a real-time monitoring module can be integrated into the code review system to track operating data and performance indicators during code execution, and trigger alarms when certain indicators reach thresholds.

[0112] In addition, a log module can be integrated into the code review system to record the operation data and performance indicators tracked by the real-time monitoring module.

[0113] Corresponding to the aforementioned embodiments based on the code review method, the present application also provides an embodiment of a code review device.

[0114] Figure 4 It is a schematic diagram of a service activation device based on user intention provided in an embodiment of the present application.

[0115] like Figure 4 As shown, the code review system 500 includes a code input module 510 , an intelligent analysis module 520 and an interactive interface 530 .

[0116] A code input module 510 is used to obtain the code to be reviewed; The intelligent analysis module 520 is used to identify the error code segments that do not comply with the code review rules in the code to be reviewed by using the first review model; and to generate error description text corresponding to the error code segments by using the second review model; wherein the first review model is a deep learning model and the second review model is a natural language processing model; The interactive interface 530 is used to display the review result, which includes the error code segment and the error description text.

[0117] In one implementation, the code review system 500 further includes a rule matching module for determining a code review rule that matches the code to be reviewed.

[0118] In one implementation, the intelligent analysis module 520 is used to generate modification suggestions and modification examples corresponding to the error code segment using the first review model; wherein the modification suggestions and modification examples comply with the code review rules; and, using the second review model, generate code comments corresponding to the modification examples; The review results displayed by the interactive interface 530 include modification suggestions, modification examples, and code comments.

[0119] In one implementation, a rule matching module is used to determine code review rules based on attribute information of the code to be reviewed using a rule matching model; wherein the attribute information includes at least one of a programming language, a framework, an auxiliary library, and a system dependency; and, adjust the code review rules according to user preference information.

[0120] In one implementation, the code review system 500 further includes: Real-time monitoring module, used to monitor the operation data generated by the code to be reviewed during its operation; The rule matching module is used to adjust the code review rules, the model parameters of the first review model, and the model parameters of the second review model in real time according to the operation data.

[0121] In one implementation, the interactive interface 530 is used to display a feedback area on the interactive interface; and receive feedback information input by the user through the feedback area; The code review system 500 also includes an optimization module for updating at least one of the first review model, the second review model, and the rule matching model based on feedback information.

[0122] In one implementation, the code review system 500 further includes a modification module for modifying the erroneous code segment in the code to be reviewed in response to modification instruction information for the erroneous code segment input by the user through the interactive interface; and applying the modified code to be reviewed to the project corresponding to the code to be reviewed.

[0123] In one implementation, the code review system 500 also includes a training module for obtaining a first training set and using the first training set to train a first review model and a second review model; wherein the first training set is constructed based on first historical code data, and the first historical code data includes historical codes and historical repair records corresponding to the historical codes; and, obtaining a second training set and using the second training set to train a rule matching model; wherein the second training set is constructed based on second historical code data, and the second historical code data includes historical codes and historical operation data generated during the operation of the historical codes.

[0124] In one implementation, the code review system 500 also includes an integration module for integrating the trained first review model, the second review model, the rule matching model, and the interactive interface.

[0125] The present application also provides a code review method, which implements code review using the code review system in the aforementioned embodiment.

[0126] Figure 5 This is another flow chart of the code review method provided in the embodiment of the present application.

[0127] like Figure 5As shown, the method includes the following steps S41-S45: S41: For multiple edge devices of the communication network system, respectively deploy at least one edge computing device that is communicatively connected to each edge device.

[0128] S42: Deploy a code review system in edge computing devices.

[0129] In steps S41-S42, edge computing devices are deployed on edge devices such as communication base stations and routers. Among them, edge computing devices can integrate field-programmable gate array (FPGA) integrated circuits and dedicated processors to support real-time data processing and machine learning model operation. Code review systems are deployed on edge computing devices to perform local real-time data analysis and code review.

[0130] Specifically, after the code review system is deployed, edge computing devices and edge devices can use the code review system to perform real-time analysis on passing data streams and identify anomalies. They can also perform preliminary reviews of the code locally to detect potential problems. They can also process and optimize detected problems locally to reduce data transmission and the load on central servers.

[0131] The embodiment of the present application deploys a code review system on edge computing devices. When data flows through these devices, the code review system can analyze and review the data locally in real time without transmitting all data to a central server. This can not only reduce the delay in data transmission, but also reduce the load on the central server. For example, when a base station management system generates log data, the edge computing device will immediately review these logs to detect whether there are any abnormalities or code problems, and perform preliminary processing and optimization locally, and then feed the results back to the development team.

[0132] S43: Divide the task to be reviewed into multiple subtasks, and assign each subtask to one or more edge computing devices.

[0133] In step S43, the edge computing devices can be connected using a distributed system architecture. For example, a large multinational communications company has R&D centers and operations teams in multiple countries around the world, mainly responsible for developing and maintaining complex communication network systems. In this way, the central server of the communication network system can decompose the code review task into multiple microservices and distribute them to servers in different R&D centers.

[0134] S44: In the edge computing device, using the code review system, review the code to be reviewed corresponding to the subtask, obtain the sub-review result corresponding to the subtask, and share the sub-review result to other edge computing devices.

[0135] In step S44, each edge computing device uses the code review system to complete the assigned subtasks and obtain the corresponding sub-review results. As in the above embodiment, each R&D center is responsible for the code review of its own area, and the code review system automatically synchronizes the modifications and feedback of each R&D center. In this way, the edge computing devices of each R&D center can share the review results and feedback information.

[0136] S45: Utilize the central server of the communication network system to aggregate the sub-review results and obtain the target review result corresponding to the task to be reviewed.

[0137] In step S45, the central server of the communication network system can summarize the sub-review results and feedback information of each area. In addition, the central server can also monitor the operating status of each edge device and distributed server in real time, and dynamically adjust computing resources according to the operating status and actual business needs.

[0138] The embodiment of the present application deploys a code review system on each edge computing device based on a distributed system architecture, splits the code review task into multiple subtasks, and completes the code review by having each edge computing device execute the subtasks separately, which can reduce the computing pressure of the central server and improve the efficiency of code review. Therefore, the embodiment of the present application can solve the problem that the current code review method usually requires sending the code to the central server, and the central server completes the code review uniformly, resulting in low code review efficiency.

[0139] The present application also provides an electronic device, including: a processor and a memory; the memory stores program instructions, and when the program instructions are executed by the processor, the electronic device executes the code review method in any implementation method of the above embodiments.

[0140] An embodiment of the present application also provides a computer-readable storage medium, which includes computer instructions. When the computer instructions are executed on the above-mentioned electronic device, the electronic device executes each function or step executed in the above-mentioned method embodiment.

[0141] The embodiment of the present application also provides a computer program product. When the computer program product is run on a computer, it enables the computer to execute each function or step executed in the above method embodiment.

[0142] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0143] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, 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 interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0144] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0145] 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.

[0146] 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 readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially 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 storage medium and includes several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.

[0147] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims

1. A code review method, characterized in that: The method comprises: Get the code to be reviewed; Determine the code review rules that match the code to be reviewed; Using a first review model, identifying an erroneous code segment that does not comply with the code review rule in the code to be reviewed; wherein the first review model is a deep learning model; Generate an error description text corresponding to the error code segment using a second review model; wherein the second review model is a natural language processing model; The review result is displayed on the interactive interface, and the review result includes the error code segment and the error description text.

2. The method according to claim 1, characterized in that The method further comprises: Using the first review model, generating modification suggestions and modification examples corresponding to the erroneous code segment; wherein the modification suggestions and the modification examples comply with the code review rules; Using the second review model, generating code comments corresponding to the modification example; The review result includes the modification suggestion, the modification example, and the code comment.

3. The method according to claim 1, characterized in that The determining of the code review rules that the code to be reviewed matches includes: Determine the code review rule based on the attribute information of the code to be reviewed by using a rule matching model; wherein the attribute information includes at least one of a programming language, a framework, an auxiliary library, and a system dependency; The code review rules are adjusted according to the user preference information.

4. The method according to claim 1, characterized in that: After determining the code review rule that the code to be reviewed matches, the method further includes: By using a rule matching model, at least one of the code review rules, the model parameters of the first review model, and the model parameters of the second review model is adjusted in real time according to the operation data generated by the code to be reviewed during the operation.

5. The method according to claim 3 or 4, characterized in that: The method further comprises: Displaying a feedback area on the interactive interface; receiving feedback information input by the user through the feedback area; Based on the feedback information, at least one of the first review model, the second review model, and the rule matching model is updated.

6. The method according to claim 1, characterized in that The method further comprises: In response to modification instruction information for the erroneous code segment input by the user through the interactive interface, modifying the erroneous code segment in the code to be reviewed; Apply the modified code to be reviewed to the project corresponding to the code to be reviewed.

7. The method according to claim 3 or 4, characterized in that: The method further comprises: Obtain a first training set, and use the first training set to train the first review model and the second review model; wherein the first training set is constructed based on first historical code data, and the first historical code data includes historical codes and historical repair records corresponding to the historical codes; Obtain a second training set, and use the second training set to train the rule matching model; wherein the second training set is constructed based on second historical code data, and the second historical code data includes the historical code and historical operation data generated by the historical code during operation.

8. The method according to claim 7, characterized in that The method further comprises: The first review model, the second review model, the rule matching model and the interactive interface after training are integrated to obtain a code review system.

9. A code review system, characterized in that: The code review system includes: Code input module, used to obtain the code to be reviewed; An intelligent analysis module, configured to use a first review model to identify an erroneous code segment that does not comply with the code review rule in the code to be reviewed; and, using a second review model, to generate an error description text corresponding to the erroneous code segment; wherein the first review model is a deep learning model, and the second review model is a natural language processing model; The interactive interface is used to display the review results, and the review results include the error code segment and the error description text.

10. The system according to claim 9, characterized in that The code review system also includes: A real-time monitoring module, used to monitor the operation data generated during the operation of the code to be reviewed; A rule matching module is used to determine the code review rules that match the code to be reviewed; and, based on the operation data, adjust the code review rules, the model parameters of the first review model, and the model parameters of the second review model in real time.

11. A code review method, characterized in that: The method comprises: For multiple edge devices of the communication network system, respectively deploy at least one edge computing device that is communicatively connected to each of the edge devices; In the edge computing device, deploying the code review system as claimed in claim 9 or 10; Divide the task to be reviewed into a plurality of subtasks, and assign each of the subtasks to one or more of the edge computing devices; In the edge computing device, using the code review system, review the code to be reviewed corresponding to the subtask, obtain a sub-review result corresponding to the subtask, and share the sub-review result with other edge computing devices; The sub-review results are summarized using the central server of the communication network system to obtain the target review result corresponding to the task to be reviewed.

12. An electronic device, characterized in that: It includes a memory and a processor; the memory and the processor are coupled; the memory is used to store computer program code, and the computer program code includes computer instructions. When the processor executes the computer instructions, the electronic device executes the code review method as described in any one of claims 1 to 8 and 11.

Citation Information

Patent Citations

  • Code auditing method and device, electronic equipment and storage medium

    CN117454377A

  • Instant detection tool for plug-in software defect repair submission stage

    CN119046157A

  • Code review and optimization method driven by large language model

    CN119512556A

  • Active learning source code review framework

    US20180276105A1