Code review method based on AI, computing device and storage medium
Patent Information
- Application Number
- CN202411187865.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-27
- Publication Date
- 2024-12-17
AI Technical Summary
In the prior art, code review mainly relies on manual labor, is inefficient and prone to review omissions, making it difficult to guarantee code quality and functionality.
Introduce the AI model, by analyzing the code information to be merged, extracting the code change content and the preset prompt templates, interacting to generate code review information, determining the code review results, and realizing automated and standardized code review.
Ensure that code review has consistent standards, avoid manual negligence, improve review efficiency, reduce human investment, and make full use of AI's semantic understanding capabilities.
Smart Images

Figure CN119149416A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information processing technology, and in particular to an AI-based code review method, computing device, and storage medium. Background Art
[0002] In the process of software development, developers usually use version control systems such as Git to manage different versions of the code. In a version control system, merging refers to code merging, specifically the basic operation of integrating different changes that occur in a group of files. Among them, different branches can be established in the process of using a version control system, allowing different developers to perform operations such as adding and editing on the same group of files. These collaborative branches need to be merged to integrate all changes to form a file version. In order to facilitate the discovery of potential errors and vulnerabilities in the code and ensure code quality and functionality, after initiating a merge request, a code review is required, and the merge operation is performed after the code review is passed. In the prior art, code review is mainly completed manually, the review efficiency is low, and the process and results of manual review vary from person to person, which is prone to review omissions. Summary of the invention
[0003] In view of the above problems, the present invention is proposed to provide an AI-based code review method, computing device and storage medium that overcome the above problems or at least partially solve the above problems.
[0004] According to one aspect of the present invention, there is provided an AI-based code review method, the method comprising:
[0005] Obtain the code information to be merged corresponding to the merge request, parse the code information to be merged, and extract the code change content;
[0006] Combine the code change content with the preset prompt template to obtain prompt information, and interact with the AI model based on the prompt information to obtain code review information;
[0007] Determine the code review results based on the code review information.
[0008] According to another aspect of the present invention, there is provided a computing device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus;
[0009] The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform the following operations:
[0010] Obtain the code information to be merged corresponding to the merge request, parse the code information to be merged, and extract the code change content;
[0011] Combine the code change content with the preset prompt template to obtain prompt information, and interact with the AI model based on the prompt information to obtain code review information;
[0012] Determine the code review results based on the code review information.
[0013] According to another aspect of an embodiment of the present invention, a computer storage medium is provided, in which at least one executable instruction is stored, and the executable instruction enables a processor to perform operations corresponding to the above-mentioned AI-based code review method.
[0014] According to the technical solution provided by the present invention, an AI model is introduced into the code review process, and the code change content can be easily extracted by parsing the code information to be merged corresponding to the merge request; the code change content is spliced with the preset prompt template to obtain prompt information, and the prompt information is interacted with the AI model. The code review is completed through the AI model, which not only ensures that the code review has a consistent review standard, realizes automated and standardized code review, avoids problems such as omissions caused by negligence in manual review, but also makes full use of the semantic understanding ability of the AI model, effectively improves the review efficiency, and reduces the manpower investment in code review.
[0015] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0017] Figure 1 A schematic diagram of a flow chart of an AI-based code review method according to Embodiment 1 of the present invention is shown;
[0018] Figure 2 A schematic diagram of a flow chart of an AI-based code review method according to Embodiment 2 of the present invention is shown;
[0019] Figure 3 A timing diagram of an AI-based code review method is shown;
[0020] Figure 4 A schematic diagram showing a code review result;
[0021] Figure 5 A schematic diagram of the structure of a computing device according to a fourth embodiment of the present invention is shown. DETAILED DESCRIPTION
[0022] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0023] First, the terms involved in one or more embodiments of the present invention are explained.
[0024] Git: is an open-source version control system used for software development that helps manage different versions of code in a repository (repo).
[0025] Git Flow: is a recommended branch management strategy when using the Git version control system. Its main purpose is to provide a clear framework for managing the development, testing, release and maintenance processes in a project, especially suitable for a team collaboration environment. Git Flow designs a specific set of naming conventions and workflows to simplify and standardize the development process.
[0026] Tag: is a snapshot in the version control system, used to mark a version or milestone. In Git, tags can be lightweight or signed.
[0027] Fork: It is the process of copying a repository in a version control system, usually used in open source projects, allowing users to create a copy of a project under their own account, so that they can freely modify the code without interfering with the original project.
[0028] Gitlab: is an open source project for warehouse management systems, using Git as a code management tool and building a web service on this basis. It is a widely used open source code management platform based on Git, built on Ruby on Rails, and mainly manages the code and documents generated during the software development process. Gitlab mainly manages code and documents in two dimensions: groups and projects. A group can manage multiple projects, which can be understood as a group with multiple software development tasks, and a project may contain multiple branches. The branches are independent of each other and different branches can be merged.
[0029] In order to facilitate understanding of the present invention, the application scenario of the present invention is introduced below. Taking Git as the version control system, Git Flow is used to manage the development, testing, release and maintenance processes in the project. Git Flow includes branches such as Master, Hotfix, Release, Develop, and Feature, and each branch has a different function. Among them, the Master branch stores the officially released historical versions. It is a fully functional and available branch that can be released to the online for deployment at any time. It is marked based on tags for easy and quick rollback; the Hotfix branch is used to fix online failures (bugs) and quickly patch. This branch is based on the tag fork of the online Master branch. After the bug is fixed, the branch needs to be merged into the Master branch and the Develop branch; the Release branch is a pre-release branch. Once all the work is ready, the Release branch is merged into the Master branch and a tag is added to the Master branch, marked as the version number; the Develop branch is a test branch. As an integration branch of the function, subsequent version releases and new function development of the Feature branch are all based on this branch fork; the Feature branch is a functional branch, using the Develop branch as the parent branch, and merged into the Develop branch when the new function development is completed.
[0030] For example, every time a new function needs to be developed, a development branch, such as the Develop-1 branch, is pulled from the Master branch. When the Master branch is updated, it is merged into the Develop-1 branch, the Develop branch, and the Release branch in a timely manner. After the Develop-1 branch is developed, it is merged into the Develop branch and the test environment is deployed. After the Develop environment test passes, the code of the Develop-1 branch is merged into the Release environment for pre-release testing. After the Release environment test passes, the code of the Develop-1 branch is merged into the Master branch and put online. In the code merging mechanism in Gitlab, the source branch can be pushed to the remote end, the target branch is specified in Gitlab, and a merge request is submitted through the page. After the merge request is initiated, the requested merged code and its related information are code reviewed, and the merge operation is performed after the code review passes to complete the code merge. The present invention introduces an AI (Artificial Intelligence) model into the code review process, extracts the code change content, splices it with a preset prompt template, interacts with the AI model, and is processed by the AI model to obtain the code review information fed back by the AI model, and then determines the code review result according to the code review information.
[0031] Embodiment 1
[0032] Figure 1 A flowchart of an AI-based code review method according to Embodiment 1 of the present invention is shown. Figure 1 As shown, the method comprises the following steps:
[0033] Step S101, obtaining the code information to be merged corresponding to the merge request, parsing the code information to be merged, and extracting the code change content.
[0034] The present invention can be performed by a code review server. When a developer wants to merge a part of the code into other parts after completing the development of the code, a merge request (Merge Request, MR) can be initiated to a code management platform such as Gitlab through a client, and the code management platform notifies the code review server. The code review server can obtain the code information to be merged corresponding to the merge request from the code management platform, and then extract the code change content by parsing the code information to be merged.
[0035] Step S102, splicing the code change content with the preset prompt template to obtain prompt information, and interacting with the AI model based on the prompt information to obtain code review information.
[0036] In order to facilitate the interaction with the AI model so that it can efficiently complete the code review work, a preset prompt template is set in advance, and the code change content is spliced with the preset prompt template to obtain prompt information. The AI model interacts with the prompt information based on the prompt information. The AI model reviews and processes the received prompt information, generates and feeds back code review information.
[0037] Step S103, determining the code review result according to the code review information.
[0038] After obtaining the code review information, the code review results corresponding to the merge request can be obtained by summarizing and formatting the code review information. Among them, the code review information may include: change summary information, file change list and coding suggestion information, and the code review information may also include: the code problem level corresponding to the merge request. Specifically, the change summary information can also be called a change walkthrough, which refers to the summary and general information of the change content of all files; the file change list refers to the change content classified according to the file dimension and displayed in the form of a list; the coding suggestion information refers to the coding suggestion generated by the AI model according to the change content of the file and its related knowledge content; the code problem level refers to the level determined by rating the coding suggestion information, for example, it may include N levels of different degrees, and the N levels may correspond to no obvious problems, need to pay attention, focus on, etc.
[0039] By utilizing the AI-based code review method provided in this embodiment, an AI model is introduced into the code review process. By parsing the code information to be merged corresponding to the merge request, the code change content can be easily extracted; the code change content is spliced with the preset prompt template to obtain prompt information, and the prompt information is interacted with the AI model. The code review is completed through the AI model, which not only ensures that the code review has a consistent review standard, realizes automated and standardized code review, and avoids problems such as omissions caused by negligence in manual review, but also makes full use of the semantic understanding ability of the AI model, effectively improves the review efficiency, and reduces the manpower investment in code review.
[0040] Embodiment 2
[0041] Figure 2 A schematic diagram of a flow chart of an AI-based code review method according to Embodiment 2 of the present invention is shown. Figure 2 As shown, the method comprises the following steps:
[0042] Step S201: receiving a notification request carrying merge request information sent by a code management platform according to a merge request from a client, parsing the merge request information, and determining a status type of the merge request.
[0043] When a developer wants to merge a part of the code into other parts after completing the development of a certain part, he can initiate a merge request to a code management platform such as Gitlab through the client, and the merge request carries the information of the code to be merged; based on the merge request of the client, the code management platform can send a notification request to the code review server through webhook, and the notification request carries the merge request information, wherein webhook is a real-time communication technology based on the HTTP callback mechanism, that is, when a predefined event occurs, the source system (usually an API or service, etc.) will send a request to the target system (Webhook subscriber) carrying information related to the event. Specifically, the merge request information may include the merge initiating user information, source branch, target branch, merge request status type, request initiation time, etc.
[0044] After receiving the notification request, the code review server parses the merge request information carried in the notification request to determine whether it is necessary to initiate a code review process. Specifically, the merge request information is parsed to determine the status type of the merge request. There are many types of merge request status types, such as open, closed, and update. Among them, the open status indicates that the merge request is newly created, indicating that the merge request is currently active and is waiting for review and processing; the closed status indicates that the merge operation is not allowed; the update status indicates that the merge request has been updated. Code review is only required when the merge request is in the open state.
[0045] Step S202: If the status type is open, the to-be-merged code information corresponding to the merge request is obtained from the code management platform.
[0046] If the status type is open, it means that code review is required, then the interface of the code management platform is called to obtain the code information to be merged corresponding to the merge request from the code management platform. The code information to be merged may specifically include the changed code and related comments for this merge. Figure 3 A timing diagram of an AI-based code review method is shown, Figure 3 As shown, the code review server calls the interface of the code management platform to obtain the code information to be merged, and the code management platform returns the code information to be merged to the code review server.
[0047] Step S203: parse the code information to be merged and extract the code change content.
[0048] The code review server parses the code information to be merged, and extracts the code change content (i.e., diffs) from the code information to be merged. Check whether the code change content is empty; if it is empty, the method ends. Since the present invention introduces the AI model into the code review process and performs code review processing through the AI model, if the code change content is too much, it is not convenient to perform code review processing through the AI model. If the code change content is not empty, it can be identified based on the total number of characters in the code change content whether the code change content is too much and the review is abandoned. Specifically, it is determined whether the total number of characters in the code change content is greater than the preset number of characters; if the total number of characters is greater than the preset number of characters, it means that the code change content is too much and it is not convenient to perform code review processing through the AI model, then the interface of the code management platform is called to submit the abandonment review information for the merge request; if the total number of characters is less than or equal to the preset number of characters, it means that the code change content is not too much and can be processed through the AI model for code review, then step S204 is executed to splice the code change content with the preset prompt template to obtain prompt information.
[0049] Step S204: splice the code change content with the preset prompt template to obtain prompt information, and interact with the AI model based on the prompt information to obtain code review information.
[0050] In order to facilitate interaction with the AI model so that it can efficiently complete the code review work, a preset prompt template is pre-set, wherein the preset prompt module can be set in the form of prompt information (i.e. prompt) based on the experience records of the development team in the code review work. The preset prompt module may include several parts such as title, description, code change content splicing part, instructions, etc., and the code review information is obtained by splicing the code change content obtained in step S203 into the code change content splicing part in the preset prompt module. Those skilled in the art can set the specific content of the title, description, instructions and other parts according to actual needs. For example, the content of the description part can be: "I hope to succinctly summarize the differences in 100 words. If applicable, the feedback summary should include changes to the signatures of exported functions, global data structures and variables, as well as descriptions of any changes that may affect the external interface or behavior of the code."
[0051] Optionally, the preset prompt template can record preset check items. In the process of setting preset check items, the following precautions for front-end coding can be combined for setting: (1) The client time can be modified by the user. If there are scenarios in the front-end that are heavily dependent on time, such as hourly flash sales, the server time returned by the interface should be used. Taking the hourly flash sales scenario as an example, if the countdown depends on the client time, the user can enter the activity flash sales page corresponding to the hourly flash sales in advance by modifying the client time. (2) Due to numerical precision problems in the front-end, the calculation results may be too long, and even the page display may overflow due to precision problems. Therefore, do not perform numerical calculations on the front-end. It is recommended to directly use the fields returned by the server. If calculations must be performed, be sure to use front-end numerical calculation libraries such as bignumber.js. (3) Since the front-end code is exposed to the user, the user may tamper with the code execution logic to cross some restrictions and achieve specific purposes. Therefore, the front-end does not make additional decisions such as "whether the user is eligible to participate in a certain activity" or "whether the user can use a certain coupon". It should directly use the specific fields returned by the server to make judgments. (4) Do not write mock data in the code. Try to use YAPI to simulate data. Otherwise, forgetting to delete the mock code will cause serious online failures. (5) Basic operations refer to non-specific business logic processing, which are commonly used processing operations in front-end development, such as page jumps, URL parameter parsing, host environment judgment, page bottom judgment, etc. When basic operations are needed, core-lib should be used first (core-lib usage documentation). If core-lib does not have relevant methods, you should give priority to core-lib and use it after the new version is released. (6) Use front-end local storage with caution. When using front-end local storage, follow the following principles: storage keys should have corresponding deletion times; cache key names should be specific, clear, and not easily reused; once the local storage logic is online, any subsequent modifications must be regressed throughout the process. For example, after entering a certain activity page, there is a pop-up guidance logic. In order to avoid repeated pop-ups, the front-end development caches the ID list of the pop-up windows through localStorage. Later, due to changes in requirements, a specific pop-up window type needs to be able to pop up multiple times, so the storage structure changes, but the cache Key does not change. Since online users have cached the old data structure, the impact on such users was not regressed before going online. Therefore, after the change is online, the new code logic is used to operate the old data structure, resulting in code errors.
[0052] Specifically, the preset check items may include one or more of the following check items: client time check items, function check items, digital calculation check items, analog data check items, global variable check items, digital check items, type check items, etc. Those skilled in the art may set the preset check items according to actual needs, which are not limited here.
[0053] Different preset prompt templates can be set for different project types. According to the project type of the project to which the code information to be merged belongs, the preset prompt template corresponding to the project type is loaded, so as to implement code review with different focuses for different project types. Among them, project types may include mobile web, PC web, mini-programs or quick applications, server-side Nodejs, and other custom extension project types. The preset prompt template can be written in a lightweight markup language such as Markdown. Taking the mobile web project as an example, its corresponding preset prompt template can be as follows:
[0054] Given a set of code differences in a merge request in GitLab, you need to review the code based on the following principles:
[0055] -Don't give positive comments or compliments
[0056] -Only point out points that need improvement, please omit positive affirmations
[0057] -Stick to the facts
[0058] -Focus on the following issues when reviewing the code (check if they exist, if so, report an error and point out the error; if not, skip it):
[0059] 1. You cannot use client time, such as Date.now()
[0060] 2. Do not use console.log()
[0061] 3. Do not perform numerical calculations, such as addition, subtraction, multiplication and division, as this will cause precision problems
[0062] 4. Do not write mock data into the code
[0063] 5. Global variables, such as window, cannot be used
[0064] 6. Do not use magic numbers, such as if (status === 1) code
[0065] 7. Do not use any type in typescript projects
[0066] In step S204, the code change content is spliced with the preset prompt template to obtain prompt information, and a create completion request is sent to the AI model according to the prompt information. The "completion" here refers to requesting the AI model to generate subsequent text content according to the given prompt information in the natural language processing (NLP) task. The AI model performs review processing based on the received prompt information, generates code review information, and sends it to the code review server in the completion content. Among them, the code review information may include: change summary information, file change list and coding suggestion information; the file change list is obtained by classifying the change content of each file.
[0067] In the present invention, the interaction process between the code review server and the AI model is relatively complicated, and the interaction process is specifically introduced below.
[0068] Specifically, the code change content is traversed, and for each code change content, the code change content is spliced with the first prompt sub-template in the preset prompt template to obtain the first prompt information corresponding to the code change content, and the AI model is interacted with based on the first prompt information to obtain the change content of the corresponding file. Then, based on the change content of each file, it is spliced with the second prompt sub-template in the preset prompt template to obtain the second prompt information, and the AI model is interacted with based on the second prompt information to obtain the change summary information and the file change list. Then, the code change content is traversed, and for each code change content, the AI model is interacted with based on the preset check items, and the AI model performs code review on the corresponding file to obtain the corresponding coding suggestion information.
[0069] For example, traverse all the code change content diffs, and obtain the first prompt information corresponding to each diffs by splicing them with the first prompt sub-template in the preset prompt template, and then call the AI model, and send a creation completion request to the AI model so that the AI model can summarize the changes of each file according to the first prompt information. It can also determine whether each file needs code review, and send it to the code review server in the completion content. In order to effectively manage the creation completion request, each creation completion request can be inserted into an asynchronous queue. At the same time, the number of creation completion requests in the waiting state in the asynchronous queue can be limited to ensure the processing efficiency of the asynchronous queue. In addition, when the creation completion request needs to be inserted into the asynchronous queue, the total number of traversed files can also be limited, and some files can be discarded when the total number of files is too large. The completion content fed back by the AI model can be returned as a whole through the asynchronous queue, and then the completion content can be matched by regular expressions and spliced with the second prompt sub-template in the preset prompt template to obtain the second prompt information, and the AI model can be called to enable the AI model to aggregate and summarize the change content of each file according to the second prompt information to obtain the change summary information, and deduplicate and classify the change content of each file according to the file dimension to obtain a file change list, and carry the change summary information and the file change list in the completion content to send to the code review server.
[0070] Traverse diffs, interact with the AI model according to the preset check items, and the AI model performs code review on each file corresponding to the merge request to obtain the corresponding coding suggestion information, which is carried in the completion content and sent to the code review server. The present invention can also determine the level of code problems corresponding to the merge request. Considering that the coding suggestion information is output by the AI model, the combination of its format and content may not be fixed, resulting in the inability to accurately calculate the amount of coding suggestion information in the form of coding. In the present invention, the coding suggestion information output by the AI model is spliced with the third prompt sub-template in the preset prompt template to obtain the third prompt information, and interact with the AI model based on the third prompt information. The AI model counts the number of coding suggestion information and rates it based on the number to determine the level of code problems corresponding to the merge request. For example, the code problem level can be divided into no obvious problems, attention required, and focus on.
[0071] Parse the completion content returned by the AI model and extract key information from it, such as change summary information, file change list, coding suggestion information, code problem level, etc., as code review information.
[0072] Optionally, the method may further include: counting the number of tokens consumed during the interaction with the AI model. Token is the basic unit used to measure text length and calculate model processing costs in natural language processing (NLP). When interacting with the AI model, whether asking questions, generating text, or performing other NLP tasks, a certain number of tokens are consumed. In the present invention, the tokens consumed for each call to the AI model can be counted in order to understand the processing cost consumed by the code review for this merge request.
[0073] Step S205: determine the code review result according to the code review information.
[0074] Specifically, the code review information is summarized according to a preset format, and the summarized code review information is added to the reply content corresponding to the merge request by calling the interface of the code management platform to update the reply content corresponding to the merge request to form a code review result, so that the code management platform can render and display the code review result. The timing diagram can be shown as follows: Figure 3 shown.
[0075] Figure 4 A schematic diagram showing a code review result is shown in FIG. Figure 4 As shown, the code review results include change summary information, file change list, coding suggestion information, time spent on this code review, and the number of tokens consumed.
[0076] Optionally, the relevant information of this merge request (such as merge request information, the number of code changes, the number of tokens consumed, etc.) can be stored in a database for subsequent analysis. The database may specifically include MongoDB, etc. Table 1 shows the relevant information of the merge request stored in the database and its description.
[0077] Table 1 Information and description of merge requests stored in the database
[0078]
[0079]
[0080] By using the AI-based code review method provided in this embodiment, by parsing the merge request information, it is possible to conveniently determine whether the merge request requires code review; when it is determined that code review is required, the code information to be merged corresponding to the merge request is parsed to extract the code change content; the preset prompt template records information such as preset inspection items set according to the experience records of the development team in the code review work, which helps to improve the accuracy of code review based on the AI model, and when loading the preset prompt template, the preset prompt template corresponding to the project type of the project to which the code information to be merged belongs can also be loaded, thereby realizing code review with different focuses for different project types; by splicing the code change content with the preset prompt template to obtain prompt information, interacting with the AI model based on the prompt information, and performing code review by the AI model, it can ensure that the code review has consistent review standards, realize automated and standardized code review, effectively improve the review efficiency, and can also be rated according to the number of coding suggestion information to determine the code problem level corresponding to the merge request, so that developers can have an intuitive perception of the severity of the existing code problems for their review.
[0081] Embodiment 3
[0082] Embodiment 3 of the present invention provides a non-volatile storage medium, which stores at least one executable instruction, and the executable instruction can execute the AI-based code review method in any of the above method embodiments.
[0083] The executable instructions can be specifically used to enable the processor to perform the following operations: obtain the code information to be merged corresponding to the merge request, parse the code information to be merged, and extract the code change content; splice the code change content with the preset prompt template to obtain prompt information, interact with the AI model based on the prompt information, and obtain code review information; determine the code review result based on the code review information.
[0084] In an optional embodiment, the executable instructions further cause the processor to perform the following operations: receive a notification request carrying merge request information sent by the code management platform based on the merge request of the client, parse the merge request information, and determine the status type of the merge request; if the status type is an open status, obtain the code information to be merged corresponding to the merge request from the code management platform.
[0085] In an optional embodiment, the executable instructions further cause the processor to perform the following operations: determine whether the total number of characters in the code change content is greater than the preset number of characters; if the total number of characters is greater than the preset number of characters, call the interface of the code management platform to submit the abandonment review information for the merge request; if the total number of characters is less than or equal to the preset number of characters, then splice the code change content with the preset prompt template to obtain prompt information.
[0086] In an optional implementation, the executable instructions further cause the processor to perform the following operations: according to the project type of the project to which the code information to be merged belongs, load a preset prompt template corresponding to the project type.
[0087] In an optional implementation, the code review information includes: change summary information, a file change list, and coding suggestion information.
[0088] In an optional embodiment, the executable instructions further cause the processor to perform the following operations: traverse the code change content, and for each code change content, splice the code change content with the first prompt sub-template in the preset prompt template to obtain the first prompt information corresponding to the code change content, and interact with the AI model based on the first prompt information to obtain the change content of the corresponding file; based on the change content of each file, splice it with the second prompt sub-template in the preset prompt template to obtain the second prompt information, and interact with the AI model based on the second prompt information to obtain change summary information and a file change list; traverse the code change content, and for each code change content, interact with the AI model according to preset check items, and have the AI model perform code review on the corresponding file to obtain corresponding coding suggestion information.
[0089] In an optional implementation, the file change list is obtained by classifying the changed content of each file.
[0090] In an optional implementation, the executable instructions further cause the processor to perform the following operations: determine a code issue level corresponding to the merge request.
[0091] In an optional embodiment, the executable instructions further cause the processor to perform the following operations: splicing the coding suggestion information with the third prompt sub-template in the preset prompt template to obtain third prompt information, and interacting with the AI model based on the third prompt information, and the AI model counts the number of coding suggestion information and rates them based on the number to determine the code problem level corresponding to the merge request.
[0092] In an optional embodiment, the preset prompt template records preset check items; the preset check items include one or more of the following check items: client time check items, function check items, digital calculation check items, simulation data check items, global variable check items, digital check items, and type check items.
[0093] In an optional embodiment, the executable instructions further cause the processor to perform the following operations: summarize the code review information according to a preset format, and add the summarized code review information to the reply content corresponding to the merge request by calling the interface of the code management platform to form a code review result.
[0094] In an optional embodiment, the executable instructions further cause the processor to perform the following operations: counting the number of tokens consumed during the interaction with the AI model.
[0095] Embodiment 4
[0096] Figure 5 A schematic diagram of the structure of a computing device according to Embodiment 4 of the present invention is shown. The specific embodiment of the present invention does not limit the specific implementation of the computing device.
[0097] like Figure 5 As shown, the computing device may include: a processor (processor) 502 , a communications interface (Communications Interface) 504 , a memory (memory) 506 , and a communication bus 508 .
[0098] in:
[0099] The processor 502 , the communication interface 504 , and the memory 506 communicate with each other via a communication bus 508 .
[0100] The communication interface 504 is used to communicate with other devices such as clients or other servers.
[0101] Processor 502 is used to execute program 510, and specifically can execute the relevant steps in the above-mentioned AI-based code review method embodiment.
[0102] Specifically, the program 510 may include program codes, which include computer operation instructions.
[0103] The processor 502 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention. The one or more processors included in the computing device may be processors of the same type, such as one or more CPUs; or processors of different types, such as one or more CPUs and one or more ASICs.
[0104] The memory 506 is used to store the program 510. The memory 506 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0105] Program 510 can be specifically used to enable processor 502 to perform the following operations: obtain the code information to be merged corresponding to the merge request, parse the code information to be merged, and extract the code change content; splice the code change content with the preset prompt template to obtain prompt information, interact with the AI model based on the prompt information, and obtain code review information; determine the code review result based on the code review information.
[0106] In an optional embodiment, the program 510 further enables the processor 502 to perform the following operations: receive a notification request carrying merge request information sent by the code management platform based on the merge request of the client, parse the merge request information, and determine the status type of the merge request; if the status type is an open status, obtain the code information to be merged corresponding to the merge request from the code management platform.
[0107] In an optional embodiment, the program 510 further enables the processor 502 to perform the following operations: determine whether the total number of characters in the code change content is greater than the preset number of characters; if the total number of characters is greater than the preset number of characters, call the interface of the code management platform to submit the abandonment review information for the merge request; if the total number of characters is less than or equal to the preset number of characters, then splice the code change content with the preset prompt template to obtain prompt information.
[0108] In an optional implementation, the program 510 further enables the processor 502 to perform the following operations: according to the project type of the project to which the code information to be merged belongs, load a preset prompt template corresponding to the project type.
[0109] In an optional implementation, the code review information includes: change summary information, a file change list, and coding suggestion information.
[0110] In an optional embodiment, the program 510 further enables the processor 502 to perform the following operations: traverse the code change content, and for each code change content, splice the code change content with the first prompt sub-template in the preset prompt template to obtain the first prompt information corresponding to the code change content, and interact with the AI model based on the first prompt information to obtain the change content of the corresponding file; based on the change content of each file, splice it with the second prompt sub-template in the preset prompt template to obtain the second prompt information, and interact with the AI model based on the second prompt information to obtain change summary information and a file change list; traverse the code change content, for each code change content, interact with the AI model according to the preset check items, and have the AI model perform code review on the corresponding file to obtain corresponding coding suggestion information.
[0111] In an optional implementation, the file change list is obtained by classifying the changed content of each file.
[0112] In an optional implementation, the program 510 further causes the processor 502 to perform the following operations: determine a code issue level corresponding to the merge request.
[0113] In an optional embodiment, the program 510 further enables the processor 502 to perform the following operations: splicing the coding suggestion information with the third prompt sub-template in the preset prompt template to obtain the third prompt information, and interacting with the AI model based on the third prompt information, and the AI model counts the number of coding suggestion information and rates them based on the number to determine the code problem level corresponding to the merge request.
[0114] In an optional embodiment, the preset prompt template records preset check items; the preset check items include one or more of the following check items: client time check items, function check items, digital calculation check items, simulation data check items, global variable check items, digital check items, and type check items.
[0115] In an optional embodiment, the program 510 further enables the processor 502 to perform the following operations: summarize the code review information according to a preset format, and add the summarized code review information to the reply content corresponding to the merge request by calling the interface of the code management platform to form a code review result.
[0116] In an optional embodiment, the program 510 further causes the processor 502 to perform the following operations: counting the number of tokens consumed during the interaction with the AI model.
[0117] The specific implementation of each step in program 510 can refer to the description of the corresponding steps in the above-mentioned AI-based code review embodiment, which will not be repeated here. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the device described above can refer to the corresponding process description in the above-mentioned method embodiment, which will not be repeated here.
[0118] Through the solution provided in this embodiment, the AI model is introduced into the code review process. Code review is completed through the AI model, which not only ensures that the code review has consistent review standards, realizes automated and standardized code review, avoids problems such as omissions due to negligence in manual review, but also makes full use of the semantic understanding ability of the AI model, effectively improves the review efficiency, and reduces the manpower investment in code review.
[0119] The algorithm and display provided herein are not inherently related to any particular computer, virtual system or other device. Various general purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious that the structure required for constructing such systems. In addition, the present invention is not directed to any specific programming language either. It should be understood that various programming languages can be utilized to realize the content of the present invention described herein, and the description of the above specific languages is for disclosing the best mode of the present invention.
[0120] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0121] Similarly, it should be understood that in order to streamline the present disclosure and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the intention that the claimed invention requires more features than those expressly recited in each claim. Rather, as reflected in the claims, inventive aspects lie in less than all of the features of the individual embodiments previously disclosed. Therefore, the claims that follow the detailed description are hereby expressly incorporated into the detailed description, with each claim itself serving as a separate embodiment of the present invention.
[0122] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0123] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present invention and form different embodiments. For example, in the claims, any one of the claimed embodiments may be used in any combination.
[0124] It should be noted that the above embodiments illustrate the present invention rather than limit it, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets should not be constructed as a limitation to the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention may be implemented by means of hardware including a number of different elements and by means of a suitably programmed computer. The use of the words first, second, and third, etc., does not indicate any order. These words may be interpreted as names.
[0125] The present invention discloses: A1. A code review method based on AI, comprising:
[0126] Obtaining the code information to be merged corresponding to the merge request, parsing the code information to be merged, and extracting the code change content;
[0127] The code change content is spliced with a preset prompt template to obtain prompt information, and the prompt information is interacted with the AI model to obtain code review information;
[0128] A code review result is determined based on the code review information.
[0129] A2. According to the method described in A1, the step of obtaining the to-be-merged code information corresponding to the merge request further comprises:
[0130] Receiving a notification request carrying merge request information sent by the code management platform according to the merge request of the client, parsing the merge request information, and determining a status type of the merge request;
[0131] If the status type is an open status, the to-be-merged code information corresponding to the merge request is obtained from the code management platform.
[0132] A3. According to the method described in A1, after parsing the code information to be merged and extracting the code change content, the method further includes:
[0133] Determining whether the total number of characters in the code change content is greater than a preset number of characters;
[0134] If the total number of characters is greater than the preset number of characters, calling an interface of the code management platform to submit information on abandoning review of the merge request;
[0135] The step of concatenating the code change content with a preset prompt template to obtain prompt information is as follows: if the total character amount is less than or equal to the preset character amount, concatenating the code change content with a preset prompt template to obtain prompt information.
[0136] A4. According to the method described in any one of A1-A3, before the code change content is spliced with the preset prompt template to obtain the prompt information, the method further includes:
[0137] According to the project type of the project to which the code information to be merged belongs, a preset prompt template corresponding to the project type is loaded.
[0138] A5. According to the method described in any one of A1-A4, the code review information includes: change summary information, file change list and coding suggestion information.
[0139] A6. The method according to A5, wherein the code change content is spliced with a preset prompt template to obtain prompt information, and the code review information is obtained by interacting with the AI model according to the prompt information, further comprising:
[0140] Traversing the code change content, for each code change content, splicing the code change content with the first prompt sub-template in the preset prompt template to obtain first prompt information corresponding to the code change content, and interacting with the AI model according to the first prompt information to obtain the change content of the corresponding file;
[0141] According to the changed content of each file, the second prompt sub-template in the preset prompt template is spliced to obtain second prompt information, and according to the second prompt information, the AI model is interacted to obtain change summary information and a file change list;
[0142] The code change content is traversed, and for each code change content, the AI model is interacted with according to preset inspection items, and the AI model performs code review on the corresponding file to obtain corresponding coding suggestion information.
[0143] A7. According to the method described in A6, the file change list is obtained by classifying the changed content of each file.
[0144] A8. The method according to any one of A5-A7, further comprising:
[0145] Determine the code issue level corresponding to the merge request.
[0146] A9. The method according to A8, wherein determining the code issue level corresponding to the merge request further comprises:
[0147] The coding suggestion information is spliced with the third prompt sub-template in the preset prompt template to obtain third prompt information, and the AI model is interacted with based on the third prompt information. The AI model counts the number of the coding suggestion information and rates them based on the number to determine the code problem level corresponding to the merge request.
[0148] A10. The method according to any one of A1-A9, wherein the preset prompt template records preset inspection items;
[0149] The preset inspection items include one or more of the following inspection items:
[0150] Client time check items, function check items, digital calculation check items, simulation data check items, global variable check items, digital check items, and type check items.
[0151] A11. According to any one of A1-A10, the method of determining the code review result according to the code review information further comprises:
[0152] The code review information is summarized according to a preset format, and the summarized code review information is added to the reply content corresponding to the merge request by calling the interface of the code management platform to form the code review result.
[0153] A12. The method according to any one of A1 to A11, further comprising:
[0154] Count the number of tokens consumed during the interaction with the AI model.
[0155] B13. A computing device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other through the communication bus;
[0156] The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform the following operations:
[0157] Obtaining the code information to be merged corresponding to the merge request, parsing the code information to be merged, and extracting the code change content;
[0158] The code change content is spliced with a preset prompt template to obtain prompt information, and the prompt information is interacted with the AI model to obtain code review information;
[0159] A code review result is determined based on the code review information.
[0160] B14. The computing device according to B13, wherein the executable instructions further cause the processor to perform the following operations:
[0161] Receiving a notification request carrying merge request information sent by the code management platform according to the merge request of the client, parsing the merge request information, and determining a status type of the merge request;
[0162] If the status type is an open status, the to-be-merged code information corresponding to the merge request is obtained from the code management platform.
[0163] B15. The computing device according to B13, wherein the executable instructions further cause the processor to perform the following operations:
[0164] Determining whether the total number of characters in the code change content is greater than a preset number of characters;
[0165] If the total number of characters is greater than the preset number of characters, calling an interface of the code management platform to submit information on abandoning review of the merge request;
[0166] If the total number of characters is less than or equal to the preset number of characters, the code change content is concatenated with a preset prompt template to obtain prompt information.
[0167] B16. The computing device according to any one of B13-B15, wherein the executable instructions further cause the processor to perform the following operations:
[0168] According to the project type of the project to which the code information to be merged belongs, a preset prompt template corresponding to the project type is loaded.
[0169] B17. According to the computing device described in any one of B13-B16, the code review information includes: change summary information, file change list and coding suggestion information.
[0170] B18. The computing device according to B17, wherein the executable instructions further cause the processor to perform the following operations:
[0171] Traversing the code change content, for each code change content, splicing the code change content with the first prompt sub-template in the preset prompt template to obtain first prompt information corresponding to the code change content, and interacting with the AI model according to the first prompt information to obtain the change content of the corresponding file;
[0172] According to the changed content of each file, the second prompt sub-template in the preset prompt template is spliced to obtain second prompt information, and according to the second prompt information, the AI model is interacted to obtain change summary information and a file change list;
[0173] The code change content is traversed, and for each code change content, the AI model is interacted with according to preset inspection items, and the AI model performs code review on the corresponding file to obtain corresponding coding suggestion information.
[0174] B19. According to the computing device described in B18, the file change list is obtained by classifying the changed content of each file.
[0175] B20. The computing device according to any one of B17-B19, wherein the executable instructions further cause the processor to perform the following operations:
[0176] Determine the code issue level corresponding to the merge request.
[0177] B21. The computing device according to B20, wherein the executable instructions further cause the processor to perform the following operations:
[0178] The coding suggestion information is spliced with the third prompt sub-template in the preset prompt template to obtain third prompt information, and the AI model is interacted with based on the third prompt information. The AI model counts the number of the coding suggestion information and rates them based on the number to determine the code problem level corresponding to the merge request.
[0179] B22. The computing device according to any one of B13-B21, wherein the preset prompt template records preset inspection items;
[0180] The preset inspection items include one or more of the following inspection items:
[0181] Client time check items, function check items, digital calculation check items, simulation data check items, global variable check items, digital check items, and type check items.
[0182] B23. A computing device according to any one of B13-B22, wherein the executable instructions further cause the processor to perform the following operations:
[0183] The code review information is summarized according to a preset format, and the summarized code review information is added to the reply content corresponding to the merge request by calling the interface of the code management platform to form the code review result.
[0184] B24. A computing device according to any one of B13-B23, wherein the executable instructions further cause the processor to perform the following operations:
[0185] Count the number of tokens consumed during the interaction with the AI model.
[0186] C25. A computer storage medium, wherein at least one executable instruction is stored in the storage medium, and wherein the executable instruction enables a processor to perform operations corresponding to the AI-based code review method described in any one of A1-A12.
Claims
1. An AI-based code review method, comprising: Obtaining the code information to be merged corresponding to the merge request, parsing the code information to be merged, and extracting the code change content; The code change content is spliced with a preset prompt template to obtain prompt information, and the prompt information is interacted with the AI model to obtain code review information; A code review result is determined based on the code review information.
2. According to the method of claim 1, the obtaining the to-be-merged code information corresponding to the merge request further comprises: Receiving a notification request carrying merge request information sent by the code management platform according to the merge request of the client, parsing the merge request information, and determining a status type of the merge request; If the status type is an open status, the to-be-merged code information corresponding to the merge request is obtained from the code management platform.
3. According to the method of claim 1, after parsing the code information to be merged and extracting the code change content, the method further comprises: Determining whether the total number of characters in the code change content is greater than a preset number of characters; If the total number of characters is greater than the preset number of characters, calling an interface of the code management platform to submit information on abandoning review of the merge request; The step of concatenating the code change content with a preset prompt template to obtain prompt information is as follows: if the total character amount is less than or equal to the preset character amount, concatenating the code change content with a preset prompt template to obtain prompt information.
4. According to the method according to any one of claims 1 to 3, before splicing the code change content with the preset prompt template to obtain the prompt information, the method further includes: According to the project type of the project to which the code information to be merged belongs, a preset prompt template corresponding to the project type is loaded.
5. According to the method according to any one of claims 1 to 4, the code review information includes: Change summary information, file change lists, and coding suggestion information.
6. According to the method of claim 5, the step of combining the code change content with a preset prompt template to obtain prompt information, and interacting with an AI model according to the prompt information to obtain code review information further comprises: Traversing the code change content, for each code change content, splicing the code change content with the first prompt sub-template in the preset prompt template to obtain first prompt information corresponding to the code change content, and interacting with the AI model according to the first prompt information to obtain the change content of the corresponding file; According to the changed content of each file, the second prompt sub-template in the preset prompt template is spliced to obtain second prompt information, and according to the second prompt information, the AI model is interacted to obtain change summary information and a file change list; The code change content is traversed, and for each code change content, the AI model is interacted with according to preset inspection items, and the AI model performs code review on the corresponding file to obtain corresponding coding suggestion information.
7. The method according to claim 6, wherein the file change list is obtained by classifying the changed contents of each file.
8. The method according to any one of claims 5 to 7, further comprising: Determine the code issue level corresponding to the merge request.
9. A computing device comprising: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform the following operations: Obtaining the code information to be merged corresponding to the merge request, parsing the code information to be merged, and extracting the code change content; The code change content is spliced with a preset prompt template to obtain prompt information, and the prompt information is interacted with the AI model to obtain code review information; A code review result is determined based on the code review information.
10. A computer storage medium, wherein at least one executable instruction is stored in the storage medium, and the executable instruction enables a processor to perform operations corresponding to the AI-based code review method as described in any one of claims 1-8.
