Code review method and device, storage medium and program product

By listening to code change events in the code review model and using the model to identify code snippets with inconsistent writing errors and inconsistent styles in the code change file, the problem of difficult to identify duplicate code in the prior art is solved, and more accurate code review and more efficient development is achieved.

CN120104462APending Publication Date: 2025-06-06BEIJING 58 INFORMATION TTECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510258995.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-05
Publication Date
2025-06-06

AI Technical Summary

Technical Problem

Existing AI-based code review methods are difficult to effectively identify the code problem in the code that repeatedly develops the same functions, and it is difficult to meet the specific code style and development specifications of the enterprise.

Method used

By listening to the code change event triggered by the user to the code repository, obtain the corresponding code change file, and use the code review model to determine whether there are writing errors in the file and identify whether the code private database contains code segments of different styles.

Benefits of technology

Improve the accuracy of code review results, effectively identify and avoid duplicate code construction issues, improve development efficiency and maintain overall consistency of the code base.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120104462A_ABST
    Figure CN120104462A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a code review method and device, a storage medium and a program product. The method comprises the steps that in response to a monitored code change event triggered by a user to a code warehouse, a code change file corresponding to the code change event is obtained, code change information is marked in the code change file, and the code change file is input into a code review model, through the code review model, whether the code change file has a writing error problem or not can be detected according to the change information, and whether a code private database corresponding to a user contains a second code which is different from a first code style corresponding to a first function in the code change file or not can be identified; therefore, whether a common writing error problem exists in the code change file or not can be accurately detected, and whether the code style corresponding to each function in the code change file is the same as the writing style of each function in the code private database or not can be recognized, so that the problem of repeated code construction is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a code review method, device, storage medium and program product. Background Art

[0002] As the scale and complexity of software development continue to increase, code review has become an important part of ensuring code quality and improving development efficiency. In particular, code review before code submission and merging can effectively discover and fix potential problems. Traditional code review methods mainly rely on manual review, which is time-consuming, labor-intensive and inefficient.

[0003] In recent years, code review methods based on artificial intelligence technology have gradually emerged, especially review solutions based on large language models, which use large-scale corpora to train large language models so that they can understand and generate natural language and programming language, thereby achieving understanding and review of code logic. However, this code review solution can only check common coding errors in the code to a certain extent, and it is difficult to effectively review the problem of repeated development of the same functional code in the code. Summary of the invention

[0004] Multiple aspects of the present application provide a code device method, device, storage medium and program product to improve the accuracy of code review results and effectively identify whether there are code segments in the code change file that implement various functions in a private database but use different styles to avoid the problem of duplicate code construction.

[0005] An embodiment of the present application provides a code review method, including: in response to monitoring a code change event triggered by a user to a code repository, obtaining a code change file corresponding to the code change event; marking code change information in the code change file; inputting the code change file into a code review model, so that the code review model determines whether there is writing error information in the code change file according to the code change information and identifies whether a code private database corresponding to the user contains a second code that is different from a first code style corresponding to a first function in the code change file; and obtaining review output information output by the code review model, wherein the review output information includes review information corresponding to the writing error information and the second code.

[0006] Optionally, the method also includes: in response to a third code corresponding to a second function input by the user into the code review model, obtaining rewriting result information output by the code review model, the rewriting result information including a fourth code having the same style as the codes corresponding to each function in the user's private database, and the style of the third code having a different style from the codes corresponding to each function in the user's private database.

[0007] Optionally, the code change event is a code merge event, and the method further includes: determining whether the code change file meets the set merge requirements based on the review output information; and outputting merge prompt information in response to the determination result that the code change file does not meet the merge requirements.

[0008] Optionally, determining whether the code change file meets the set merging requirements based on the review output information includes: determining, based on the review output information, the error code line in the code change file corresponding to the writing error information and the first error type of the error code line, and determining the second error type corresponding to the second code in the code change file; determining whether the code change file meets the set merging requirements based on the proportion of the error code lines in the code change file and the set error levels corresponding to the first error type and the second error type.

[0009] Optionally, the method further includes: sending the review output information to the user; receiving feedback information sent by the user in response to the review output information; and generating optimized training data according to the feedback information to optimize the code review model based on the optimized training data.

[0010] Optionally, sending the review output information to the user includes: extracting the file name of the code change file, the error code line position and the review information corresponding to the error code line from the review output information; and generating a text including the file name of the code change file, the error code line position and the review information corresponding to the error code line, to send to the user; and / or extracting the error code line position and the review information corresponding to the error code line from the review output information, generating comment information including the error code line position and the review information corresponding to the error code line, and displaying the comment information at the error code line position.

[0011] Optionally, generating optimized training data according to the feedback information to optimize the code review model based on the optimized training data includes: determining a first weight corresponding to the feedback information and a second weight corresponding to the review output information, the first weight being greater than the second weight; determining a weighted result of the feedback information and the review output information according to the first weight and the second weight as optimized supervision information; and using the code change file and the optimized supervision information as optimized training data to optimize the code review model based on the optimized training data.

[0012] Optionally, the method also includes: obtaining a first training sample code file and a second training sample code file, wherein the first training sample code file includes a code file for implementing a target function collected from a non-user private database, and the second training sample code file includes a code file for implementing the target function collected from the user private database, and the first training sample code file and the second training sample code file have different styles; determining first supervision information corresponding to the first training sample code file and second supervision information corresponding to the second training sample code file, the first supervision information including writing error information, style error information and identification information of the target function in the first training sample code file, and the second supervision information including writing error information and identification information of the target function in the second training sample code file; training the code review model according to the first training sample code file, the first supervision information, the second training sample code file and the second supervision information.

[0013] The present application provides a code review device, the device comprising:

[0014] A response module, configured to, in response to monitoring a code change event triggered by a user to a code repository, obtain a code change file corresponding to the code change event;

[0015] A marking module, used for marking code change information in the code change file;

[0016] An input module, configured to input the code change file into a code review model, so that the code review model determines whether there is writing error information in the code change file according to the code change information and identifies whether a private code database corresponding to the user contains a second code different in style from a first code corresponding to a first function in the code change file;

[0017] An acquisition module is used to acquire the review output information output by the code review model, wherein the review output information includes audit information corresponding to the writing error information and the second code.

[0018] An embodiment of the present application also provides an electronic device, including: a memory and a processor; the memory is used to store a computer program; the processor is coupled to the memory and is used to execute the computer program to implement each step in the code review method provided in the embodiment of the present application.

[0019] The embodiment of the present application also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the processor implements the steps in the code review method provided in the embodiment of the present application.

[0020] The embodiment of the present application also provides a computer program product, including a computer program / instruction. When the computer program / instruction is executed by a processor, the processor implements the steps in the code review method provided in the embodiment of the present application.

[0021] In the code review solution provided in the embodiment of the present application, the code change event triggered by the user to the code repository is monitored. If the code change event triggered by the user to the code repository is monitored, in response to the code change event triggered by the user to the code repository, the code change file corresponding to the code change event is obtained. Then, the code change information is marked in the code change file, and the code change file is input into the code review model, so that the code review model determines whether there is writing error information in the code change file based on the code change information and identifies whether the user's corresponding code private database contains a second code that is different from the first code style corresponding to the first function in the code change file. Then, the review output information output by the code review model is obtained, and the review output information includes the audit information corresponding to the writing error information and the second code.

[0022] In the above scheme, through the code review model, according to the code change information, it is detected whether there is writing error information in the code change file and whether the user's corresponding code private database contains code with a different code style from the code corresponding to each function in the code change file. This can not only accurately detect whether there are common writing errors in the code change file to improve the accuracy of the code review results, but also effectively identify whether there are code segments in the code change file that use a different writing style from the functions in the private database to avoid the problem of duplicate code construction. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0024] Figure 1 A flowchart of a keyword identification method provided for an exemplary embodiment of the present application;

[0025] Figure 2 A flowchart of another code review method provided for an exemplary embodiment of the present invention;

[0026] Figure 3 A flowchart of another code review method provided for an exemplary embodiment of the present application;

[0027] Figure 4 A flowchart of another code review method provided for an exemplary embodiment of the present application;

[0028] Figure 5 A code review device provided for an exemplary embodiment of the present application;

[0029] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0030] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.

[0031] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0032] The various models involved in this application (including but not limited to language models or large models) are in compliance with relevant laws and standards.

[0033] Currently, in the software development process, the following methods are often used for code review.

[0034] Implementation method 1: Use static code analysis tools to automatically check the code by parsing the code structure, checking grammar rules and preset programming specifications.

[0035] However, although static analysis tools are widely used in practice, they still have serious shortcomings. First, static analysis tools rely on predefined rule bases and cannot identify logical errors or security risks that are not covered by the rule base. The ability to analyze code semantics and logic is limited, making it difficult to detect vulnerabilities in complex scenarios. Second, static analysis tools have incorrect markings for some problems, causing developers to manually troubleshoot false positives, increasing their workload. In addition, static analysis tools cannot improve themselves based on user feedback, making it difficult to optimize long-term use results.

[0036] Implementation method 2: Manual code review by experienced developers.

[0037] However, when manually reviewing code, the review time depends on the reviewer's experience and energy, which is difficult to meet the needs of large-scale code bases. The review cycle is long, which affects the delivery efficiency of the development team. In addition, the review results vary from person to person, making it difficult to unify the review standards. In addition, manual review mainly depends on the developer's experience and code familiarity, which makes it difficult to cover complex logical vulnerabilities and hidden security risks.

[0038] Implementation method three: directly use the large language model for code review.

[0039] However, although this code review solution can improve the efficiency of code review, it can only check common coding errors in the code to a certain extent, and it is difficult to effectively check the problem of repeated development of the same functional code in the code. In addition, this code review solution also fails to fully combine the code style and development specifications formulated within the enterprise, resulting in the review results often being difficult to meet the enterprise's specific development standards and requirements.

[0040] In response to the above technical problems, this application proposes a new code review solution, in which a code review model is used to detect whether there are writing errors in the code change file and to find out whether the code change file contains codes with different styles corresponding to each function in the private code database corresponding to the user, so as to avoid the problem of duplicate code construction and effectively improve development efficiency.

[0041] The following is a detailed description of the code review solution provided in the embodiment of the present application in conjunction with the accompanying drawings.

[0042] Figure 1 The following is a flowchart of a code review method provided by an exemplary embodiment of the present application. Figure 1 As shown, the execution subject of the method may be a code review device. Specifically, the method includes:

[0043] 101. In response to monitoring a code change event triggered by a user to a code repository, obtain a code change file corresponding to the code change event.

[0044] 102. Mark code change information in the code change file.

[0045] 103. Input the code change file into a code review model, so that the code review model determines whether there is writing error information in the code change file according to the code change information and identifies whether the code private database corresponding to the user contains a second code that is different from the first code style corresponding to the first function in the code change file.

[0046] 104. Obtain review output information output by the code review model, where the review output information includes audit information corresponding to the writing error information and the second code.

[0047] In the software development process, when the development team completes the development of a new function or module, it is necessary to review the changed code to ensure the quality, readability and compliance with project specifications of the code. Or before merging the code of different development branches into the main branch, the code in the development branch is reviewed to ensure the quality of the code and the compatibility of the code of each development branch.

[0048] Then, in order to realize automatic code review, in this embodiment, the code change event triggered by the user to the code repository is monitored. Among them, the code repository is a centralized or distributed storage space used to store, manage, track and control project code changes. It provides a framework for developers so that multiple people can collaborate on the same project without conflicting with each other. In this embodiment, the code repository can be a private GIT repository corresponding to the user, or it can be a public code repository.

[0049] In specific implementation, you can integrate WebHook in the code repository to monitor code change events triggered to the code repository. Or you can use the repository API to monitor code change events triggered to the code repository. A code change event refers to an event triggered when code is modified, added, or deleted during the software development process. For example, a code change event can be a code merge event, a code submission event, etc.

[0050] After monitoring the code change event triggered by the user to the code repository, in response to monitoring the code change event triggered by the user to the code repository, the code change file corresponding to the code change event is obtained to automatically trigger the code review process. This not only can respond to the code change event in the code repository in a timely and accurate manner, avoid manual intervention, and review the code immediately, but also ensure that each submitted code meets the team's quality standards and coding specifications, which helps to discover potential problems in advance and improve the overall quality of the code.

[0051] Among them, the code change file refers to a file that records the code modification content, which is usually used to track and manage code changes. It contains detailed information about the addition, modification or deletion operations made by developers to the code, helping the team understand the evolution process of the code and the reasons for the change.

[0052] In practical applications, in order to improve the review efficiency, it is usually necessary to focus on reviewing the changed code. In this embodiment, after obtaining the code change file, the code change file is reviewed to determine whether there are quality problems in the code in the code change file.

[0053] Specifically, when conducting code review, the code change files can be reviewed in combination with the code change information, so as to better understand the background and intention of the code change and provide important contextual information for the review.

[0054] For example, code change information may indicate that a code change is made to fix a specific bug or to optimize a certain performance. Code change information can be used to quickly understand the scope and objectives of the change, thereby more effectively evaluating whether the code change meets expectations and identifying potential problems or risks.

[0055] In addition, code change information can also help determine whether the changes are consistent with the overall style and specifications of the project, or whether there are unreasonable modifications or logical errors. By combining code change information and code content, the quality of code changes can be more comprehensively evaluated to ensure the consistency and stability of the code base.

[0056] In specific implementation, after obtaining the code change file, the code change information can be marked in the code change file, so that when reviewing the code in the code change file, the code change information can be combined to further determine whether there are quality problems in the code in the code change file.

[0057] The code change information may be determined in a manner as follows: determining the code change information according to a code change event. After the code change information is determined, the code change information may be marked in a code change file.

[0058] Among them, when the code change file is code reviewed in combination with the code change information, a pre-trained code review model can be used to perform code review on the code change file. Specifically, after the code change file is marked, the code change file is input into the code review model, so that the code review model determines whether there is writing error information in the code change file according to the code change information and identifies whether the user's corresponding code private database contains a second code that is different from the first code style corresponding to the first function in the code change file. The first function here can be any function in the code change file. For the sake of convenience of description, the first function is described here as an example. The first code refers to the code segment corresponding to the first function in the code change file. The second code refers to the code segment corresponding to the first function in the code private database.

[0059] The code review model is used to review whether there are writing errors in the code change file, and further identify whether the code style corresponding to each function in the code change file is different from the style corresponding to each function in the user's corresponding private code database.

[0060] It should be noted that: the identification of whether the code style corresponding to each function in the code change file is different from the code style corresponding to each function in the private code database corresponding to the user can refer to searching in the private code database corresponding to the user whether there is code that implements similar functions (or the same functions) as the code change file but uses a different style, or searching whether there is code in the code change file that has a different style from the code style corresponding to each function in the private code database corresponding to the user. This can not only prevent the code for implementing the same function in the development project from having different writing styles, which is not conducive to later maintenance, but also prevent the code for implementing different functions in the development project from having different writing styles.

[0061] The private code database can refer to the internal code library of the company corresponding to the user. The codes of various functions involved in various projects of the company can be packaged together and stored in the private code database in advance. When writing codes with similar functions, the writing styles of various codes in the private code database can be reused, so that the writing style of the entire project can be kept consistent, which is convenient for later maintenance.

[0062] However, in actual applications, a project may be completed by multiple developers, and not every developer is familiar with the functional modules included in the project and the code styles corresponding to each function. In the actual development process, duplicate code writing may occur. In order to avoid duplicate code construction problems, when reviewing code change files, in addition to checking code writing problems, you can also detect the writing styles corresponding to each function in the code change files.

[0063] For example, suppose that development team A writes a user login module in a certain style, while development team B may write a similar module in another style. This situation can be detected through the code review model, reminding developers that there may be inconsistent code styles. Such detection helps maintain the overall consistency of the code base, reduce maintenance costs, and improve code readability and maintainability. At the same time, it can also help the team discover possible duplicate code or different implementation methods, promote code reuse and the implementation of unified specifications.

[0064] From the above description, it can be seen that: in this embodiment, the code review model is not only used to review common code writing problems, for example, to check whether the code has syntax errors, logical loopholes, security risks, and performance optimization points. The code review model can also be used to identify whether the code corresponding to each function in the code change file is consistent with the writing style corresponding to the same function in the private database, so as to further determine whether there is a problem of duplicate code construction in the code change file corresponding to the same function in the private database. That is, the code review model can not only check code writing errors, but also check the consistency of the writing style corresponding to the same function, and can effectively identify whether there are code segments in the code change file that implement similar functions in the private database but use different styles, so as to avoid the problem of duplicate code construction.

[0065] In addition, the code review model can be a pre-trained code model obtained by fine-tuning the pre-trained code model, for example, further fine-tuning the CodeBERT model, etc. It can also be obtained by training a deep learning model based on multiple code training samples.

[0066] Finally, the review output information output by the code review model is obtained, wherein the review output information includes the review information corresponding to the writing error information and the second code. For example, the output review output information is: there is a syntax error in the code change file, and the second code in the code change file has a different writing style from the first code corresponding to the first function in the code private database.

[0067] In an embodiment of the present application, a code review model is used to detect whether there is writing error information in the code change file and identify whether the user's corresponding code private database contains code with a different code style from the code corresponding to each function in the code change file based on the code change information. This can not only accurately detect whether there are common writing errors in the code change file to improve the accuracy of the code review results, but also effectively identify whether there are code segments in the code change file that implement similar functions as those in the private database but use different writing styles to avoid the problem of duplicate code construction.

[0068] The above embodiment describes a specific application process of using a pre-trained code review model to review the code in a code change file. The training process of the code review model is described in detail below in conjunction with the following embodiment.

[0069] Figure 2 A flowchart of another code review method provided by an exemplary embodiment of the present invention. Figure 2 As shown, based on the above embodiment, specifically, the method may further include the following steps:

[0070] 201. Obtain a first training sample code file and a second training sample code file, wherein the first training sample code file includes a code file for implementing a target function collected from a non-user private database, and the second training sample code file includes a code file for implementing a target function collected from a user private database.

[0071] 202. Determine first supervision information corresponding to the first training sample code file and second supervision information corresponding to the second training sample code file, wherein the first supervision information includes writing error information, style error information and identification information of the target function in the first training sample code file, and the second supervision information includes writing error information and identification information of the target function in the second training sample code file.

[0072] 203. Train the code review model according to the first training sample code file and the first supervision information and the second training sample code file and the second supervision information.

[0073] Among them, the first training sample code file and the second training sample code file have different styles. When learning and training the code review model, not only can the code files in the non-user private database be used, but also the code files in the code private database can be collected at the same time. In this way, the trained code review model can not only understand the code structure and code semantic information well, but also accurately identify a variety of writing errors, so that the code review model has better generalization ability, and at the same time, it can also enable the code review model to learn the characteristics corresponding to different styles of code for the same function. In this way, when the code change file is reviewed based on the code review model in the future, it can quickly and accurately identify whether there is code in the code change file that is inconsistent with the code style corresponding to each function in the code private database.

[0074] After obtaining the first training sample code file and the second training sample code file, determine the first supervision information corresponding to the first training sample code file and the second supervision information corresponding to the second training sample code file. The supervision information may include specific writing error information and style error information in the code file, so that the code review model has the ability to detect basic writing errors in the code file and the ability to identify whether there are inconsistencies in the style corresponding to each function in the code private database in the code file. In addition, the supervision information may also include identification information of the target function corresponding to the code file, so that the code review model can learn the characteristics corresponding to different styles of code for the same function.

[0075] In an embodiment of the present application, a code file that implements the target function in a non-user private database and a code file that implements the target function in a user private database are used as training samples at the same time, and the writing error information, style error information and identification information of the target function in the training samples are used as supervision information to train the code review model. This allows the code review model to not only accurately identify writing errors in code change files, but also identify whether the code change files contain codes with different styles corresponding to the codes corresponding to the functions in the code private database corresponding to the user, so as to avoid the problem of duplicate code construction.

[0076] In addition, in actual applications, in order to facilitate users to view the audit information and modify the code in accordance with the audit information in a timely manner, after obtaining the audit output information output by the code review model, the audit output information can be directly sent to the corresponding user end. Alternatively, after obtaining the audit output information output by the code review model, the audit output information can be integrated and optimized first, and a detailed audit report can be generated and sent to the corresponding user end. At the same time, in order to enable the code review model to more accurately detect errors in the code change file, it is also possible to collect user feedback information corresponding to the audit output information output by the code review model, and optimize the code review model based on the user feedback information.

[0077] This process is described in detail with reference to the following embodiments.

[0078] Figure 3 A flowchart of another code review method provided for an exemplary embodiment of the present application is shown below. Figure 3 As shown, based on the above embodiment, specifically, the method may further include the following steps:

[0079] 301. Send the review output information to the user.

[0080] 302. Receive feedback information sent by the user in response to the review output information.

[0081] 303. Generate optimized training data according to the feedback information to optimize the code review model based on the optimized training data.

[0082] After obtaining the review output information output by the code review model, the review output information may be directly sent to the user, or the review output information may be integrated and then sent to the user.

[0083] Specifically, in an optional embodiment, the file name of the code change file, the position of the error code line, and the review information corresponding to the error code line can be extracted from the review output information; and a text containing the file name of the code change file, the position of the error code line, and the review information corresponding to the error code line is generated to be sent to the user. And / or, the position of the error code line and the review information corresponding to the error code line are extracted from the review output information, and annotation information containing the position of the error code line and the review information corresponding to the error code line is generated, and the annotation information is displayed at the position of the error code line. For example, the annotation information is displayed in association with the position of the error code line.

[0084] The generated text may include not only the audit information but also a summary of code issues in the code change file and suggestions for modifying the issues.

[0085] After the review output information is sent to the user, the user can provide feedback on the review output information to generate corresponding feedback information. The feedback information sent by the user for the review output information is received, and optimized training data is generated according to the feedback information to optimize the code review model based on the optimized training data.

[0086] Among them, in an optional embodiment, the specific implementation process of generating optimized training data according to feedback information to optimize the code review model based on the optimized training data includes: determining a first weight corresponding to the feedback information and a second weight corresponding to the review output information, the first weight being greater than the second weight. Determine a weighted result of the feedback information and the review output information according to the first weight and the second weight as optimized supervision information. Use the code change file and the optimized supervision information as optimized training data to optimize the code review model based on the optimized training data.

[0087] In addition, you can continuously collect new code and code in the private code database as optimized training data to optimize the code review model. Through incremental learning, you can continuously optimize the code review model so that the code review model can adapt to the continuous changes in project scale, development specifications, and technology stack in a timely manner.

[0088] In the embodiment of the present application, optimized training data is generated according to feedback information sent by the user in response to the review output information output by the code review model, so as to optimize the code review model based on the optimized training data. The code review model can be continuously optimized so that the code review model can accurately review the writing errors in the code change file and accurately identify whether the code style of each function in the code change file is consistent with the code style of each function in the code private database.

[0089] In addition, the embodiments of the present application can not only be used to review and process code change files, but also can be used to rewrite writing errors in code change files and second codes with different writing styles corresponding to the same function in code change files.

[0090] For example, suppose the code review model finds that there is a writing error in the first code corresponding to the first function in the code change file. In specific implementation, the code review device responds to the first code corresponding to the first function input by the user into the code review model, and obtains the rewrite result information output by the code review model, and the rewrite result information includes the code after the writing error corresponding to the first code is modified. For example, suppose the first code is @property(nonatomic,strong)NSString*subscribe. Then the rewrite result information output by the code review model is: Use copy instead of strong: For properties of NSString type, it is generally recommended to use copy instead of strong. This is because NSString is immutable, and using copy can prevent external code from passing a mutable NSMutableString object and then modifying it later, thereby affecting your property value. The modified declaration should be: ```objc\n@property(nonatomic,copy)NSString*subscribe;```\n”}]}.

[0091] It is assumed that the code review model finds that the third code corresponding to the second function in the code change file has a different style from the codes corresponding to the functions in the user's private database. In specific implementation, the code review device responds to the third code corresponding to the second function input by the user into the code review model, and obtains the rewriting result information output by the code review model, the rewriting result information includes a fourth code having the same style as the codes corresponding to the functions in the user's private database, and the style of the third code has a different style from the codes corresponding to the functions in the user's private database.

[0092] Among them, when the code review model recognizes that the style of the third code corresponding to the second function is different from the style of the codes corresponding to each function in the user's private database, the style of the third code can be rewritten based on the style corresponding to each function in the code private database to generate rewriting result information.

[0093] In an optional embodiment, if the code private database contains a fourth code corresponding to the second function, the third code in the code change file can be directly rewritten as the fourth code corresponding to the second function in the code private database. That is, if the code private database contains the fourth code corresponding to the second function, it is recommended that the user directly reuse the fourth code in the code private database.

[0094] If the private code database does not contain the code corresponding to the second function, the third code can be rewritten according to the style of the code corresponding to each function in the user private database, or the third code can be rewritten according to the style of the code corresponding to the context code corresponding to the third code.

[0095] For example, the third code in the code change file is: if(self.lastLocal.length>0). The user private database contains the string empty judgment macro IS_NOT_EMPTY. The current project has a unified string empty judgment macro IS_NOT_EMPTY. Please use a unified method to maintain the consistency and maintainability of the code. That is, the rewrite result information output by the code review model is: The current project has a unified string empty judgment macro IS_NOT_EMPTY. Please use a unified method to maintain the consistency and maintainability of the code. The modified code is: ```objc\n if IS_NOT_EMPTY(self.lastLocal){```\n”}]}.

[0096] In addition, the code review solution provided in the embodiment of the present application can not only review the code problems corresponding to the code change files and provide modification suggestions for the code problems, but also directly perform subsequent processing on the code change events triggered by the users. This process is exemplified in conjunction with the following embodiment.

[0097] Figure 4 A flowchart of another code review method provided for an exemplary embodiment of the present application. Figure 4 As shown, the code change event is a code merge event. Based on the above embodiment, specifically, the method may further include the following steps:

[0098] 401. Determine whether the code change file meets the set merge requirements based on the review output information.

[0099] 402. In response to a determination result that the code change file does not meet the merge requirement, output merge prompt information.

[0100] After obtaining the review output information output by the code review model, determine whether the code change file meets the set merge requirements based on the review output information. The merge requirements can be pre-set according to actual application requirements. Optionally, in the embodiment of the present application, the set merge requirements may include whether the number of error codes meets a preset threshold, whether the error type corresponding to the error code meets a set error level, whether the code in the code change file meets the code style and development rules defined by the project, etc.

[0101] Specifically, in an optional embodiment, the implementation process of determining whether the code change file meets the set merging requirements based on the review output information can be: determining the error code line corresponding to the writing error information and the first error type of the error code line in the code change file according to the review output information, and determining the second error type corresponding to the second code in the code change file; determining whether the code change file meets the set merging requirements based on the proportion of the error code lines in the code change file and the set error levels corresponding to the first error type and the second error type.

[0102] The error types corresponding to each code problem and the optimization levels corresponding to each error type can be preset. The error types include grammatical errors, spelling errors, contextual logic errors, etc., as well as error types corresponding to writing styles. The error types corresponding to writing styles include that the representation of certain characters in the first code is inconsistent with the style of each function code in the code private database, the implementation method corresponding to the first code is different from the implementation method corresponding to the second code, or the style of the first code is inconsistent with the style of the context code related to the first code. The implementation method here means, for example, that the function is to sort numbers, the implementation method corresponding to the first code is to sort from small to large, and the second code is to sort from large to small.

[0103] After determining whether the code change file meets the merge requirements, a merge prompt message may be output in response to the determination result that the code change file does not meet the merge requirements to prompt the user to modify the error code in the code change file. The merge prompt message may include detailed improvement suggestions.

[0104] Alternatively, in response to a determination result that the code change file meets the merge requirement, a merge operation may be performed based on the code change file.

[0105] In the embodiment of the present application, by determining whether the code change file meets the set merge requirements based on the review output information, it is automatically decided whether to allow the code merge. This not only can seamlessly connect to the private Git repository API, and realize automatic review and merge processing or merge blocking processing in the pull request (Pull Request) or merge request (Merge Request) process, but also can ensure the quality and standardization of the submitted code, and avoid affecting the overall development progress and stability of the project due to quality problems.

[0106] In order to facilitate understanding of the specific implementation process of the above code review, the above implementation process is illustrated with examples combined with specific application scenarios.

[0107] Before performing code review on the code change files submitted to the code repository, you can first create a private code database corresponding to the user. The private code database is used to store code files of commonly used functions in various projects of the company.

[0108] In addition, the code review model can be pre-trained so that the code review model can be used to perform code review on the code change file in the future to output corresponding review information, rewriting result information, rewriting suggestion information, etc. The specific training process of the code review model can refer to the content described in the above embodiment, which will not be repeated here.

[0109] After completing the above preliminary work, the code change files can be reviewed. In specific implementation, after monitoring the code merge event triggered by the user to the GIT repository through WebHook or repository API, in response to monitoring the code merge event triggered by the user to the GIT repository, the code change files corresponding to the code merge event are obtained.

[0110] According to the code merge event, the code change information related to the code merge is extracted. The code change information includes the commit record, branch status, pull request difference Diff, change code context, etc. The code change information is marked in the code change file, and the code change file is input into the code review model, so that the code review model determines whether there is writing error information in the code change file according to the code change information and identifies whether the user's corresponding code private database contains a second code with a different code style from the first code style corresponding to the first function in the code change file.

[0111] Finally, the review output information output by the code review model is obtained, where the review output information includes audit information corresponding to the writing error information and the second code.

[0112] In another specific application scenario, this solution can be applied to perform code review on the extracted target code. When implemented:

[0113] First, a code change event triggered by a user to a code repository is monitored. If a code change event is monitored, a code change file corresponding to the code change event is obtained in response to the monitored code change event.

[0114] Extract the code to be reviewed and the code change information corresponding to the code to be reviewed from the code change file. The code to be reviewed can be the changed code or the important code in the code change file.

[0115] Next, the code to be reviewed, the context code corresponding to the code to be reviewed, the code change information, the file information corresponding to the code to be reviewed, and the line number information corresponding to the code to be reviewed are input into the code review model, so that the code review model determines whether there is writing error information in the code to be reviewed based on the code change information and identifies whether the user's corresponding code private database contains code that is different from the first working style corresponding to the code to be reviewed.

[0116] When the code review model determines that there is coding error information in the code to be reviewed, the cause of the error and the corresponding rewriting result information can be generated based on the coding error information, and finally the audit information corresponding to the coding error information, the cause of the error and the corresponding rewriting result information are output. When the code review model determines that the style corresponding to the code to be reviewed is different from the style corresponding to each function in the user's code private database, the audit information corresponding to the style error information can be output, and the cause of the style error and the corresponding rewriting result information can be generated based on the style error information, and the cause of the style error and the corresponding rewriting result information are output, so that the user can modify the code to be reviewed based on this information.

[0117] Among them, in an optional embodiment, the specific implementation process of determining the review information corresponding to the code to be reviewed, the cause of the error and the corresponding rewrite result information through the code review model can be: inputting the code to be reviewed, the context code corresponding to the code to be reviewed, the code change information, the file information corresponding to the code to be reviewed, and the line number information corresponding to the code to be reviewed into the code review model.

[0118] In the code review model, the input layer is used to perform word embedding and position embedding processing on the code to be reviewed, the context code, and the code change information to obtain a first embedding vector containing position information corresponding to the code to be reviewed and a second embedding vector containing position information corresponding to the context code; the first feature vector and the second feature vector are input into the encoding layer, and the first feature vector is encoded using the second feature vector to determine the grammatical features, semantic features, and contextual features corresponding to the code to be reviewed; the grammatical features, semantic features, and contextual features corresponding to the code to be reviewed are input into the code checking layer, and based on the grammatical features, semantic features, and contextual features corresponding to the code to be reviewed, the code to be reviewed is checked for writing errors to obtain a first inspection result corresponding to the code to be reviewed. The quality assessment includes coding standard checking, grammatical error checking, logical error checking, security checking, performance optimization checking, etc. The grammatical features, semantic features, and context features corresponding to the code to be reviewed are input into the code judgment layer, and based on the grammatical features, semantic features, and context features corresponding to the code to be reviewed, the code to be reviewed is checked for consistency in code style with the upper and lower code fragments, and the code to be reviewed is checked for consistency in code style with the code corresponding to each function in the code private database, so as to obtain the second inspection result corresponding to the code to be reviewed; the first inspection result and the second inspection result are input into the code analysis layer, and based on the first inspection result and the second inspection result, the audit information and the corresponding rewriting prompt information are generated, and the corresponding audit information and the corresponding rewriting prompt information are output.

[0119] Next, based on the review output information output by the code review model, determine whether the code to be reviewed meets the set merge requirements. If the code to be reviewed meets the set merge requirements, then in response to the determination result that the code to be reviewed meets the merge requirements, based on the code merge request triggered by the user, perform a merge operation on the code to be reviewed. If the code to be reviewed does not meet the set merge requirements, then in response to the determination result that the code to be reviewed does not meet the merge requirements, output merge prompt information so that the user can process the code to be reviewed in a timely manner based on the merge prompt information.

[0120] In this embodiment, by making full use of the advantages of the private code base, it is possible to accurately identify whether the code to be reviewed has functional duplication problems, so as to avoid duplicate code construction, effectively improve development efficiency, reduce testing costs, and greatly reduce the iterative maintenance costs of the code. In addition, the code to be reviewed can be reviewed in combination with the code style and development specifications of the private code database, which can ensure that the code quality is uniform and meets the code standards in the private code database. When performing style review on the code to be reviewed, the quality of code review can be improved.

[0121] The following will describe in detail the code review device of one or more embodiments of the present application. Those skilled in the art will appreciate that these devices can be configured using commercially available hardware components through the steps taught in this solution.

[0122] Figure 5 A code review device is provided for an exemplary embodiment of the present application, such as Figure 5 As shown, the device includes: a response module 11, a marking module 12, an input module 13, and an acquisition module 14.

[0123] The response module 11 is used for acquiring a code change file corresponding to the code change event in response to monitoring a code change event triggered by a user to the code repository.

[0124] The marking module 12 is used to mark the code change information in the code change file.

[0125] The input module 13 is used to input the code change file into a code review model so that the code review model determines whether there is writing error information in the code change file according to the code change information and identifies whether the code private database corresponding to the user contains a second code that is different from the first code style corresponding to the first function in the code change file.

[0126] The acquisition module 14 is used to acquire the review output information output by the code review model, wherein the review output information includes the review information corresponding to the writing error information and the second code.

[0127] Optionally, the device also includes a rewriting module, which is specifically used to: in response to a third code corresponding to a second function input by the user into the code review model, obtain rewriting result information output by the code review model, the rewriting result information including a fourth code having the same style as the codes corresponding to each function in the user's private database, and the style of the third code has a different style from the codes corresponding to each function in the user's private database.

[0128] Optionally, the code change event is a code merge event, and the device also includes a merge module, which is specifically used to: determine whether the code change file meets the set merge requirements based on the review output information; and output merge prompt information in response to the determination result that the code change file does not meet the merge requirements.

[0129] Optionally, the merging module is also used to: determine, based on the review output information, the error code line in the code change file corresponding to the writing error information and the first error type of the error code line, and determine the second error type corresponding to the second code in the code change file; determine whether the code change file meets the set merging requirements based on the proportion of the error code lines in the code change file and the set error levels corresponding to the first error type and the second error type.

[0130] Optionally, the device also includes a feedback module, which is specifically used to: send the review output information to the user; receive feedback information sent by the user regarding the review output information; generate optimized training data according to the feedback information to optimize the code review model based on the optimized training data.

[0131] Optionally, the feedback module is specifically used to: extract the file name of the code change file, the error code line position and the review information corresponding to the error code line from the review output information; and generate a text containing the file name of the code change file, the error code line position and the review information corresponding to the error code line, to send to the user; and / or extract the error code line position and the review information corresponding to the error code line from the review output information, generate comment information containing the error code line position and the review information corresponding to the error code line, and display the comment information at the error code line position.

[0132] Optionally, the feedback module is specifically used to: determine a first weight corresponding to the feedback information and a second weight corresponding to the review output information, the first weight being greater than the second weight; determine a weighted result of the feedback information and the review output information according to the first weight and the second weight as optimization supervision information; use the code change file and the optimization supervision information as optimization training data to optimize the code review model based on the optimization training data.

[0133] Optionally, the device also includes a training module, which is specifically used to: obtain a first training sample code file and a second training sample code file, wherein the first training sample code file includes a code file for implementing a target function collected from a non-user private database, and the second training sample code file includes a code file for implementing the target function collected from the user private database, and the first training sample code file and the second training sample code file have different styles; determine first supervision information corresponding to the first training sample code file and second supervision information corresponding to the second training sample code file, the first supervision information including writing error information, style error information and identification information of the target function in the first training sample code file, and the second supervision information including writing error information and identification information of the target function in the second training sample code file; train the code review model according to the first training sample code file, the first supervision information, the second training sample code file and the second supervision information.

[0134] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 6 As shown, in practice, the electronic device includes: a memory 21 and a processor 22.

[0135] The memory 21 is used to store computer programs and can be configured to store various other data to support operations on the electronic device. Examples of such data include instructions for any application or method operating on the electronic device, data structures, contact data, phone book data, messages, pictures, videos, etc.

[0136] The processor 22 is coupled to the memory 21 and is used to execute the computer program in the memory 21 to implement the code review method provided in the above embodiment.

[0137] Further, if Figure 6 As shown, the electronic device also includes: a communication component 23, a display 24, a power component 25, an audio component 26 and other components. Figure 6 Only some components are shown schematically, which does not mean that the electronic device only includes Figure 6 The electronic device of this embodiment can be implemented as a terminal device such as a desktop computer, a laptop computer, a smart phone or an IOT device, or a server device such as a conventional server, a cloud server or a server array.

[0138] The above-mentioned memory can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read only memory (EEPROM), erasable programmable read only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk or optical disk.

[0139] The communication component is configured to facilitate wired or wireless communication between the device where the communication component is located and other devices. The device where the communication component is located can access a wireless network based on a communication standard, such as a mobile communication network such as 2G, 3G, 4G / LTE, 5G, or a combination thereof. In an exemplary embodiment, the communication component receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel.

[0140] The above-mentioned display includes a screen, and the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.

[0141] The power supply assembly provides power to various components of the device where the power supply assembly is located. The power supply assembly may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device where the power supply assembly is located.

[0142] The above-mentioned audio component can be configured to output and / or input audio signals. For example, the audio component includes a microphone (Microphone, MIC), and when the device where the audio component is located is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in a memory or sent via a communication component. In some embodiments, the audio component also includes a speaker for outputting an audio signal.

[0143] Accordingly, an embodiment of the present application further provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the processor is enabled to implement each step in the above method embodiment.

[0144] Among them, the computer-readable storage medium includes volatile or non-volatile or a combination thereof, and may be removable or non-removable. Examples of computer-readable storage media include, but are not limited to, phase-change random access memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), flash memory or other memory technology, read-only compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette, tape disk storage or other magnetic storage device or any other non-transmission medium.

[0145] Accordingly, an embodiment of the present application further provides a computer program product, which includes a computer program or instructions. When the computer program or instructions are executed by a processor, the processor is enabled to implement each step in the above method embodiment.

[0146] It should be understood that each process or a combination of multiple processes in the above method process can be implemented by a computer program or instruction. In addition, these computer programs or instructions can be applied to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device, so that the processor of the general-purpose computer, the special-purpose computer, the embedded processor or other programmable data processing device can be implemented as a device to implement the corresponding functions in the above method embodiments.

[0147] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A code review method, characterized in that: include: In response to monitoring a code change event triggered by a user to a code repository, obtaining a code change file corresponding to the code change event; Marking code change information in the code change file; Inputting the code change file into a code review model, so that the code review model determines whether there is writing error information in the code change file according to the code change information and identifies whether the private code database corresponding to the user contains a second code that is different from the first code style corresponding to the first function in the code change file; The review output information output by the code review model is obtained, wherein the review output information includes audit information corresponding to the writing error information and the second code.

2. The method according to claim 1, characterized in that The method further comprises: In response to the third code corresponding to the second function input by the user into the code review model, rewriting result information output by the code review model is obtained, the rewriting result information includes a fourth code having the same style as the codes corresponding to the functions in the user's private database, and the style of the third code is different from the style of the codes corresponding to the functions in the user's private database.

3. The method according to claim 1, characterized in that The code change event is a code merge event, and the method further includes: Determining whether the code change file meets the set merging requirements according to the review output information; In response to a determination result that the code change file does not meet the merge requirement, merge prompt information is output.

4. The method according to claim 3, characterized in that The determining, according to the review output information, whether the code change file meets the set merging requirements includes: Determine, according to the review output information, an error code line corresponding to the writing error information and a first error type of the error code line in the code change file, and determine a second error type corresponding to the second code in the code change file; Whether the code change file meets the set merging requirements is determined according to the proportion of the error code lines in the code change file and the set error levels corresponding to the first error type and the second error type.

5. The method according to claim 1, characterized in that The method further comprises: Sending the review output information to the user; receiving feedback information sent by the user in response to the review output information; Generate optimized training data according to the feedback information to optimize the code review model based on the optimized training data.

6. The method according to claim 5, characterized in that The sending the review output information to the user comprises: Extracting the file name of the code change file, the position of the error code line, and the review information corresponding to the error code line from the review output information; and generating a text including the file name of the code change file, the position of the error code line, and the review information corresponding to the error code line, to send to the user; and / or, The error code line position and the review information corresponding to the error code line are extracted from the review output information, annotation information including the error code line position and the review information corresponding to the error code line is generated, and the annotation information is displayed at the error code line position.

7. The method according to claim 5, characterized in that Generating optimized training data according to the feedback information to optimize the code review model based on the optimized training data includes: Determine a first weight corresponding to the feedback information and a second weight corresponding to the review output information, wherein the first weight is greater than the second weight; Determining a weighted result of the feedback information and the review output information according to the first weight and the second weight as optimized supervision information; The code change file and the optimization supervision information are used as optimization training data to optimize the code review model based on the optimization training data.

8. The method according to claim 1, characterized in that The method further comprises: Acquire a first training sample code file and a second training sample code file, wherein the first training sample code file includes a code file for implementing a target function collected from a non-user private database, the second training sample code file includes a code file for implementing the target function collected from the user private database, and the first training sample code file and the second training sample code file have different styles; Determine first supervision information corresponding to the first training sample code file and second supervision information corresponding to the second training sample code file, wherein the first supervision information includes writing error information, style error information, and identification information of the target function in the first training sample code file, and the second supervision information includes writing error information and identification information of the target function in the second training sample code file; The code review model is trained according to the first training sample code file, the first supervision information and the second training sample code file, and the second supervision information.

9. An electronic device, characterized in that: include: Memory and processor; The memory is used to store a computer program; the processor is coupled to the memory and is used to execute the computer program to implement the steps in the code review method according to any one of claims 1 to 8.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the processor is caused to implement the steps in the code review method according to any one of claims 1 to 8.

11. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the processor is caused to implement the steps in the code review method according to any one of claims 1 to 8.