Code processing method and device, computer equipment and storage medium

By receiving event information from code hosting platforms, extracting code discrepancies, identifying key features, querying document fragments related to code review, generating multi-dimensional prompts, and using target models for code review, this technology solves the problem of low accuracy in existing code review methods and achieves efficient and accurate automated code review.

CN121658347APending Publication Date: 2026-03-13SHENZHEN YUNFAN ACCELERATION TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-05
Publication Date
2026-03-13

AI Technical Summary

Technical Problem

Existing technologies have low accuracy in code review in MR/PR scenarios. Traditional manual review methods are costly, prone to missing defects, and lack standardized practices. Existing tools cannot unify team standards or identify business logic vulnerabilities.

Method used

By receiving event information from code hosting platforms, extracting code discrepancies, identifying key features, querying document fragments related to code review, generating multi-dimensional prompts, and using a trained target model for code review.

Benefits of technology

It improves the comprehensiveness and accuracy of code reviews, ensures that review results are consistent with the specific context of the project, reduces human intervention and errors, and improves code quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121658347A_ABST
    Figure CN121658347A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to a code processing method and device, computer equipment and a storage medium, and the method comprises the steps: receiving event information sent by a code hosting platform when a change request event for a code is detected; obtaining difference content of a code corresponding to the change request event according to the event information; key features of the codes are extracted according to the difference content; querying a document fragment associated with the change request event from a database according to the key features; and generating prompt words according to the document segments, so that the trained target model performs processing operation on the codes according to the prompt words to complete code examination. Therefore, by obtaining the event information of the code change event, the difference content of the code before and after change can be accurately determined, and after the document fragment for review is obtained according to the difference content to generate the multi-dimensional cue word, the model performs code review operation, so that the comprehensiveness and accuracy of code review are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a code processing method, apparatus, computer device and storage medium. Background Technology

[0002] In the field of modern software development, the pace of software project iteration continues to accelerate, and the number of code merge requests (MR / Pull Request, PR) has increased significantly. The traditional manual code review model faces challenges such as high labor costs, easy omission of defects, and subjective and inconsistent review standards.

[0003] To address this issue, the following solutions can be considered: Local Integrated Development Environment (IDE) plugins require manual installation by developers and can only analyze local code snapshots, failing to unify team review standards or cover MR / PR level differences; Software as a Service (SaaS) static scanning tools require full repository cloning with fixed review rules and cannot identify business logic vulnerabilities; existing AI-powered code review tools lack customizable rules and cannot integrate with the latest project technical documentation, resulting in poor adaptability. All of these solutions contribute to low code review accuracy.

[0004] In summary, the most pressing technical problem to be solved is how to improve the accuracy of code review in MR / PR scenarios. Summary of the Invention

[0005] In view of this, in order to solve the above-mentioned technical problems or some of the technical problems, the embodiments of the present invention provide a code processing method, apparatus, computer equipment and storage medium.

[0006] In a first aspect, embodiments of the present invention provide a code processing method, including: When a change request event for code is detected, the system receives event information sent by the code hosting platform. Based on the event information, obtain the difference content of the code corresponding to the change request event; Extract the key features of the code based on the differences; Based on the key features, the database is used to query document fragments associated with the change request event, and the database stores multiple document fragments associated with code review; Prompt words are generated based on the document fragments, so that the trained target model can process the code according to the prompt words to complete the code review.

[0007] In one possible implementation, receiving event information sent by the code hosting platform includes: Obtain the access token for the code hosting platform; After the access token is used to verify the permissions, the source branch of the code change, the target branch of the code change, the unique identifier of the source version of the code change, and the unique identifier of the target version of the code change are sent by the code hosting platform as the event information. When the code hosting platform detects the change request event, it triggers the sending of the event information to the target address.

[0008] In one possible implementation, before detecting a change request event for the code, the method further includes: Obtain the relevant documents associated with code review for different project types; The document is converted to plain text and then segmented to obtain multiple text blocks; Convert the multiple text blocks into vectors; The vector and its corresponding original text and metadata are stored as document fragments in the database.

[0009] In one possible implementation, obtaining the difference content of the code corresponding to the change request event based on the event information includes: Call the application programming interface provided by the code hosting platform to communicate with the code hosting platform; Based on the source version unique identifier and the target version unique identifier, obtain the differences between the two code versions before and after the change request event from the code hosting platform. The differences include at least one of the following: newly added code content, deleted code content, and modified code content.

[0010] In one possible implementation, extracting key features of the code based on the differences includes: The differences are parsed and processed, and the programming language type used in the differences is identified by combining the file extension information, code syntax structure, and keyword features. Based on the syntax rules and code structure characteristics corresponding to the programming language type, the key features are extracted from the differences. The key features include at least one of the following: information about imported libraries, defined function names, defined class names, and application interface information called in the code.

[0011] In one possible implementation, querying the database for document fragments associated with the change request event based on the key features includes: The key features are converted into query vectors so that the feature space of the query vectors is consistent with the vector feature space of the document fragments stored in the database; Based on the query vector, a similarity matching operation is performed on the document fragments in the database, which is used as the semantic relevance. The target number of document fragments with a semantic relevance greater than a preset threshold are selected as the associated document fragments.

[0012] In one possible implementation, generating prompt words based on the document fragment includes: The system sets system role information, review tasks, review content, and uses the document fragments as contextual knowledge information for the target model. The prompt words are generated based on the role information, the review task, the review content, and the contextual knowledge information.

[0013] Secondly, embodiments of the present invention provide a code processing apparatus, comprising: The receiving module is used to receive event information sent by the code hosting platform when a change request event for code is detected. The acquisition module is used to acquire the difference content of the code corresponding to the change request event based on the event information; The extraction module is used to extract key features of the code based on the differences. The query module is used to query document fragments associated with the change request event from the database based on the key features. The database stores multiple document fragments associated with code review. The generation module is used to generate prompt words based on the document fragment, so that the trained target model can process the code according to the prompt words to complete the code review.

[0014] Thirdly, embodiments of the present invention provide a computer device, including: a processor and a memory, wherein the processor is configured to execute a code processing program stored in the memory to implement the code processing method described in any one of the first aspects above.

[0015] Fourthly, embodiments of the present invention provide a storage medium storing one or more programs, which can be executed by one or more processors to implement the code processing method described in any one of the first aspects.

[0016] The code processing method provided in this invention involves receiving event information from a code hosting platform when a code change request event is detected; obtaining the differences in the code corresponding to the change request event based on the event information; extracting key features of the code based on the differences; querying a database containing multiple document fragments associated with the change request event based on the key features; and generating prompts based on the document fragments, enabling a trained target model to process the code according to the prompts, thereby completing the code review. Thus, by obtaining event information of code change events, accurately determining the differences in the code before and after the change, and then generating multi-dimensional prompts based on the differences to enable the model to perform code review operations, the comprehensiveness and accuracy of code review are improved. Attached Figure Description

[0017] Figure 1 A flowchart illustrating a code processing method provided in an embodiment of the present invention; Figure 2 A flowchart illustrating another code processing method provided in an embodiment of the present invention; Figure 3 A flowchart illustrating another code processing method provided in an embodiment of the present invention; Figure 4 This is a schematic diagram of the structure of a code processing device provided in an embodiment of the present invention; Figure 5 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present invention. Detailed Implementation

[0018] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0019] To facilitate understanding of the embodiments of the present invention, further explanations and descriptions will be provided below with reference to the accompanying drawings and specific embodiments. These embodiments do not constitute a limitation on the embodiments of the present invention.

[0020] Figure 1 This is a flowchart illustrating a code processing method provided in an embodiment of the present invention, as shown below. Figure 1 As shown, the method specifically includes: S11. When a change request event for code is detected, receive event information sent by the code hosting platform.

[0021] The code processing method provided in this invention is applied to computer devices, including but not limited to servers, desktop computers, and tablets. It is suitable for scenarios where a user initiates a Mod Request / Release (MR / PR) on a code hosting platform (e.g., GitLab), quickly triggering automated review. Specifically, in this embodiment, the computer device can be a pre-built system for code review. This system communicates with the code hosting platform. By acquiring event information of code change events, the system accurately determines the differences between the code before and after the change. Based on these differences, it generates multi-dimensional prompts from document fragments for review, enabling the model to perform code review operations, thus improving the comprehensiveness and accuracy of code review.

[0022] In this embodiment, the code hosting platform is an online service used to store, manage, and collaboratively develop software source code. It provides functions such as code repositories, branch management, merge requests, and issue tracking. A code change request event refers to the user's action of initiating a merge request (MR) or pull request (PR) on the code hosting platform, along with related operations (e.g., a formal request to merge changes from one branch into another), used to trigger subsequent automated review steps. Event information (event payload) is structured data generated by the code hosting platform, containing core information about the change request event, which may include, but is not limited to: source branch, target branch, unique identifier of the source version (source commit ID), unique identifier of the target version (target commit ID), request creator, and event time, used by the system to locate the specific scope of code changes.

[0023] Specifically, when a user creates or updates a code change request on the code hosting platform, the platform automatically identifies the code change request event and generates structured data containing detailed information about the change request event as event information. The code hosting platform can send the event information to a pre-configured system receiving address via HTTP / HTTPS protocol, and the system simultaneously receives the event information.

[0024] S12. Obtain the difference content of the code corresponding to the change request event based on the event information.

[0025] In this embodiment, core location information is extracted from the received event information, including but not limited to: source branch name, target branch name, source commit ID, and target commit ID. The system calls the difference comparison interface provided by the code hosting platform (e.g., GitLab's Compare API) and passes the extracted commit ID or branch information as parameters to the interface. Based on the passed parameters, the platform interface automatically calculates and returns the code differences between the two versions. The differences include the changed filenames and paths; specific line changes in each file (the content and location of added, deleted, and modified lines); and metadata such as the number of changed lines. This allows for precise identification of the version range of the code change using the two commit IDs, ensuring that the obtained difference content corresponds to the specific modifications made in the change request.

[0026] Furthermore, the system parses the raw difference content (diff data) returned by the interface and converts it into a unified structured format (e.g., grouped by file, marking the change type of each line) as standardized input for subsequent feature extraction and review.

[0027] S13. Extract key features of the code based on the differences in content.

[0028] In this embodiment, the key feature refers to the feature extracted from the code difference content corresponding to the code change request, based on the programming language type, syntax rules and structural characteristics of the code, which can be used to associate relevant document fragments for code review. This feature can be converted into a query vector consistent with the feature space of document fragment vectors in the database, and then reference knowledge suitable for the current code change review can be obtained through semantic relevance matching.

[0029] Specifically, structural features are extracted from the differences (new and modified lines of code) as key features, which may include, but are not limited to: imported libraries (e.g., import pandas), new or modified function names (e.g., def calculate_price()), class names (e.g., class UserService), variable names, APIs called, control flow statements (e.g., the logical structure of loops and conditional statements), business terms mentioned in comments, constant definitions, etc.

[0030] Optionally, meaningless formatting changes (such as spaces and line breaks) can be filtered out, and the extracted key features can be categorized by type (e.g., "library dependencies", "function definitions", "API calls") and converted into a unified text or structured data format as the basic elements for subsequent data retrieval.

[0031] S14. Based on key characteristics, query the database for document fragments associated with the change request event. The database stores multiple document fragments associated with code review.

[0032] In this embodiment, document fragments are semantically independent subunits extracted from complete documents (e.g., an API usage manual or a coding specification clause). A semantic coding model consistent with that used for document fragments in the database is employed to convert extracted key features into query vectors, thus quantifying the semantic information of the features. In a vector database storing code review-related document fragments, the cosine similarity (or Euclidean distance) between the query vector and the pre-stored document fragment vectors in the database is calculated to measure the semantic association between them. The fragments are then sorted from highest to lowest similarity score, and the top K (e.g., K=5) document fragments with the highest semantic match to the current key feature are selected. These fragments are typically extracted from project technical documents, coding specifications, API manuals, historical review cases, etc., and converted into vectors for storage in the database.

[0033] The selected document fragments are integrated according to their relevance weights and used as contextual knowledge related to the current code change request, providing a basis for generating review prompts in the future.

[0034] S15. Generate prompt words based on document fragments so that the trained target model can process the code according to the prompt words to complete the code review.

[0035] In this embodiment, the model's role is defined at the beginning of the prompt, and the review criteria are clearly defined to constrain the model's output direction. Retrieved related document fragments are sorted by relevance and embedded as background knowledge into the prompt, ensuring the model can review within the specific context of the project, avoiding generalized judgments detached from the business scenario. The review objective is clearly described (e.g., "Analyze the following code changes, identify bugs, security vulnerabilities, performance issues, and code smells, and provide specific improvement suggestions"), while specifying the output format (e.g., "Structured presentation by 'problem type + location + description + suggestion'") to improve the usability of the review results. The acquired code differences are grouped by file and used as prompts, ensuring the model focuses on the specific lines of code involved in the change, avoiding ineffective analysis of irrelevant code. The above components are integrated to form a complete prompt, which is sent to the trained target model (e.g., a large language model) via an interface, triggering the model to perform inference based on the prompt and generate targeted code review results.

[0036] The code processing method provided in this invention involves receiving event information from a code hosting platform when a code change request event is detected; obtaining the differences in the code corresponding to the change request event based on the event information; extracting key features of the code based on the differences; querying a database containing multiple document fragments associated with the change request event based on the key features; and generating prompts based on the document fragments, enabling a trained target model to process the code according to the prompts, thereby completing the code review. Thus, by obtaining event information of code change events, accurately determining the differences in the code before and after the change, and then generating multi-dimensional prompts based on the differences to enable the model to perform code review operations, the comprehensiveness and accuracy of code review are improved.

[0037] Figure 2 A flowchart illustrating another code processing method provided in an embodiment of the present invention is shown below. Figure 2 As shown, the method specifically includes: S21. Obtain the documents associated with code review corresponding to the code of different project types; convert the documents into plain text and perform segmentation to obtain multiple text blocks; convert the multiple text blocks into vectors; store the vectors and the corresponding original text and metadata as document fragments in the database.

[0038] In this embodiment, documents related to code review are collected for different project types (e.g., front-end projects, back-end services, mobile applications, etc.), including but not limited to project coding standards, API reference manuals, architecture design documents, security compliance guidelines, and summaries of historical issues. The collected documents (formats may include PDF, Word, etc.) are converted to plain text and then segmented into multiple independent text blocks (e.g., a function usage description, a coding rule) based on semantic relevance (e.g., chapters, paragraph topics). Each text block can contain a single knowledge point. A semantic encoding model is used to convert each text block into a high-dimensional vector, quantifying the semantic information of the text into computable vector features, ensuring that subsequent semantic-level association retrieval can be achieved through vector similarity matching.

[0039] Furthermore, the vector data, the corresponding original text block content, and metadata (e.g., document source, project type, update time) are bound and stored in the database to form a structured code review knowledge base, supporting efficient semantic retrieval and management. Thus, through standardized document processing and storage processes, a structured knowledge base matching the project type is constructed, solving the problem of inefficient use of scattered documents and providing a high-quality data foundation for accurate knowledge matching for specific code changes.

[0040] S22. When a change request event for code is detected, obtain the access token of the code hosting platform; after passing the permission verification based on the access token, receive the source branch of the code change, the target branch of the code change, the unique identifier of the source version of the code change, and the unique identifier of the target version of the code change sent by the code hosting platform as event information. When the code hosting platform detects a change request event, it triggers the sending of event information to the target address.

[0041] In this embodiment, during the initial configuration phase, the user generates and provides an access token with specific permissions (e.g., reading code, obtaining MR / PR information) through the code hosting platform. This token serves as the identity credential for the system to access platform resources and is only temporarily held by the system after the user authorizes it.

[0042] Users pre-configure the system's target receiving address as a Webhook endpoint in the project settings of the code hosting platform and bind code change request events as trigger conditions. When the platform detects a change request event, it automatically initiates a verification process: verifying the request using a preset access token or key to confirm that it is an authorized system; and simultaneously verifying whether the access token held by the system has the permission to read the project's change information.

[0043] After authorization is granted, the code hosting platform will proactively send the event information (including core data such as the source branch, target branch, source version unique identifier (source commit ID), and target version unique identifier (target commit ID) of the code change) to the target address of the system via HTTP / HTTPS protocol, thus completing the secure transmission of the change request event.

[0044] The source and target versions are unique identifiers for code commits. These are hash values ​​used in the Git version control system to mark specific versions of the code, accurately locating the code versions before and after the change and ensuring the accuracy of subsequent comparisons. The target address is a dedicated URL endpoint used by the system to receive Webhook events. It needs to be pre-configured in the code hosting platform and is the designated location for receiving event information pushed by the platform.

[0045] S23. Call the application programming interface provided by the code hosting platform for communication connection with the code hosting platform; based on the unique identifier of the source version and the unique identifier of the target version, obtain the difference content between the two code versions before and after the change request event from the code hosting platform. The difference content includes at least one of the following: newly added code content, deleted code content and modified code content.

[0046] In this embodiment, the system integrates the application programming interface (API) provided by the code hosting platform, establishing a communication connection with the platform through a standardized interface protocol. Before the call, the system uses a user-authorized access token for authentication to ensure permission to access the target repository's code version information. The system uses the unique source and target version identifiers extracted from the event information as core parameters to call the version comparison interface provided by the platform. The platform interface automatically calculates and returns the complete diff between the two versions based on the two unique version identifiers, which may include, but is not limited to, added lines of code, deleted lines of code, modified lines of code, and changed file paths and filenames. The system performs structured parsing of the returned raw diff content, categorizes and organizes it by file, forming a standardized format that facilitates subsequent feature extraction.

[0047] By directly calling the platform API and obtaining the differences based on precise version identifiers, the accuracy of the scope of code changes is ensured, while avoiding the security risks of full-cloning the repository.

[0048] S24. Analyze the differences and combine the file extension information of the code file with the code syntax structure and keyword features to identify the programming language type used in the differences. Based on the syntax rules and code structure characteristics corresponding to the programming language type, extract key features from the differences. The key features include at least one of the following: information on the imported program libraries, the names of defined functions, the names of defined classes, and the information on the application interface called in the code.

[0049] In this embodiment, for the code files associated with the differing content, the language type is first initially determined by the file extension, and then a second verification is performed by combining the code syntax structure and feature keywords to finally determine the programming language type to which the differing content belongs, providing a grammatical rule basis for subsequent feature extraction.

[0050] Based on the identified programming language syntax rules and code structure characteristics, key features are extracted from the differences, including: parsing import statements to extract library information, identifying definition statements to extract function names and class names, analyzing call statements to extract application interface information, and using the extracted content as key features.

[0051] S25. Convert key features into query vectors so that the feature space of the query vectors is consistent with the vector feature space of the document fragments stored in the database; based on the query vectors, perform similarity matching operations on the document fragments in the database as semantic relevance; filter out the target number of document fragments with semantic relevance greater than a preset threshold as associated document fragments.

[0052] In this embodiment, a pre-trained model consistent with that used to generate document fragment vectors in the database is employed to convert the extracted key code features into high-dimensional query vectors. By unifying model parameters and vector dimensions, it is ensured that the query vectors and document fragment vectors in the database reside in the same feature space.

[0053] Based on the query vectors corresponding to key features, cosine similarity is calculated on the document fragment vectors stored in the database to measure the degree of semantic relevance. A preset threshold (e.g., 0.7) and a target number (e.g., top 10) are set, and document fragments with similarity scores exceeding the threshold and ranking at the top are selected as reference knowledge with the highest semantic relevance to the current code change. This can improve the accuracy and relevance of the review process.

[0054] S26. Set system role information, review tasks, and review content for the target model, and use document fragments as contextual knowledge information for the target model; generate prompt words based on the role information, review tasks, review content, and contextual knowledge information. This allows the trained target model to process the code according to the prompt words, thus completing the code review.

[0055] In this embodiment, system role information is first defined to clarify the model's positioning (e.g., "You are a code review expert proficient in programming languages, and you must strictly follow project specifications, focusing on code quality, security, and business adaptability"). Then, the review tasks are clarified (e.g., "Analyze this code change, identify bugs, security risks, and non-compliant code writing, and provide specific modification suggestions") and the review content (e.g., the obtained code differences are clearly presented according to file paths).

[0056] The selected related document fragments (e.g., project coding style rules, API usage instructions) are sorted by semantic relevance and used as contextual knowledge embedding prompts. Reference document labels can be added to ensure that project-specific rules can be combined during model review.

[0057] All information is integrated in a logical order (e.g., "role information → review task → contextual knowledge → review content") to form a clear and complete prompt, avoiding information confusion and guiding the model to efficiently output accurate review results.

[0058] Furthermore, the target model understands code syntax and logic, and uses document snippets to pinpoint problems (such as API usage errors or missing security checks); prioritizes problems, generates specific modification suggestions and associated supporting evidence; and outputs results in a structured format, thus automating the review of code changes. Finally, a review report is generated.

[0059] As an example, such as Figure 3The diagram shown is a flowchart illustrating another code processing method provided in an embodiment of the present invention. The method specifically includes: First, a knowledge base is built (Retrieval-Augmented Generation (RAG) preprocessing), an offline preparation process that provides data support for RAG: 1. Document Processing: Provides a management portal, allowing users to upload project technical documents, API references, coding standards, design documents, etc. (supporting multiple formats such as PDF, Word, and Markdown), and converts them into plain text. 2. Text Segmentation: Uses a text segmenter to divide long documents into appropriately sized text chunks to ensure retrieval accuracy. 3. Vectorization: Uses a semantic model (such as SentenceTransformer) to convert each text chunk into a high-dimensional vector (Embedding). 4. Storage: Stores the vectors and their corresponding original text and metadata (such as source documents) in a vector database (ChromaDB).

[0060] The specific automated code review process includes: Automated workflow triggered by code hosting platform events: 1. Access and triggering: The user configures a webhook on the code hosting platform (such as GitLab), pointing it to the backend service address of this system, and sets the trigger event to Merge RequestCreation. The user enters the platform's access token through the system interface, authorizing this system to access the repository and submit review comments with sufficient permissions.

[0061] 2. Code Reception and Difference Extraction: When a user creates a MapReduce (MR), the platform sends an event payload to this system via a webhook. This payload contains key information such as the source branch, target branch, source commit ID, and target commit ID. The system then uses an API provided by the platform (such as GitLab's Compare API) to retrieve detailed diff information for all files in this MR based on the two commit IDs.

[0062] 3. Language Detection and Feature Extraction: The system analyzes the diff content and automatically detects the programming language (such as Python) based on the file extension and code content. It extracts key features from the code, such as imported libraries (e.g., pandas), function names, class names, and API calls.

[0063] 4. Knowledge Retrieval: Extracted features (such as library names and API names) are used as query keywords and converted into query vectors. A similarity search (semantic retrieval) is performed in the vector database (ChromaDB) to find the K document fragments most relevant to the current code change.

[0064] 5. RAG Enhanced Review: The system constructs a powerful prompt, which typically includes the following parts: System Role: "You are a senior code review expert, focusing on code quality, security, and performance." Contextual Knowledge: Relevant document snippets retrieved in the previous step are injected as background knowledge. Review Task: "Please review the following code changes, point out bugs, security issues, and performance risks, and provide improvement suggestions. Please refer to the provided technical documentation." Code Content: The obtained diff code is used as the main review content. The assembled prompt is sent to a large language model (such as GPT-4, DeepSeek, etc.).

[0065] 6. Result Generation and Push: Based on the injected knowledge and code changes, the large model generates a structured, high-quality review report. The system submits the review report as comments to the corresponding MR / PR via the code hosting platform's API, completing the closed loop.

[0066] Alternatively, one could not solely rely on RAG, but instead first fine-tune the basic model using project-related technical documentation to obtain a domain-specific model, and then use RAG to inject more real-time, fine-grained knowledge into it. RAG provides the latest information. Combining both methods may yield better results, but it is more costly and technically complex.

[0067] The code processing method provided in this invention, in the application of the large language model in the field of code review, allows code hosting platforms to automatically generate code review implementation mechanisms by only filling in two input boxes (configuring access_token and webhooks), reducing integration costs while ensuring code security. By introducing the RAG architecture and a built-in updatable knowledge base, the knowledge lag problem of traditional models is solved, resulting in more accurate, timely, and context-aware review suggestions.

[0068] Figure 4 This is a schematic diagram of the structure of a code processing device provided in an embodiment of the present invention, as shown below. Figure 4 As shown, the device specifically includes: The receiving module 41 is used to receive event information sent by the code hosting platform when a change request event for code is detected; The acquisition module 42 is used to acquire the difference content of the code corresponding to the change request event based on the event information; Extraction module 43 is used to extract key features of the code based on the differences. The query module 44 is used to query a document fragment associated with the change request event from a database based on the key features. The database stores multiple document fragments associated with code review. The generation module 45 is used to generate prompt words based on the document fragment, so that the trained target model can process the code according to the prompt words to complete the code review.

[0069] In one possible implementation, the receiving module is specifically used to obtain the access token of the code hosting platform; After the access token is used to verify the permissions, the source branch of the code change, the target branch of the code change, the unique identifier of the source version of the code change, and the unique identifier of the target version of the code change are sent by the code hosting platform as the event information. When the code hosting platform detects the change request event, it triggers the sending of the event information to the target address.

[0070] In one possible implementation, the acquisition module is further configured to acquire documents associated with code review corresponding to code of different project types; The document is converted to plain text and then segmented to obtain multiple text blocks; Convert the multiple text blocks into vectors; The vector and its corresponding original text and metadata are stored as document fragments in the database.

[0071] In one possible implementation, the acquisition module is specifically used to call the application programming interface provided by the code hosting platform for communicating with the code hosting platform; Based on the source version unique identifier and the target version unique identifier, obtain the differences between the two code versions before and after the change request event from the code hosting platform. The differences include at least one of the following: newly added code content, deleted code content, and modified code content.

[0072] In one possible implementation, the extraction module is specifically used to parse the difference content and, in combination with the file extension information, code syntax structure, and keyword features, identify the programming language type used in the difference content. Based on the syntax rules and code structure characteristics corresponding to the programming language type, the key features are extracted from the differences. The key features include at least one of the following: information about imported libraries, defined function names, defined class names, and application interface information called in the code.

[0073] In one possible implementation, the query module is specifically used to convert the key features into query vectors so that the feature space of the query vectors is consistent with the vector feature space of the document fragments stored in the database; Based on the query vector, a similarity matching operation is performed on the document fragments in the database, which is used as the semantic relevance. The target number of document fragments with a semantic relevance greater than a preset threshold are selected as the associated document fragments.

[0074] In one possible implementation, the generation module is specifically used to set system role information, review tasks, and review content for the target model, and to use the document fragment as contextual knowledge information for the target model. The prompt words are generated based on the role information, the review task, the review content, and the contextual knowledge information.

[0075] The code processing device provided in this embodiment can be as follows: Figure 4 The apparatus shown can perform, as Figure 1-3 The code processes all steps of the method, thereby achieving... Figure 1-3 For details on the technical effects of the code processing method shown, please refer to [link / reference]. Figure 1-3 The relevant descriptions are presented concisely and will not be elaborated upon here.

[0076] Figure 5 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present invention. Figure 5 The computer device 500 shown includes at least one processor 501, a memory 502, at least one network interface 504, and other user interfaces 503. The various components in the computer device 500 are coupled together via a bus system 505. It is understood that the bus system 505 is used to implement communication between these components. In addition to a data bus, the bus system 505 also includes a power bus, a control bus, and a status signal bus. However, for clarity, ... Figure 5 The general designated all buses as Bus System 505.

[0077] The user interface 503 may include a display, keyboard, or clicking device (e.g., mouse, trackball, touchpad, or touchscreen).

[0078] It is understood that the memory 502 in the embodiments of the present invention can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), Synchronous DRAM (SDRAM), Double Data Rate Synchronous DRAM (DDRSDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), and Direct Rambus RAM (DRRAM). The memory 502 described herein is intended to include, but is not limited to, these and any other suitable types of memory.

[0079] In some implementations, memory 502 stores elements, executable units or data structures, or subsets thereof, or extended sets thereof: operating system 5021 and application program 5022.

[0080] The operating system 5021 includes various system programs, such as the framework layer, core library layer, and driver layer, used to implement various basic business functions and handle hardware-based tasks. The application program 5022 includes various applications, such as a media player and a browser, used to implement various application functions. The program implementing the method of this embodiment can be included in the application program 5022.

[0081] In this embodiment of the invention, by calling the program or instructions stored in memory 502, specifically the program or instructions stored in application program 5022, processor 501 executes the method steps provided in each method embodiment, including, for example: When a change request event for code is detected, the system receives event information sent by the code hosting platform. Based on the event information, obtain the difference content of the code corresponding to the change request event; Extract the key features of the code based on the differences; Based on the key features, the database is used to query document fragments associated with the change request event, and the database stores multiple document fragments associated with code review; Prompt words are generated based on the document fragments, so that the trained target model can process the code according to the prompt words to complete the code review.

[0082] The methods disclosed in the above embodiments of the present invention can be applied to or implemented by processor 501. Processor 501 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the integrated logic circuit of the hardware in processor 501 or by instructions in the form of software. The processor 501 may be 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 devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present invention. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of the present invention can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software units in the decoding processor. The software units may be located in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. The storage medium is located in memory 502. Processor 501 reads the information in memory 502 and, in conjunction with its hardware, completes the steps of the above method.

[0083] It is understood that the embodiments described herein can be implemented in hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit can be implemented in one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), general-purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions described herein, or combinations thereof.

[0084] For software implementation, the techniques described herein can be implemented by units that perform the functions described herein. The software code can be stored in memory and executed by a processor. The memory can be implemented in the processor or external to the processor.

[0085] The computer device provided in this embodiment may be as follows: Figure 5 The computer device shown can perform, for example Figure 1-3 The code processes all steps of the method, thereby achieving... Figure 1-3 For details on the technical effects of the code processing method shown, please refer to [link / reference]. Figure 1-3 The relevant descriptions are presented concisely and will not be elaborated upon here.

[0086] This invention also provides a storage medium (computer-readable storage medium). This storage medium stores one or more programs. The storage medium may include volatile memory, such as random access memory; it may also include non-volatile memory, such as read-only memory, flash memory, hard disk, or solid-state drive; and it may also include combinations of the above types of memory.

[0087] When one or more programs in the storage medium can be executed by one or more processors to implement the code processing method described above that is executed on the device side.

[0088] The processor is used to execute code processing programs stored in memory to implement the following steps of a code processing method executed on the device side: When a change request event for code is detected, the system receives event information sent by the code hosting platform. Based on the event information, obtain the difference content of the code corresponding to the change request event; Extract the key features of the code based on the differences; Based on the key features, the database is used to query document fragments associated with the change request event, and the database stores multiple document fragments associated with code review; Prompt words are generated based on the document fragments, so that the trained target model can process the code according to the prompt words to complete the code review.

[0089] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0090] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented in hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0091] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A code processing method, characterized in that, include: When a change request event for code is detected, the system receives event information sent by the code hosting platform. Based on the event information, obtain the difference content of the code corresponding to the change request event; Extract the key features of the code based on the differences; Based on the key features, the database is used to query document fragments associated with the change request event, and the database stores multiple document fragments associated with code review; Prompt words are generated based on the document fragments, so that the trained target model can process the code according to the prompt words to complete the code review.

2. The method according to claim 1, characterized in that, The event information received from the code hosting platform includes: Obtain the access token for the code hosting platform; After the access token is used to verify the permissions, the source branch of the code change, the target branch of the code change, the unique identifier of the source version of the code change, and the unique identifier of the target version of the code change are sent by the code hosting platform as the event information. When the code hosting platform detects the change request event, it triggers the sending of the event information to the target address.

3. The method according to claim 1, characterized in that, Before detecting a change request event for the code, the method further includes: Obtain the relevant documents associated with code review for different project types; The document is converted to plain text and then segmented to obtain multiple text blocks; Convert the multiple text blocks into vectors; The vector and its corresponding original text and metadata are stored as document fragments in the database.

4. The method according to claim 2, characterized in that, The step of obtaining the difference content of the code corresponding to the change request event based on the event information includes: Call the application programming interface provided by the code hosting platform to communicate with the code hosting platform; Based on the source version unique identifier and the target version unique identifier, obtain the differences between the two code versions before and after the change request event from the code hosting platform. The differences include at least one of the following: newly added code content, deleted code content, and modified code content.

5. The method according to claim 1, characterized in that, The step of extracting key features of the code based on the differences includes: The differences are parsed and processed, and the programming language type used in the differences is identified by combining the file extension information, code syntax structure, and keyword features. Based on the syntax rules and code structure characteristics corresponding to the programming language type, the key features are extracted from the differences. The key features include at least one of the following: information about imported libraries, defined function names, defined class names, and application interface information called in the code.

6. The method according to claim 3, characterized in that, The step of querying the database for document fragments associated with the change request event based on the key features includes: The key features are converted into query vectors so that the feature space of the query vectors is consistent with the vector feature space of the document fragments stored in the database; Based on the query vector, a similarity matching operation is performed on the document fragments in the database, which is used as the semantic relevance. The target number of document fragments with a semantic relevance greater than a preset threshold are selected as the associated document fragments.

7. The method according to claim 1, characterized in that, The step of generating prompt words based on the document fragment includes: The system sets system role information, review tasks, review content, and uses the document fragments as contextual knowledge information for the target model. The prompt words are generated based on the role information, the review task, the review content, and the contextual knowledge information.

8. A code processing device, characterized in that, include: The receiving module is used to receive event information sent by the code hosting platform when a change request event for code is detected. The acquisition module is used to acquire the difference content of the code corresponding to the change request event based on the event information; The extraction module is used to extract key features of the code based on the differences. The query module is used to query document fragments associated with the change request event from the database based on the key features. The database stores multiple document fragments associated with code review. The generation module is used to generate prompt words based on the document fragment, so that the trained target model can process the code according to the prompt words to complete the code review.

9. A computer device, characterized in that, include: A processor and a memory, the processor being configured to execute a code processing program stored in the memory to implement the code processing method according to any one of claims 1 to 7.

10. A storage medium, characterized in that, The storage medium stores one or more programs, which can be executed by one or more processors to implement the code processing method according to any one of claims 1 to 7.