Code review method and device and medium
By combining AI code review models with encrypted channels, the problems of low quality and data security in manual code review are solved, achieving efficient and secure code review.
Patent Information
- Application Number
- CN202510772686.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-11
- Publication Date
- 2025-11-07
AI Technical Summary
Current code reviews rely on manual methods, which leads to inconsistent quality, makes it difficult to solve code quality problems, and poses data security risks.
An AI-powered code review model is used to automate the review of code changes, and data is transmitted via an encrypted channel to ensure review quality and data security.
It enables high-quality code review, improves code security, performance and standardization, increases review efficiency, and enhances data transmission security.
Smart Images

Figure CN120909591A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure belongs to the technical field of code quality management, and particularly relates to a code review method and device and medium. BACKGROUND
[0002] With the increasing complexity of software development, code review has become a key link to ensure software quality. Code review is generally reviewed by manual methods. Manual review has the following defects:
[0003] First, the review quality is affected by subjective factors of manual review, and potential code problems are easily missed.
[0004] Second, it is difficult to guarantee uniform quality standards, and the review quality is generally low.
[0005] In addition, the existing code review method is prone to data security problems. SUMMARY
[0006] The present disclosure provides a code review method, device and medium to solve the problem of low review quality caused by manual review.
[0007] According to a first aspect of the present disclosure, a code review method is provided, the method comprising: receiving code change content sent by a Gitlab platform, wherein the code change content is generated when the Gitlab platform monitors a Webhook event; parsing the code change content to obtain parsed code change content; sending the parsed code change content to a server through an encrypted channel, wherein when the server receives the parsed code change content, calling an AI to review the parsed code change content to obtain a review result; forwarding the review result to the Gitlab platform, wherein the Gitlab platform adds the review result to the Webhook event.
[0008] In some embodiments, an error report is received, wherein when the call fails, the call is re-executed; when multiple calls fail, the error report is generated and sent.
[0009] In some embodiments, the Webhook event is a code submission, a merge request, or a label creation.
[0010] In some embodiments, the review result is a review score lower than a score threshold; after the AI reviews the parsed code change content to obtain a review result, the method further comprises: when the review score is lower than the score threshold, issuing a warning, and prohibiting forwarding the review result to the Gitlab platform.
[0011] In some embodiments, the sending the parsed code change content to the server through an encrypted channel comprises: performing AES-256 encryption on the parsed code change content to obtain encrypted change code; and performing encrypted transmission on the encrypted change code through a TLS1.3 protocol.
[0012] According to a second aspect of the present disclosure, a code review device is provided, comprising: a code change content receiving module configured to receive code change content sent by a Gitlab platform, wherein the code change content is generated when the Gitlab platform monitors a Webhook event; a code change content parsing module configured to parse the code change content to obtain parsed code change content; a code change content sending module configured to send the parsed code change content to a server through an encrypted channel, wherein the server calls an AI to review the parsed code change content when the server receives the parsed code change content, and obtains a review result; and a review result forwarding module configured to forward the review result to the Gitlab platform, wherein the Gitlab platform adds the review result to the Webhook event.
[0013] In some embodiments, the device further comprises a review result prohibition forwarding module configured to issue a warning and prohibit forwarding the review result to the Gitlab platform when the review score is lower than a score threshold, wherein the review result is that the review score is lower than the score threshold.
[0014] In some embodiments, the code change content sending module comprises an encryption unit and a transmission unit; the encryption unit is configured to perform AES-256 encryption on the parsed code change content to obtain encrypted change code; and the transmission unit is configured to perform encrypted transmission on the encrypted change code through a TLS1.3 protocol.
[0015] According to a third aspect of the present disclosure, a code review device is provided, comprising: a memory; and a processor coupled to the memory, the processor being configured to execute a code review method as described above based on instructions stored in the memory.
[0016] According to a fourth aspect of the present disclosure, a computer readable storage medium is provided, having computer program instructions stored thereon, the instructions being executed by a processor to implement a code review method as described above.
[0017] Advantages of the present disclosure: digital review is realized for code review, replacing traditional manual review, and code review is performed by using a trained AI code review model, with high review quality. The code review model only reviews code change content from the dimensions of code security, code performance, code maintainability, and code standardization, with high review efficiency. When data is transmitted, the code change content is sent by using an encrypted channel, improving the security of data. BRIEF DESCRIPTION OF DRAWINGS
[0018] The accompanying drawings, which constitute a part of this specification, illustrate embodiments of the present disclosure and serve to explain the principles of the present disclosure.
[0019] The present disclosure can be understood more readily by reference to the following detailed description, when taken in connection with the accompanying drawings, and wherein:
[0020] Figure 1 is a flowchart illustrating a code review method according to some embodiments of the present disclosure.
[0021] Figure 2 is a system architecture diagram illustrating a code review system according to some embodiments of the present disclosure.
[0022] Figure 3 is a flowchart of a code review method according to some embodiments of the present disclosure based on Figure 2 a system architecture diagram.
[0023] Figure 4 is a block diagram illustrating a code review apparatus according to some embodiments of the present disclosure.
[0024] Figure 5 is a block diagram illustrating a code review apparatus according to some other embodiments of the present disclosure.
[0025] Figure 6 is a block diagram of a computer system for implementing some embodiments of the present disclosure. DETAILED DESCRIPTION
[0026] Various exemplary embodiments of the present disclosure will now be described in detail with reference to the accompanying drawings. Note that the relative arrangement, numerical expressions, and numerical values of components and steps set forth in these embodiments are not limiting to the scope of the present disclosure, unless otherwise specifically stated.
[0027] It should be understood, however, that the embodiments are merely examples and other embodiments can be made without departing from the scope of the present disclosure.
[0028] The following description of at least one example embodiment is merely illustrative in nature and is in no way limiting to the scope of the present disclosure and its applications or uses.
[0029] Techniques, methods, and apparatus known to those of ordinary skill in the relevant art(s) can not be discussed in detail herein, but should be considered as part of the specification.
[0030] In all of the compositions and methods shown and discussed herein, any specific values should be interpreted as merely exemplary, and are not intended to be limiting. Thus, other examples of the exemplary embodiments can have different values.
[0031] It should be noted that like reference numerals and letters refer to like items throughout the attached drawings, and thus, once certain items are defined in one drawing, further discussion of such items in subsequent drawings can be dispensed with.
[0032] At present, with the increasing complexity of software development, code review has become a key link to ensure software quality. Code review is generally reviewed by manual methods. Manual review has the following defects: first, the review quality is affected by the subjective factors of manual review, and potential code problems are easily missed. Second, it is difficult to guarantee uniform quality standards, and the review quality is generally low. In addition, the existing code review method is prone to data security problems.
[0033] In view of this, the present disclosure proposes a code review method, device and medium, which realizes digital review of code review, replaces traditional manual review, and the code review is reviewed by using a trained AI code review model, and the review quality is high. The code review model reviews only the code change content from the dimensions of code security, code performance, code maintainability, and code standardization, and the review efficiency is high. When data is transmitted, the code change content is sent by using an encrypted channel, and the security of the data is improved.
[0034] Figure 1 is a flowchart showing a code review method according to some embodiments of the present disclosure. As shown in Figure 1 , the code review method includes steps S110 to S140.
[0035] In step S110, the code change content sent by the Gitlab platform is received, wherein the code change content is generated when the Gitlab platform monitors a webhook event.
[0036] The function of Webhook: when GitLab listens to a preset specific event, it sends an event-related data packet to the configured external URL through an HTTP POST request.
[0037] Setting of trigger condition: the user needs to configure Webhook in the GitLab project, and specify the target URL and trigger event type.
[0038] When the event is triggered, GitLab generates a JSON-formatted data packet containing the following key information and sends it to the target URL via the request body. The basic information includes the event type, project ID, repository name, and trigger user information. It also includes commit information, code differences, and branch or tag status. Commit information includes the committer, commit time, and commit message. Code differences refer to specific file changes, such as added, modified, or deleted code lines. Branch or tag status includes the ref of the triggering branch, source branch, and target branch of the merge request.
[0039] In step S120, the code change content is parsed to obtain the parsed code change content.
[0040] In step S130, the parsed code change content is sent to the server through an encrypted channel. When the server receives the parsed code change content, it invokes AI to review the parsed code change content and obtains the review result. The AI is a code review model, and the generation method of the code review model includes: training a preset language model based on a defect code set to generate a preliminary review model; optimizing the preliminary review model through a human feedback mechanism to obtain a code review model. The method of training the preset language model based on the defect code set to generate the preliminary review model includes: performing semantic extraction on the defect code set to obtain the original semantic vector corresponding to the defect code set; training the preset language model based on the original semantic vector, the original defect type, and the defect code set to generate the preliminary review model, and outputting the preliminary review result of the defect code set. The method of optimizing the preliminary review model through the human feedback mechanism to obtain the code review model includes: evaluating and scoring the preliminary review result through the human feedback mechanism to obtain an evaluation result, wherein the evaluation and scoring dimensions include code security, code performance, code maintainability, and code standardization; and optimizing the preliminary review model according to the evaluation result using an adversarial training method to obtain the code review model.
[0041] The APP side and the Server side realize indirect communication with the external network through a special traffic forwarding mechanism. The APP side forwards the Webhook event triggered by GitLab to the Server side. The Server side interacts with the AI model through an API interface. After the AI model completes the code review, it feeds back the result to the APP side. To ensure the security and privacy of data during transmission, all transmitted data is encrypted using AES-256 and transmitted through the TLS1.3 protocol. The key is managed by a hardware security module.
[0042] In step S140, the review result is forwarded to the Gitlab platform, wherein the Gitlab platform adds the review result to the Webhook event.
[0043] As shown in Figure 2 APP side: running on the server in the intranet, responsible for interacting with GitLab, receiving Webhook events of GitLab. Due to the isolation between the intranet and the extranet, the APP side initiates a request through the intranet to communicate with the Server side. The APP side is also responsible for parsing the Webhook event triggered by GitLab, extracting the code change information and forwarding it to the Server side.
[0044] Server side: deployed on an external server, responsible for receiving requests from the APP side, calling AI models (such as code review models) for code review, and returning the review results to the APP side through a secure channel.
[0045] Intranet and extranet isolation communication mechanism: under the architecture of intranet and extranet isolation, the APP side and the Server side realize indirect communication between the intranet and the extranet through a special traffic forwarding mechanism. Specifically, the APP side forwards the Webhook event triggered by GitLab to the Server side. The Server side interacts with the AI model through the API interface, and the AI model completes the code review and feeds back the results to the APP side. In order to ensure the security and privacy of data in the transmission process, all transmitted data is encrypted using AES-256, and transmitted through TLS1.3 protocol, and the key is managed by hardware security module (HSM).
[0046] As shown in Figure 3 GitLab Webhook event triggering: the present disclosure realizes automatic triggering of the review process through the Webhook mechanism of GitLab. Configure GitLab to listen to specific events (such as code submission, merge request, tag creation), when the developer submits code or initiates a merge request on GitLab, GitLab will trigger a Webhook event to send an HTTP POST request, and send event data (including diff content of code changes) to the APP side. At the same time, all data requests and feedback are transmitted through encryption to prevent the risk of data leakage or tampering.
[0047] Parsing Git Diff: the APP side first parses the diff content of the changes, that is, the difference between the newly submitted code and the existing code.
[0048] Data Transmission: The APP side will transmit the parsed diff content to the Server side through a TLS 1.3 encrypted channel, ensuring the privacy and security of data transmission in the network. Due to the isolation between the internal and external networks, communication between the APP side and the Server side is achieved through a special traffic forwarding mechanism. Specifically, the APP side communicates with the Server side through a reverse proxy or VPN tunnel, ensuring safe and stable data transmission in a strictly isolated internal and external network environment.
[0049] Multi-threaded Concurrent Processing: To improve the efficiency of the system, both the APP side and the Server side use multi-threaded concurrent processing. When the APP side receives multiple GitLab events, it processes multiple requests through multi-threaded concurrent processing to ensure efficient delivery of multiple review requests. After receiving multiple requests from the APP side, the Server side also processes requests through multi-threaded concurrent processing and passes each request to the AI model for review.
[0050] To improve review efficiency, the system uses a thread pool and task queue mechanism, adopts a load balancing strategy, and ensures that each code review request is evenly distributed to each thread for processing, avoiding deadlocks and thread competition. The system also implements a dynamic resource allocation mechanism, allowing it to run efficiently and stably in a high-concurrency environment.
[0051] AI Large Model Review: After receiving code change information, the Server side calls the AI large model for review. Based on the received code change content, the AI large model automatically analyzes potential problems, vulnerabilities, code specification issues, performance bottlenecks, etc. through natural language processing (NLP) and code review algorithms. According to the review results, the AI large model will score based on code security, performance, maintainability, and specification (0-100 points). The weight of each dimension is set according to company development standards and industry best practices. When the score is high (above 80 points), the AI will summarize the review results briefly; when the score is low, the AI will provide detailed modification suggestions and code improvement plans.
[0052] Automatic Generation of Review Feedback and Return to GitLab: The AI large model generates comments based on the review results and automatically adds these comments to the corresponding code submission or merge request through the GitLab API. Developers and team members can view detailed review comments on the GitLab platform and make improvements based on the AI's suggestions.
[0053] Retry mechanism: In order to ensure the high availability of the system, in the face of network problems or API request failures, the present disclosure implements an automatic retry mechanism. The system automatically detects request failures and attempts to resend the request. The system uses an exponential backoff strategy, with a maximum of five retries, each with a doubling interval. If all five retries fail, the system will send an error report and terminate the current review process.
[0054] Figure 4 is a block diagram illustrating a code review apparatus according to some embodiments of the present disclosure. As shown in Figure 4 , the code review apparatus 400 includes a code change content receiving module 410, a code change content parsing module 420, a code change content sending module 430, and a review result forwarding module 440.
[0055] The code change content receiving module 410 is configured to receive code change content sent by a Gitlab platform, wherein the code change content is generated when the Gitlab platform detects a Webhook event;
[0056] The code change content parsing module 420 is configured to parse the code change content to obtain parsed code change content;
[0057] The code change content sending module 430 is configured to send the parsed code change content to a server through an encrypted channel, wherein when the server receives the parsed code change content, it calls an AI to review the parsed code change content and obtains a review result;
[0058] The review result forwarding module 440 is configured to forward the review result to the Gitlab platform, wherein the Gitlab platform adds the review result to the Webhook event.
[0059] In the apparatus of the embodiments of the present disclosure, digital review is implemented for code review, replacing traditional manual review, and the code review is reviewed by a trained AI code review model, with high review quality. The code review model reviews only the code change content from the dimensions of code security, code performance, code maintainability, and code standardization, with high review efficiency. In data transmission, the code change content is sent using an encrypted channel, improving the security of the data.
[0060] Figure 5 is a block diagram illustrating a code review apparatus according to some embodiments of the present disclosure. As shown in
[0061] As Figure 5As shown, the code review device 500 includes a memory 510; and a processor 520 coupled to the memory 510. The memory 510 is configured to store instructions for implementing embodiments of the code review method. The processor 520 is configured to execute the code review method in any of the embodiments of the present disclosure based on the instructions stored in the memory 510.
[0062] Figure 6 is a block diagram illustrating a computer system for implementing some embodiments of the present disclosure. As shown, the computer system 600 can be in the form of a general computing device. The computer system 600 includes a memory 610, a processor 620, and a bus 630 connecting different system components. Figure 6
[0063] The memory 610 can include, for example, system memory, non-volatile storage media, and the like. The system memory, for example, stores an operating system, application programs, a Boot Loader, and other programs, and the like. The system memory can include volatile storage media, such as random access memory (RAM) and / or cache memory. The non-volatile storage media, for example, stores instructions for implementing corresponding embodiments of at least one of the code review method. The non-volatile storage media includes, but is not limited to, magnetic disk storage, optical storage, flash memory, and the like.
[0064] The processor 620 can be implemented in the form of a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic device, a discrete gate or transistor, and the like discrete hardware component. Accordingly, each of the modules, such as the code change content receiving module, the code change content parsing module, the code change content sending module, and the review result forwarding module, can be implemented by a central processing unit (CPU) running instructions in the memory for performing corresponding steps, or by a dedicated circuit for performing corresponding steps.
[0065] The bus 630 can use any of a variety of bus structures. For example, the bus structure includes, but is not limited to, an industry standard architecture (ISA) bus, a microchannel architecture (MCA) bus, a peripheral component interconnect (PCI) bus.
[0066] The computer system 600 can also include an input / output interface 640, a network interface 650, a storage interface 660, and the like. These interfaces 640, 650, 660, and the memory 610 and the processor 620 can be connected through the bus 630. The input / output interface 640 can provide a connection interface for display, mouse, keyboard, and the like input / output devices. The network interface 650 provides a connection interface for various networking devices. The storage interface 660 provides a connection interface for external storage devices such as floppy disks, U disks, SD cards, and the like.
[0067] The computer readable program instructions can also be loaded onto a computer, other programmable apparatus, or other device to cause a series of operations to be performed on the computer, other programmable apparatus, or other device to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus implement the functions specified in the flowchart block or blocks.
[0068] These computer readable program instructions can be provided to a processor of a general purpose computer, special purpose computer, or other programmable apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable apparatus, create means for implementing the functions specified in the flowchart block or blocks.
[0069] These computer readable program instructions can also be stored in a computer readable storage medium that can direct a computer, a programmable apparatus, or other devices to function in a particular manner, such that the instructions stored in the computer readable storage medium produce an article of manufacture including instructions which implement the function specified in the flowchart block or blocks.
[0070] The computer program instructions can also be loaded onto a computer, other programmable apparatus, or other device to cause a series of operations to be performed on the computer, other programmable apparatus, or other device to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus implement the functions specified in the flowchart block or blocks.
[0071] The present disclosure provides a code review method, device and medium, which realizes digital review for code review, replaces traditional manual review, and uses a trained AI code review model to perform review, so that the review quality is high. The code review model only reviews code change content from the dimensions of code security, code performance, code maintainability and code standardization, so that the review efficiency is high. In data transmission, the code change content is sent by using an encrypted channel, so that the data security is improved.
[0072] Thus far, the code review method, device and medium according to the present disclosure have been described in detail. In order to avoid obscuring the concept of the present disclosure, some details known in the art are not described. Those skilled in the art can fully understand how to implement the technical solutions disclosed herein according to the above description.
[0073] Although some specific embodiments of the present disclosure have been described in detail through examples, those skilled in the art should understand that the above examples are only for illustration, and are not intended to limit the scope of the present disclosure. Those skilled in the art should understand that the above embodiments can be modified without departing from the scope and spirit of the present disclosure. The scope of the present disclosure is defined by the appended claims.
Claims
1. A code review method characterized by, The method comprises: receiving code change content sent by a Gitlab platform, wherein the code change content is generated when the Gitlab platform monitors a Webhook event; parsing the code change content to obtain parsed code change content; sending the parsed code change content to a server through an encrypted channel, wherein the server receives the parsed code change content, calls an AI to review the parsed code change content, and obtains a review result; forwarding the review result to the Gitlab platform, wherein the Gitlab platform adds the review result to the Webhook event.
2. The code review method of claim 1, wherein, receiving an error report, wherein the calling is re-executed when the calling fails, and the error report is generated and sent when the calling fails multiple times.
3. The code review method of claim 1, wherein, The Webhook event is code submission, merge request, or label creation.
4. The code review method of claim 1, wherein, The review result is a review score lower than a score threshold. After the AI reviews the parsed code change content and obtains a review result, the method further comprises: when the review score is lower than the score threshold, issuing a warning and prohibiting forwarding the review result to the Gitlab platform.
5. The code review method of claim 1, wherein, The sending of the parsed code change content to the server through the encrypted channel comprises: AES-256 encrypting the parsed code change content to obtain encrypted change code; encrypting and transmitting the encrypted change code through a TLS1.3 protocol.
6. A code review apparatus characterized by comprising: The method comprises: a code change content receiving module configured to receive code change content sent by a Gitlab platform, wherein the code change content is generated when the Gitlab platform monitors a Webhook event; a code change content parsing module configured to parse the code change content to obtain parsed code change content; a code change content sending module configured to send the parsed code change content to a server through an encrypted channel, wherein the server receives the parsed code change content, calls an AI to review the parsed code change content, and obtains a review result; a review result forwarding module configured to forward the review result to the Gitlab platform, wherein the Gitlab platform adds the review result to the Webhook event.
7. The code review apparatus of claim 6, wherein, The method further comprises a review result prohibition forwarding module configured to issue a warning and prohibit forwarding the review result to the Gitlab platform when the review score is lower than a score threshold, wherein the review result is a review score lower than a score threshold.
8. The code review apparatus of claim 6, wherein, The code change content sending module comprises an encryption unit and a transmission unit; the encryption unit is configured to AES-256 encrypt the parsed code change content to obtain encrypted change code; the transmission unit is configured to encrypt and transmit the encrypted change code through a TLS1.3 protocol.
9. A code review apparatus, characterized by, The method comprises: a memory; and a processor coupled to the memory, the processor configured to perform the method of code review according to any one of claims 1 to 5 based on instructions stored in the memory.
10. A computer-readable storage medium, characterized in that, A computer program product having stored thereon computer program instructions which, when executed by a processor, implement the method of code review according to any one of claims 1 to 5. A computer program product having stored thereon computer program instructions which, when executed by a processor, implement the method of code review according to any one of claims 1 to 5.