Code auditing method, system and equipment based on GitLab and medium

By building a code semantic dependency graph and a depth-first search algorithm, combined with artificial intelligence large models, the problems of low efficiency, insufficient security vulnerability review, and lack of resource management in the traditional code review process are solved, and high-accuracy and efficient code review is achieved. , ensuring code quality and security.

CN118585451APending Publication Date: 2024-09-03广州三七极耀网络科技有限公司
View PDF 0 Cites 10 Cited by

Patent Information

Application Number
CN202410791818.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-19
Publication Date
2024-09-03

AI Technical Summary

Technical Problem

The traditional code review process based on GitLab has low efficiency, insufficient security vulnerability review, and lack of resource consumption management, resulting in low code review accuracy and system stability issues.

Method used

By obtaining the code files and meta-information requested by MR, we build a code semantic dependency graph, combine the depth-first search algorithm and artificial intelligence large model to analyze and repair code problems, and alarm and cut off when resource consumption reaches the threshold to ensure sensitivity Desensitization of information.

Benefits of technology

It improves the accuracy and efficiency of code review, ensures code quality and security, avoids waste of resources and system crashes, and enables safe handling of sensitive information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118585451A
    Figure CN118585451A
Patent Text Reader

Abstract

The invention relates to the technical field of artificial intelligence, in particular to a code auditing method, system and device based on GitLab and a medium, and the method specifically comprises the steps that code problems in all code files are determined based on a code semantic dependency graph, and a code analysis report is formed, modifying the code content with defects according to the code analysis report; obtaining modified current code content, and determining context code content with a direct function call relationship or an indirect function call relationship for the current code content through a depth-first search algorithm based on the code semantic dependency relationship graph; and obtaining the number of tokens consumed by the MR request responded by the underlying artificial intelligence large model interface every time, calculating the resource consumption of the underlying artificial intelligence large model according to the number of tokens, and performing alarm pushing and call cutoff when the number of tokens reaches a preset consumption threshold. According to the invention, the accuracy and efficiency of code auditing are improved through an artificial intelligence technology.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a code review method, system, device and medium based on GitLab. Background Art

[0002] In the software development process, code review is a key link to ensure code quality, which is directly related to the stability and security of the business system. At present, code management based on GitLab has become the mainstream practice in the industry. Before the code is released, developers will submit a merge request (Merge Request, MR) to GitLab, and the technical supervisor will conduct a code review. However, the traditional code review process has the following problems: 1. Low review efficiency: When the amount of code submitted at one time is huge, it is difficult for auditors to conduct a comprehensive check and it is easy to miss key details. 2. Insufficient security vulnerability review: Auditors tend to pay more attention to the correctness of business logic, while the review of security vulnerabilities relies more on personal experience, which is easy to cause security risks. 3. For small-scale code changes, auditors often only focus on the differences in git diff code, but ignore the association between code contexts, which may lead to unexpected bugs after going online. 4. When using large artificial intelligence models for code analysis, a large amount of computing resources may be consumed. Existing code review tools often lack monitoring and management of resource consumption, which may lead to resource waste or system crashes. 5. Traditional manual code review methods are inefficient and prone to missing problems, while existing automated tools are unable to conduct in-depth analysis at the code semantic level, resulting in low audit accuracy. Summary of the invention

[0003] The purpose of the present invention is to provide a code review method, system, device and medium based on GitLab, which effectively combines sensitive information management and code quality control, improves the accuracy and efficiency of code review through artificial intelligence technology, and solves at least one of the above-mentioned prior art problems.

[0004] In a first aspect, the present invention provides a code review method based on GitLab, the method specifically comprising:

[0005] Obtain the MR request submitted by the user, obtain all code files and meta information of all code files corresponding to the MR request through the GitLab API interface based on the ID information of the MR request, and generate a code file object list according to the meta information;

[0006] Perform symbolic processing and abstract syntax tree construction on each code file object in the code file object list to obtain code syntax structure information, and construct a code semantic dependency graph according to the code syntax structure information;

[0007] Determine code problems in all code files based on the code semantic dependency graph and form a code analysis report, and modify defective code content according to the code analysis report;

[0008] Acquire the modified current code content, and determine the context code content having a direct function call relationship or an indirect function call relationship for the current code content by a depth-first search algorithm based on the code semantic dependency graph;

[0009] According to the sensitive information keyword list configured by the business, desensitize the code content and comment information containing sensitive information in all code files;

[0010] Obtain the number of tokens consumed by each MR request responded to by the underlying artificial intelligence big model interface, calculate the resource consumption of the underlying artificial intelligence big model based on the number of tokens, and push alarms and cut off calls when the number of tokens reaches the preset consumption threshold.

[0011] In a second aspect, the present invention provides a code review system based on GitLab, the system specifically comprising:

[0012] The first review module is used to obtain the MR request submitted by the user, obtain all code files and meta information of all code files corresponding to the MR request through the GitLab API interface based on the ID information of the MR request, and generate a code file object list according to the meta information;

[0013] A second audit module is used to perform symbolic processing and abstract syntax tree construction on each code file object in the code file object list, obtain code syntax structure information, and construct a code semantic dependency graph according to the code syntax structure information;

[0014] A third audit module is used to determine the code problems in all code files based on the code semantic dependency graph and form a code analysis report, and modify the defective code content according to the code analysis report;

[0015] A fourth audit module is used to obtain the modified current code content, and based on the code semantic dependency graph, determine the context code content with direct function call relationship or indirect function call relationship for the current code content through a depth-first search algorithm;

[0016] The fifth audit module is used to desensitize the code content and comment information containing sensitive information in all code files according to the sensitive information keyword list configured by the business;

[0017] The sixth audit module is used to obtain the number of tokens consumed by each MR request responded to by the underlying artificial intelligence big model interface, calculate the resource consumption of the underlying artificial intelligence big model based on the number of tokens, and push alarms and cut off calls when the number of tokens reaches a preset consumption threshold.

[0018] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor and a computer program stored in the memory, and when the computer program is executed on the processor, a GitLab-based code review method as described in any one of the above methods is implemented.

[0019] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the GitLab-based code review method as described in any one of the above methods is implemented.

[0020] Compared with the prior art, the present invention has at least one of the following effects:

[0021] 1. It effectively combines sensitive information management and code quality control, improves the accuracy and efficiency of code review through artificial intelligence technology, ensures the secure handling of sensitive information, and supports developers to maintain high standards of code quality and security during the software development process.

[0022] 2. By automatically obtaining the code files and their meta information corresponding to the MR request, building a code semantic dependency graph, and analyzing and repairing code problems based on the graph, the efficiency and accuracy of code review can be greatly improved. At the same time, the depth-first search algorithm is used to determine the context code content that has a direct or indirect function call relationship with the modified code, which can help auditors better understand the logical relationship of the code and avoid missing problems.

[0023] 3. According to the sensitive information keyword list configured by the business, the code content and comment information are scanned using a regular expression matching algorithm. After sensitive information is found, it is desensitized, which can effectively prevent the leakage of sensitive information and improve the security of the code.

[0024] 4. By obtaining the number of tokens consumed by the underlying artificial intelligence large model interface each time responding to an MR request, calculating the resource consumption, and pushing alarms and cutting off calls when the preset consumption threshold is reached, it can effectively avoid the risk of resource waste and system crashes, and improve the stability and reliability of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0026] Figure 1 It is a flowchart of a code review method based on GitLab provided by one embodiment of the present invention;

[0027] Figure 2 This is a structural diagram of a GitLab-based code review system provided by one embodiment of the present invention;

[0028] Figure 3 It is a structural schematic diagram of a computer device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0029] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.

[0030] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.

[0031] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0032] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.

[0033] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0034] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0035] In the embodiment of the present application, the execution subject of the process includes a terminal device, which includes but is not limited to: a server, a computer, a smart phone, a tablet computer, and other devices capable of executing the method disclosed in the present application. Figure 1 A flowchart of a code review method based on GitLab disclosed in an embodiment of the present invention is shown, and the details are as follows:

[0036] S101, obtain the MR request submitted by the user, obtain all code files and meta information of all code files corresponding to the MR request through the GitLab API interface based on the ID information of the MR request, and generate a code file object list according to the meta information.

[0037] In this embodiment, after obtaining the MR (Merge Request) request submitted by the user, the ID information corresponding to the MR request is obtained through the GitLab API interface. According to the obtained ID information, all code files and meta information of all code files corresponding to the MR request are obtained again through the GitLab API interface. After obtaining the meta information of all code files, the meta information parsing algorithm is used to parse the meta information to obtain the file name, file path, file size, file type, last modification time and other meta information of each code file. According to the meta information obtained by parsing, a code file object is created, and the code file object contains attributes such as file name, file path, file size, file type, and last modification time. The created code file object is added to the code file object list. It is determined whether there is any unprocessed code file meta information. If there is any unprocessed code file meta information, the next code file meta information is continued to be parsed, and a code file object is created and added to the code file object list until all code file meta information is processed. Finally, a code file object list containing all code file objects is obtained.

[0038] For example, in a large software project, the development team uses GitLab as a version control system to manage code. In order to improve code quality and review efficiency, the team decided to adopt a code review method based on the GitLab API. When developers complete a function or fix a defect, they will create a merge request (MergeRequest, MR) on GitLab and assign it a unique ID, which is globally unique and is used to identify and track the status of the MR throughout the review process. Once the MR is created, the review system automatically captures this event and obtains the ID information of the MR. Subsequently, the system obtains the ID information corresponding to the MR request through the GitLab API interface, for example, the MR request ID is 123. Then, based on the obtained MR request ID 123, the system again obtains all the code files corresponding to the MR request and the meta information of all the code files through the GitLab API interface. Assuming that the number of code files obtained is 10, the meta information of each code file includes the file name, file path, file size, file type, last modified time, etc. After obtaining the meta information of all code files, the system uses the meta information parsing algorithm to parse the meta information. The algorithm extracts information such as file name, file path, file size, file type, and last modification time from the meta information by matching regular expressions. Based on the parsed meta information, the system creates a code file object and assigns attributes such as file name, file path, file size, file type, and last modification time to the corresponding attributes of the code file object. The created code file object is added to the code file object list. The system determines whether there is any unprocessed code file meta information. If there is, it continues to parse the next code file meta information and repeats the above process until all 10 code file meta information are processed. Finally, the system obtains a code file object list containing 10 code file objects, each of which contains attribute information such as the file name, file path, file size, file type, and last modification time of the corresponding code file. This code file object list can be used for subsequent code analysis, code review, and other operations to improve code quality and development efficiency.

[0039] In this embodiment, by automatically capturing MR creation events and obtaining the code files and meta-information corresponding to MR based on the GitLab API interface, the audit system implements an automated code collection process, which not only improves the audit efficiency, but also reduces the errors and omissions that may be caused by manual operations.

[0040] S102, symbolizing and constructing an abstract syntax tree for each code file object in the code file object list to obtain code syntax structure information, and constructing a code semantic dependency graph according to the code syntax structure information.

[0041] In this embodiment, the programming language used by the code file is first determined, such as Java, Python, C++, etc. Different programming languages ​​have different lexical rules and symbol systems. A lexical analyzer (also called a scanner or lexer) for the selected programming language is used to perform lexical analysis on each code file in the code file object list. This process converts the code into a series of tokens or symbols, each of which corresponds to a basic element in the code, such as a keyword, identifier, literal, operator, etc. The results of the lexical analysis are organized into a token stream sequence, which contains all the basic elements in the code file and their order information.

[0042] Use a syntax analyzer (also called a parser) to parse the symbol stream sequence, combine the symbols into grammatical structures (such as expressions, statements, declarations, etc.) according to the grammatical rules of the programming language, and build an abstract syntax tree (AST). AST is a tree structure in which each node corresponds to a grammatical structure in the code and contains the type and attribute information of the structure. In the process of building AST, some optimization operations can be performed, such as eliminating redundant nodes, merging similar structures, etc., to improve the efficiency and accuracy of subsequent analysis.

[0043] Next, perform semantic analysis on the AST to determine the dependencies between code elements. This includes determining which variables or functions are called by other variables or functions, as well as the data flow and control flow relationships between them. Based on the results of the semantic analysis, a code semantic dependency graph is constructed. This graph is a directed graph in which nodes represent code elements (such as variables, functions, etc.) and edges represent dependencies between elements (such as function calls, data transfer, etc.). The constructed code semantic dependency graph is optimized, such as eliminating redundant edges, merging similar nodes, etc., to improve the clarity and readability of the graph.

[0044] In this embodiment, through symbolic processing and AST construction, the internal structure and grammatical rules of the code can be deeply understood, providing a basis for subsequent code analysis and review. Based on the code semantic dependency graph, potential problems in the code can be found, such as unused variables, dead code, circular dependencies, etc., which may affect the performance, maintainability or security of the code.

[0045] In some embodiments, in the above step S102, the symbolization processing and abstract syntax tree construction of each code file object in the code file object list to obtain code syntax structure information, and the code semantic dependency graph is constructed according to the code syntax structure information, specifically including:

[0046] Performing symbolic processing on each code file object in the code file object list according to a lexical analyzer to obtain a symbol stream sequence, wherein the symbol stream sequence includes a plurality of lexical unit information, and the lexical unit information includes an identifier, a keyword, a literal, and an operator;

[0047] Based on the symbol stream sequence, construct an abstract syntax tree by syntax analysis, wherein the nodes of the abstract syntax tree include syntax unit information, and the syntax unit information includes statements, expressions and declarations;

[0048] Obtaining code syntax structure information according to the abstract syntax tree, and obtaining dependency relationships between code elements by performing semantic analysis on the code syntax structure information;

[0049] A code semantic dependency graph is constructed according to the dependency relationships.

[0050] In this embodiment, according to the lexical analyzer, each code file object in the code file object list is symbolized to obtain a symbol stream sequence corresponding to each code file object, wherein each symbol stream sequence contains lexical unit information in the code file, such as identifiers, keywords, literals, and operators. By traversing the symbol stream sequence of each code file object, the lexical unit information in each symbol stream sequence is obtained, and according to the type of the lexical unit, it is divided into different categories such as identifiers, keywords, literals, and operators, and the lexical unit information classified by category is obtained. A statistical method is used to count the lexical unit information of each category, obtain the frequency of occurrence of each category of lexical units, and determine the importance of each category of lexical units according to the frequency. The higher the frequency, the more frequently the lexical unit of this category appears in the code file, and the higher the importance. According to the determined lexical unit importance, the symbol stream sequence of each code file object is filtered and screened, and the lexical units with high importance are retained, and the lexical units with low importance are filtered out to obtain a simplified symbol stream sequence, thereby reducing redundant information.

[0051] According to the symbol stream sequence, a syntax analysis method is used to analyze it to obtain an abstract syntax tree; by traversing the nodes of the abstract syntax tree, the syntax unit information is obtained, and the syntax unit information includes statements, expressions and declarations; according to the obtained sentence syntax unit information, the type of statement is judged, and the statement type includes conditional statements, loop statements and general statements; the conditional statement is analyzed by a conditional judgment method to obtain conditional expressions and statement blocks; the loop judgment method is used to analyze the loop statement to obtain loop conditions and loop body statement blocks; according to the statement type analysis results, a recursive method is used to further perform syntax analysis on the statement block to obtain the abstract syntax tree of the statement block; by traversing the expression nodes of the abstract syntax tree, the expression of the expression block is obtained. The grammatical unit information of the expression; according to the grammatical unit information of the expression, the recursive descent analysis method is used to evaluate the expression to obtain the value of the expression; by traversing the declaration nodes of the abstract syntax tree, the grammatical unit information of the declaration is obtained, and the grammatical unit information includes variable declarations, function declarations and class declarations; according to the grammatical unit information of the variable declaration, the symbol table method is used to add the variable name and type to the symbol table; according to the grammatical unit information of the function declaration, the symbol table method is used to add the function name, parameter list and return value type to the symbol table; according to the grammatical unit information of the class declaration, the symbol table method is used to add the class name and class members to the symbol table; through the above steps, a complete abstract syntax tree and symbol table information are obtained.

[0052] According to the node information in the abstract syntax tree, the depth-first traversal algorithm is used to obtain the definition and calling relationship of elements such as classes, functions, and variables in the code. By analyzing the parent-child relationship of the nodes, the grammatical dependency relationship between the code elements is obtained. According to the grammatical dependency relationship obtained in the previous step, the symbol table and type checking algorithm are used to analyze the scope of variables, type matching, etc., to obtain the semantic information between the code elements, determine the semantic dependency relationship between the code elements, and construct a semantic dependency relationship table. According to the semantic dependency relationship table, the graph theory algorithm is used to take the code elements as nodes and the semantic dependency relationship as directed edges. By connecting the nodes with dependencies, the initial version of the code semantic dependency graph is obtained. According to the initial version of the code semantic dependency graph, the graph optimization algorithm is used to obtain a simplified code semantic dependency graph by merging repeated edges, removing redundant nodes, and other operations to determine the final dependency relationship between code elements.

[0053] S103, determining code problems in all code files based on the code semantic dependency graph and forming a code analysis report, and modifying defective code content according to the code analysis report.

[0054] In this embodiment, based on the constructed code semantic dependency graph, a static code analysis tool is used to scan the code to find potential code problems, including but not limited to: unused variables, potential null pointer references, memory leaks, logic errors, circular dependencies, etc. By analyzing the code semantic dependency graph, the dependencies between code modules can be found, and it can be determined which modules or functions have too many dependencies, which may make the code difficult to maintain and understand. According to the complexity of the code semantic dependency graph, the complexity of the code can be evaluated. For example, if there are too many nodes and edges in the graph, or there are complex control flow and data flow structures, then the code may be difficult to understand and maintain.

[0055] Then, the detected code problems are classified by type, such as syntax errors, logic errors, performance issues, etc. A detailed description is provided for each problem, including the location of the problem (such as file name, line number), the nature of the problem, possible impact, and repair suggestions. Problems are prioritized according to their severity and urgency so that developers can prioritize important issues. The code semantic dependency graph and the location of the problem in the graph are visualized to help developers understand the problem more intuitively.

[0056] After fixing the problem, verify the effectiveness of the modification by running test cases, integration tests, or performance tests to ensure that the modification does not introduce new problems or destroy the original functionality.

[0057] In this embodiment, by automatically detecting code problems and generating detailed reports, developers can be helped to find and fix potential defects in a timely manner, thereby improving the quality and stability of the code.

[0058] In some embodiments, in the above step S103, determining the code problems in all code files based on the code semantic dependency graph and forming a code analysis report, and modifying the defective code content according to the code analysis report specifically includes:

[0059] According to the code semantic dependency graph, all code files are traversed using a graph-based depth-first search algorithm, and code defect information in the code content is determined using code static analysis technology to form a code analysis report;

[0060] Based on the code analysis report, the abstract syntax tree analysis technology is used to locate the defective code content, and the semantic analysis technology is used to determine the type and severity of the code defect;

[0061] According to the preset code repair rule library, the corresponding code repair solution is obtained according to the type and severity of the code defect, and the repaired code file is obtained;

[0062] According to the repaired code file, the code execution process is analyzed by using the control flow graph analysis technology, the data flow analysis technology is used to track the data flow and life cycle in the code content, and the code coverage analysis technology is combined to determine whether there are still problems in the code logic of the repaired code file;

[0063] If there are still problems with the code logic of the repaired code file, a new code repair solution is obtained from the code repair rule library to repair it until there are no more problems with the code logic of the repaired code file.

[0064] In this embodiment, all code files are obtained according to the code repository, and the code content is analyzed by code static analysis technology to obtain a code semantic dependency graph. A graph-based depth-first search algorithm is adopted, and the code semantic dependency graph is used as input to traverse all code files to obtain the call relationship and dependency relationship between code files. In the process of traversing the code files with depth-first search, the content of each code file is analyzed by code static analysis technology to determine whether there are code defects, and the code defect information is recorded. The code file call relationship, dependency relationship and code defect information obtained by the depth-first search traversal are integrated to form complete code analysis data. According to the code analysis data, data visualization technology is used to generate a code analysis report, which includes a call relationship graph, a dependency graph and a code defect distribution graph between code files, which is convenient for developers and managers to understand the code quality status.

[0065] According to the code analysis report, the code is parsed using the abstract syntax tree analysis technology to generate an abstract syntax tree representation, obtain the structured information of the code, and obtain the syntax structure, variables, functions and other elements of the code. By traversing the abstract syntax tree and combining the defect information in the code analysis report, the code fragment with defects is located, and the position and scope of the defective code in the abstract syntax tree are determined. The semantic analysis technology is used to conduct an in-depth analysis of the located defective code fragments to obtain the semantic information of the code, including the type of variables, function parameters and return values, etc., and determine the type of code defects, such as null pointer reference, memory leak, array out of bounds, etc. According to the type of code defects, combined with the severity assessment criteria in the code analysis report, the severity assessment algorithm is used to comprehensively consider the complexity of the defective code, the scope of impact, the possible consequences, etc., calculate the severity score of the defect, and obtain the severity level of the code defect, such as severe, high risk, medium risk, low risk, etc. The located defective code fragments, defect types and severity information are integrated to generate a code defect report, providing a detailed description of the defect, location, repair suggestions, etc., to provide a basis for subsequent code repair and optimization, and improve code quality and system stability.

[0066] Obtain the type and severity information of code defects according to the code file. By analyzing the syntax errors, logic errors, security vulnerabilities and other issues in the code file, determine the type of code defects, such as syntax errors, logic errors, security vulnerabilities, etc., and the severity of the defects, such as low, medium, and high levels. Use the preset code repair rule library to find the corresponding repair solution in the repair rule library according to the type and severity of the code defect. The repair rule library contains repair templates and repair steps for various common code defects. Obtain the corresponding code repair solution by matching the code defect type and severity. After obtaining the repair solution, apply it to the defective code file. Modify and optimize the code file according to the steps and guidelines in the repair solution to eliminate the code defects. During the repair process, make necessary adjustments and adaptations to the repair solution according to the context and business logic of the code. After the repair is completed, check and verify the repaired code file. Use code static analysis tools and unit testing to verify whether the repaired code meets the syntax specifications, whether the original defects are fixed, and whether new problems are introduced. Through multiple rounds of iteration and repair, until the code quality meets the requirements. Finally, the repaired code file is obtained. The repaired code file not only eliminates the original defects, but also complies with coding standards and best practices. At the same time, according to business needs, the repaired code is optimized and refactored as necessary to improve the readability, maintainability and performance of the code. Ensure that the repaired code can run normally and meet business functional and non-functional requirements.

[0067] According to the repaired code file, the control flow graph analysis technology is used to construct the control flow graph of the code to obtain the execution process of the code, determine the basic blocks, branch structures and loop structures of the code, and determine whether the code logic has problems such as dead code and unreachable code. The data flow analysis technology is used to track the definition and use of variables in the code to obtain the life cycle and data dependencies of the variables, determine whether there are problems such as uninitialized variables, repeated variable definitions, and unused variables in the code, and determine whether the data flow of the code is correct. The code coverage analysis technology is used to design test cases to obtain indicators such as statement coverage, branch coverage, and condition coverage of the code, determine the test adequacy of the code, determine whether there is still uncovered code logic, and find out the weak links in the code. According to the results of control flow graph analysis, data flow analysis, and code coverage analysis, a comprehensive analysis method is used to comprehensively evaluate the code logic, data flow, and test coverage to obtain the overall quality and reliability of the code, determine whether the code still has logical defects, data anomalies, and insufficient testing, and determine the effectiveness of code repair. According to the results of comprehensive analysis, optimization and improvement measures are adopted to obtain more efficient and robust code implementation by adjusting and improving the logical structure, data processing and test cases of the code. It is determined that the repaired code files have met the expected quality requirements, providing reliable guarantee for the correct operation of the software system.

[0068] S104, obtaining the modified current code content, and based on the code semantic dependency graph, determining the context code content having a direct function call relationship or an indirect function call relationship for the current code content through a depth-first search algorithm.

[0069] In this embodiment, the code change event in the code repository is monitored by GitLab's Webhooks. When the code change event occurs, the modified code file and the specific content of its modification are extracted. Specifically, in the code semantic dependency graph, the node corresponding to the currently modified code is found as the starting search point. This may be a function definition, class definition or other identifiable code element. Starting from the starting node, the code semantic dependency graph is traversed using a depth-first search algorithm. During the traversal process, all nodes with direct or indirect function call relationships with the starting node are recorded. If node A has an edge pointing to node B, and this edge indicates that A calls B (ie, A is the caller and B is the callee), then there is a direct function call relationship between A and B. If node A can reach node C through a series of edges, and the path formed by these edges indicates that A indirectly calls C (ie, A indirectly calls C through other functions or methods), then there is an indirect function call relationship between A and C. The code content corresponding to all nodes with direct or indirect function call relationships with the starting node is collected to form a context code set.

[0070] The context code set is presented to developers in an appropriate manner, such as directly highlighting the relevant code in the code editor or providing a link in the code review tool for developers to view. Developers can use this context code set to better understand the role and impact of the currently modified code in the entire system, thereby conducting more accurate code reviews.

[0071] In this embodiment, by automatically determining the context code content that has a direct or indirect function call relationship with the currently modified code, developers can more comprehensively understand the scope of the modification, thereby performing a more accurate code review. This helps reduce potential problems caused by missing related code. By building a code semantic dependency graph and using a depth-first search algorithm to determine the context code content, developers can better understand the overall structure of the system and the interaction between the various parts, thereby maintaining and managing the code more efficiently.

[0072] In some embodiments, in the above step S104, determining the context code content having a direct function call relationship or an indirect function call relationship for the current code content by a depth-first search algorithm based on the code semantic dependency graph specifically includes:

[0073] Using a depth-first search algorithm to traverse all nodes in the code semantic dependency graph;

[0074] Determine whether there is a direct function call relationship or an indirect function call relationship between the currently traversed node and the node corresponding to the modified current code content;

[0075] If there is a direct function call relationship or an indirect function call relationship between the currently traversed node and the node corresponding to the modified current code content, then it is determined that the code content corresponding to the currently traversed node is the context code content that has a direct function call relationship or an indirect function call relationship with the modified current code content.

[0076] In this embodiment, in the code semantic dependency graph, a depth-first search algorithm is used for traversal, starting from the node corresponding to the modified current code content, and recursively accessing all its unvisited adjacent nodes. During the traversal process, it is determined whether there is a direct function call relationship between the currently traversed node and the modified node, that is, whether the current node directly calls the function corresponding to the modified node; or whether there is an indirect function call relationship, that is, the current node indirectly calls the function corresponding to the modified node through other functions. This judgment can be achieved by analyzing the attributes of the edges between the nodes. If the edge between the two nodes is marked as "function call" and the direction is from the current node to the modified node, it means that there is a direct function call relationship; if there is a path consisting of one or more "function call" edges between the current node and the modified node, it means that there is an indirect function call relationship. For those nodes that have a direct or indirect function call relationship with the modified node, their corresponding code content is determined as the context code content that has a call relationship with the modified code content, and impact analysis and code maintenance can be performed based on this. For example, in a graphics rendering engine code base, if the code of a material shader is modified, this method can quickly locate the rendering pipeline code, scene graph node code, etc. that call the shader. Developers can focus on these codes to ensure that the modification does not introduce new defects.

[0077] S105: Desensitize the code content and comment information containing sensitive information in all code files according to the sensitive information keyword list configured by the business.

[0078] In this embodiment, according to the list of sensitive information keywords configured by the business, a string matching algorithm is used to scan the code content and annotation information in all code files. If the code content or annotation information contains sensitive information keywords, the keyword and its context content are extracted. The regular expression matching algorithm is used to determine whether the extracted context content conforms to the pattern of sensitive information. If it conforms to the sensitive information pattern, a data desensitization algorithm is used to desensitize the sensitive information. The data desensitization algorithm includes methods such as character replacement, string encryption, and string truncation. Character replacement is to replace the key characters in the sensitive information with specific characters, such as replacing the middle four digits of the mobile phone number with asterisks; string encryption is to encrypt the sensitive information so that it cannot be directly read; string truncation is to intercept part of the sensitive information, such as intercepting the first six digits and the last four digits of the ID card number. After desensitization, the desensitized content replaces the sensitive information in the original code file to obtain a desensitized code file. Finally, the desensitized code file is checked by code static analysis technology to ensure that the desensitized code does not affect the function and performance of the original code.

[0079] In some embodiments, in the above step S105, the sensitive information keyword list configured according to the business is used to desensitize the code content and annotation information containing sensitive information in all code files, specifically including:

[0080] Get a list of sensitive information keywords for business configuration;

[0081] Based on the sensitive information keyword list, a regular expression matching algorithm is used to scan the code content and comment information of all code files to determine whether the code content and the comment information contain sensitive information;

[0082] If the answer is yes, a data desensitization algorithm is used to desensitize the code content or comment information containing sensitive information;

[0083] The desensitized code content and comment information are replaced with the original code content and comment information to obtain a desensitized code file;

[0084] The desensitized code file is checked using code static analysis technology to determine whether the original code function of the desensitized code file is affected.

[0085] In this embodiment, according to the code content and annotation information, sensitive information that may be contained therein, such as personal name, ID number, mobile phone number, bank card number, etc., is obtained to obtain the type and specific content of the sensitive information. According to the type of sensitive information, the corresponding data desensitization algorithm is adopted. For the name, the surname can be retained for partial hiding; for the ID number, the first six digits and the last four digits can be retained, and the middle digit can be replaced with an asterisk for partial hiding; for the mobile phone number, the first three digits and the last four digits can be retained, and the middle digit can be replaced with an asterisk for partial hiding; for the bank card number, the first six digits and the last four digits can be retained, and the middle digit can be replaced with an asterisk for partial hiding, and a specific data desensitization scheme is determined. The sensitive content in the code content and annotation information is obtained, and the sensitive content is replaced by a determined data desensitization scheme to obtain the desensitized content. The original sensitive content in the code and annotation information is replaced by the desensitized content, and the code content and annotation information after the data desensitization processing are obtained. According to the desensitized code content and annotation information, the source code file is updated to ensure that the sensitive information in the source code is properly handled and will not be leaked. The updated source code file is used to rescan the code to determine whether the code still contains sensitive information. If it does not contain sensitive information, the data desensitization process is completed; if it still contains sensitive information, the data desensitization process is returned to continue until the code does not contain any sensitive information.

[0086] The code static analysis tool is used to perform syntax and structural analysis on the desensitized code file, and the code structure information such as the abstract syntax tree and control flow graph of the desensitized code file is obtained to lay the foundation for subsequent analysis. According to the obtained code structure information, the data flow analysis technology is used to track the data flow in the desensitized code file and determine the impact range of the desensitization operation on the original data. Through the control flow analysis technology, the execution path information of the desensitized code file is obtained to determine whether the desensitization operation has changed the execution logic and process of the original code. The symbolic execution technology is used to simulate the execution process of the desensitized code file, obtain the input and output data under different execution paths, and determine the impact of the desensitization operation on the original function. According to the results of data flow analysis, control flow analysis and symbolic execution, the degree of impact of the desensitization operation on the original code function is comprehensively judged to obtain the functional integrity evaluation results of the desensitized code file. By comparing the code execution results before and after desensitization, the output difference caused by the desensitization operation is obtained to determine whether the desensitization operation affects the correctness of key functions. According to the functional integrity evaluation results and the key function correctness check results, it is comprehensively judged whether the original code function of the desensitized code file is affected, and the final functional impact analysis report is obtained.

[0087] S106, obtaining the number of tokens consumed by each MR request responded to by the underlying artificial intelligence big model interface, calculating the resource consumption of the underlying artificial intelligence big model based on the number of tokens, and pushing alarms and calling cutoff when the number of tokens reaches a preset consumption threshold.

[0088] In this embodiment, the number of tokens consumed by the underlying artificial intelligence large model interface each time it responds to an MR request is obtained, and the word segmentation algorithm in natural language processing is used to perform word segmentation on the response content to obtain the token list and number of the response content. According to the number of tokens obtained, the weighted moving average algorithm is used to calculate the real-time resource consumption of the underlying artificial intelligence large model, and the number of tokens is used as an input parameter. The weighted calculation is performed through the weight coefficient and the historical consumption to obtain the estimated resource consumption at the current moment. It is determined whether the calculated estimated resource consumption reaches the preset consumption threshold. If the threshold is reached, the alarm push and call cut-off process are triggered, and the alarm information is generated according to the pre-configured alarm rules, and sent to the relevant responsible person through the message queue. At the same time, the interface control module of the underlying artificial intelligence large model is called to cut off the current MR request call. If the estimated resource consumption does not reach the preset threshold, the number of tokens for the next MR request is continued to be obtained, and the above steps are repeated to monitor the resource consumption of the underlying artificial intelligence large model in real time. The preset threshold is dynamically adjusted according to the change trend of resource consumption, and the threshold setting is optimized through the incremental learning algorithm to improve the accuracy and real-time performance of the alarm. When abnormal fluctuations in resource consumption of the underlying artificial intelligence large model are detected, the isolation forest algorithm is used for anomaly detection. By constructing an isolation tree and calculating the anomaly score, it is determined whether there is abnormal consumption behavior. An analysis report is generated based on the anomaly detection results, and an intuitive monitoring screen is generated through data visualization technology, which allows managers to promptly understand the operating status of the underlying system.

[0089] In some embodiments, in the above step S106, the resource consumption of the underlying artificial intelligence large model is calculated by the number of tokens, and an alarm is pushed and the call is cut off when the number of tokens reaches a preset consumption threshold, specifically including:

[0090] The number of tokens is used as an input parameter, and weighted calculation is performed through the weighted coefficient and historical consumption to obtain the estimated value of resource consumption of the underlying artificial intelligence model at the current moment;

[0091] Determine whether the estimated value of resource consumption reaches a preset consumption threshold. If so, trigger an alarm push process and a call cut-off process. The alarm push process generates alarm information according to pre-configured alarm rules and sends it to relevant responsible persons through a message queue. The call cut-off process cuts off the call of the current MR request by using the interface control module of the underlying artificial intelligence large model.

[0092] Monitor the resource consumption of the underlying artificial intelligence large model in real time, dynamically adjust the preset consumption threshold according to the changing trend of the resource consumption, and optimize the setting of the preset consumption threshold through the incremental learning algorithm.

[0093] In this embodiment, the estimated resource consumption of the current MR request is obtained and compared with the pre-configured resource consumption threshold. It is determined whether the estimated resource consumption reaches or exceeds the preset consumption threshold. If it reaches or exceeds, the alarm push process and the call cut-off process are triggered. According to the pre-configured alarm rules, the corresponding alarm information is generated in combination with the resource consumption of the current MR request. The generated alarm information is sent to the relevant responsible person through the message queue system for timely processing and response. The interface control module of the underlying artificial intelligence large model is used to cut off the call of the current MR request according to the alarm information and preset rules to avoid excessive resource consumption. The execution result of the cut-off operation is obtained to determine whether the current MR request has been successfully terminated and release the corresponding computing resources. The execution of the alarm push and cut-off process is recorded through the log system for subsequent analysis and optimization. According to the alarm information and the cut-off result, the status of the MR request is updated, and the relevant user request is notified that the request has been terminated. The dynamic adjustment strategy of the resource consumption threshold is obtained, and the threshold setting is adjusted in time according to the historical data of the MR request and the system load. Through the monitoring system, the resource consumption of the MR request is continuously tracked, and the data is fed back to the threshold adjustment module to form a closed-loop control.

[0094] According to the running status of the large AI model, the resource monitoring tool is used to obtain the resource consumption indicators of the large model such as CPU occupancy, memory occupancy, GPU utilization, etc. in real time, and the resource consumption data at the current moment is obtained. By statistically analyzing the resource consumption data over a continuous period of time, the change trend of resource consumption is obtained, including statistical characteristics such as mean, variance, slope, etc., to determine whether there is an obvious growth or decline trend in resource consumption. According to the historical data and current change trend of resource consumption, the adaptive threshold algorithm is used to dynamically adjust the preset consumption threshold. When the resource consumption exceeds the dynamic threshold, an alarm is triggered, indicating that the large model needs to be optimized to reduce resource consumption. The setting of the preset consumption threshold is continuously optimized through the incremental learning algorithm. According to the actual resource consumption of the large model and business needs, the optimal threshold parameters are obtained to minimize resource consumption while meeting business performance. Specifically, by analyzing user attributes and consumption behaviors, the consumption characteristics of different types of users are obtained, and the clustering algorithm is used to classify users to obtain the consumption threshold range of each category of users. According to the real-time consumption data of users, the online learning algorithm is used to dynamically adjust the consumption threshold to obtain the real-time updated user consumption threshold. By analyzing the user consumption behavior in different time periods, the time distribution characteristics of the user consumption threshold are obtained, and the user consumption threshold in the future period is predicted by the time series prediction algorithm to obtain the dynamically changing user consumption threshold curve. According to the difference between the user consumption threshold and the actual consumption, the reinforcement learning algorithm is used to optimize the setting strategy of the consumption threshold, obtain the optimal consumption threshold setting strategy, and determine the final dynamic user consumption threshold. By applying the optimized user consumption threshold to the business scenario, the user's real-time consumption feedback data is obtained, and the feedback control algorithm is used to adaptively adjust the consumption threshold to obtain a continuously optimized user consumption threshold, so as to achieve personalized threshold setting based on user consumption behavior and improve user experience and business benefits.

[0095] For example, when the system receives an MR request containing 1,000 tokens, the system multiplies the number of tokens by the preset weighting coefficient of 8, plus the weighting coefficient of the historical consumption of 2 multiplied by the resource consumption at the previous moment, and obtains the estimated resource consumption at the current moment of 850 through the weighted average algorithm. The system determines that the estimated value has reached the preset consumption threshold of 800, so it triggers the alarm push process and the call cut-off process. The alarm push process generates an alarm message according to the pre-configured alarm rule "When the estimated resource consumption exceeds 90% of the threshold, send an alarm message to the relevant responsible person", and sends it to the system administrator and developer through the Kafka message queue. The call cut-off process calls the control module of the model through the RESTAPI interface of the underlying artificial intelligence big model and cuts off the current MR request. At the same time, the system monitors the resource consumption of the underlying artificial intelligence big model in real time, fits the change curve of resource consumption through the least squares method, and obtains the change trend of increasing by 50 per minute. Based on this, the preset consumption threshold is dynamically adjusted from 800 to 900.

[0096] In some embodiments, the method further comprises:

[0097] According to the interface information of the underlying artificial intelligence big model configured by the user, the factory mode and strategy mode are adopted to dynamically select and create the corresponding model application interface adapter, and generate the corresponding request parameter object according to the interface specification of the model application interface adapter. The request parameter object includes the model identifier, code body content, context code content and role prompt description content.

[0098] In this embodiment, a model application interface adapter instance is dynamically created according to the model identifier through the factory mode to obtain a model application interface adapter object. A corresponding request parameter object is generated according to the interface specification of the model application interface adapter, and the request parameter object includes a model identifier, a code body content, a context code content, and a role prompt description content. Among them, the code body content is a core code fragment input by the user, the context code content is a context code related to the code body content, and the role prompt description content is a description of the role played by the artificial intelligence model. The model application interface specification is obtained according to the model application interface adapter object to determine the format and content requirements of the request parameters. A request parameter builder is used to fill the model identifier, the code body content, the context code content, and the role prompt description content into the request parameter object according to the model application interface specification to obtain a constructed request parameter object. Through the model application interface adapter object, the constructed request parameter object is passed to the underlying artificial intelligence large model and a request is sent. After receiving the request parameter object, the underlying artificial intelligence large model loads the corresponding pre-trained model according to the model identifier, and inputs the code body content, the context code content, and the role prompt description content into the pre-trained model. The pre-trained model generates output results related to the main content of the code and the description of the role prompts based on the input content through technologies such as the self-attention mechanism and the feedforward neural network. The self-attention mechanism can capture long-distance dependencies in the input content, and the feedforward neural network can perform nonlinear transformations and information extraction on features. The output results generated by the pre-trained model are returned to the user through the model application interface adapter. After the user obtains the output results, the generated content can be further processed and applied according to actual needs, such as integrating it into the code editor to provide intelligent programming assistance, or for automatic generation of code documents. If the user is not satisfied with the generated output results, the main content of the code, the context code content, or the role prompt description content can be adjusted, and the request can be re-initiated to generate results that better meet the needs. Through continuous interaction and feedback, the content generated by the artificial intelligence model is made more accurate and effective.

[0099] Specifically, dynamically creating a model application interface adapter instance according to the model identifier through the factory mode to obtain the model application interface adapter object can include: obtaining the corresponding model adapter class name from the model configuration file according to the model identifier. Using the reflection mechanism to obtain the class object of the model adapter class through the class name. Obtaining the constructor of the model adapter class and passing in the necessary parameters to instantiate the model adapter object. Calling the unified model interface method through the model adapter object to achieve interaction with the specific model. Judging whether the model call is successful based on the return value of the model interface method. Obtaining the result data returned by the model, and performing necessary conversion and processing on the result data. Returning the processed model result to the upper-level application to complete the dynamic call of the model.

[0100] For example, the user sets the interface information of the underlying artificial intelligence model in the configuration file, including OpenAI's GPT-5, Google's PaLM, and Microsoft's Prometheus. The system reads the configuration file and uses the factory mode to dynamically create corresponding model application interface adapter instances according to different model identifiers such as "openai", "google", "microsoft", etc. When the model identifier is "openai", the factory class will create an instance of the OpenAIAdapter class; when the model identifier is "google", the factory class will create an instance of the GoogleAdapter class. In this way, the system can flexibly select and switch different artificial intelligence models according to the configuration. Next, the system uses the request parameter builder to generate the corresponding request parameter object according to the interface specification of the selected model application interface adapter. For OpenAI's GPT-5 model, the request parameter object needs to include fields such as the model identifier "text-davinci-002", code body content, context code content, and role prompt description content; for Google's PaLM model, the request parameter object needs to include fields such as the model identifier "palm-001", code body content, context code content, and role prompt description content. The request parameter builder will fill these fields into the request parameter object according to the interface specification provided by the adapter, ensuring that the format and content of the request parameters meet the requirements of the selected model. The constructed request parameter object is sent to the underlying artificial intelligence model through the model application interface adapter. For example, the OpenAIAdapter class passes the request parameter object to the GPT-5 model by calling OpenAI's API interface; the GoogleAdapter class passes the request parameter object to the PaLM model by calling Google's API interface. After receiving the request, the artificial intelligence model will load the corresponding pre-trained model according to the model identifier, and input the code body content, context code content, and role prompt description content into the pre-trained model for processing.

[0101] Reference Figure 2 An embodiment of the present invention provides a GitLab-based code review system 2, wherein the system 2 specifically includes:

[0102] The first review module 201 is used to obtain the MR request submitted by the user, obtain all code files and meta information of all code files corresponding to the MR request through the GitLab API interface based on the ID information of the MR request, and generate a code file object list according to the meta information;

[0103] The second audit module 202 is used to perform symbolic processing and abstract syntax tree construction on each code file object in the code file object list, obtain code syntax structure information, and construct a code semantic dependency graph according to the code syntax structure information;

[0104] The third audit module 203 is used to determine the code problems in all code files based on the code semantic dependency graph and form a code analysis report, and modify the defective code content according to the code analysis report;

[0105] The fourth audit module 204 is used to obtain the modified current code content, and determine the context code content with direct function call relationship or indirect function call relationship for the current code content through a depth-first search algorithm based on the code semantic dependency graph;

[0106] The fifth review module 205 is used to perform desensitization processing on the code content and comment information containing sensitive information in all code files according to the sensitive information keyword list configured by the business;

[0107] The sixth audit module 206 is used to obtain the number of tokens consumed by each MR request responded to by the underlying artificial intelligence big model interface, calculate the resource consumption of the underlying artificial intelligence big model based on the number of tokens, and push alarms and cut off calls when the number of tokens reaches a preset consumption threshold.

[0108] It is understandable that if Figure 1 The contents of the GitLab-based code review method embodiment shown in the figure are applicable to the GitLab-based code review system embodiment. The functions specifically implemented by the GitLab-based code review system embodiment are similar to those in the example shown in the figure. Figure 1 The code review method embodiment based on GitLab shown in FIG. 1 is the same as that shown in FIG. 1 , and the beneficial effects achieved are the same as those of FIG. Figure 1 The beneficial effects achieved by the GitLab-based code review method embodiment shown are also the same.

[0109] It should be noted that the information interaction, execution process and other contents between the above-mentioned systems are based on the same concept as the embodiment of the method of the present invention. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.

[0110] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the system can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0111] Reference Figure 3 The embodiment of the present invention further provides a computer device 3, comprising: a memory 302 and a processor 301 and a computer program 303 stored in the memory 302. When the computer program 303 is executed on the processor 301, a code review method based on GitLab as described in any one of the above methods is implemented.

[0112] The computer device 3 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The computer device 3 may include, but is not limited to, a processor 301 and a memory 302. Those skilled in the art will appreciate that Figure 3 It is only an example of computer device 3 and does not constitute a limitation on computer device 3. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components, for example, it may also include input and output devices, network access devices, etc.

[0113] The processor 301 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0114] In some embodiments, the memory 302 may be an internal storage unit of the computer device 3, such as a hard disk or memory of the computer device 3. In other embodiments, the memory 302 may also be an external storage device of the computer device 3, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the computer device 3. Further, the memory 302 may also include both an internal storage unit of the computer device 3 and an external storage device. The memory 302 is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as the program code of the computer program, etc. The memory 302 may also be used to temporarily store data that has been output or is to be output.

[0115] An embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the GitLab-based code review method as described in any one of the above methods is implemented.

[0116] In this embodiment, if the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above-mentioned various method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium can at least include: any entity or device that can carry the computer program code to the camera / terminal device, recording medium, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. For example, a USB flash drive, a mobile hard disk, a disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.

[0117] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0118] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0119] In the embodiments disclosed in the present application, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

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

Claims

1. A code review method based on GitLab, characterized in that: The method specifically comprises: Obtain the MR request submitted by the user, obtain all code files and meta information of all code files corresponding to the MR request through the GitLab API interface based on the ID information of the MR request, and generate a code file object list according to the meta information; Perform symbolic processing and abstract syntax tree construction on each code file object in the code file object list to obtain code syntax structure information, and construct a code semantic dependency graph according to the code syntax structure information; Determine code problems in all code files based on the code semantic dependency graph and form a code analysis report, and modify defective code content according to the code analysis report; Acquire the modified current code content, and determine the context code content having a direct function call relationship or an indirect function call relationship for the current code content by a depth-first search algorithm based on the code semantic dependency graph; According to the sensitive information keyword list configured by the business, desensitize the code content and comment information containing sensitive information in all code files; Obtain the number of tokens consumed by each MR request responded to by the underlying artificial intelligence big model interface, calculate the resource consumption of the underlying artificial intelligence big model based on the number of tokens, and push alarms and cut off calls when the number of tokens reaches the preset consumption threshold.

2. The method according to claim 1, characterized in that The performing symbolic processing and abstract syntax tree construction on each code file object in the code file object list to obtain code syntax structure information, and constructing a code semantic dependency graph according to the code syntax structure information specifically includes: Performing symbolic processing on each code file object in the code file object list according to a lexical analyzer to obtain a symbol stream sequence, wherein the symbol stream sequence includes a plurality of lexical unit information, and the lexical unit information includes an identifier, a keyword, a literal, and an operator; Based on the symbol stream sequence, construct an abstract syntax tree by syntax analysis, wherein the nodes of the abstract syntax tree include syntax unit information, and the syntax unit information includes statements, expressions and declarations; Obtaining code syntax structure information according to the abstract syntax tree, and obtaining dependency relationships between code elements by performing semantic analysis on the code syntax structure information; A code semantic dependency graph is constructed according to the dependency relationships.

3. The method according to claim 1, characterized in that: The determining of code problems in all code files based on the code semantic dependency graph and forming a code analysis report, and modifying defective code content according to the code analysis report specifically includes: According to the code semantic dependency graph, all code files are traversed using a graph-based depth-first search algorithm, and code defect information in the code content is determined using code static analysis technology to form a code analysis report; Based on the code analysis report, the abstract syntax tree analysis technology is used to locate the defective code content, and the semantic analysis technology is used to determine the type and severity of the code defect; According to the preset code repair rule library, the corresponding code repair solution is obtained according to the type and severity of the code defect, and the repaired code file is obtained; According to the repaired code file, the code execution process is analyzed by using the control flow graph analysis technology, the data flow analysis technology is used to track the data flow and life cycle in the code content, and the code coverage analysis technology is combined to determine whether there are still problems in the code logic of the repaired code file; If there are still problems with the code logic of the repaired code file, a new code repair solution is obtained from the code repair rule library to repair it until there are no more problems with the code logic of the repaired code file.

4. The method according to claim 1, characterized in that The determining, based on the code semantic dependency graph, context code content having a direct function call relationship or an indirect function call relationship for the current code content by a depth-first search algorithm specifically includes: Using a depth-first search algorithm to traverse all nodes in the code semantic dependency graph; Determine whether there is a direct function call relationship or an indirect function call relationship between the currently traversed node and the node corresponding to the modified current code content; If there is a direct function call relationship or an indirect function call relationship between the currently traversed node and the node corresponding to the modified current code content, then it is determined that the code content corresponding to the currently traversed node is the context code content that has a direct function call relationship or an indirect function call relationship with the modified current code content.

5. The method according to claim 1, characterized in that The sensitive information keyword list configured according to the business is used to desensitize the code content and comment information containing sensitive information in all code files, specifically including: Get a list of sensitive information keywords for business configuration; Based on the sensitive information keyword list, a regular expression matching algorithm is used to scan the code content and comment information of all code files to determine whether the code content and the comment information contain sensitive information; If the answer is yes, a data desensitization algorithm is used to desensitize the code content or comment information containing sensitive information; The desensitized code content and comment information are replaced with the original code content and comment information to obtain a desensitized code file; The desensitized code file is checked using code static analysis technology to determine whether the original code function of the desensitized code file is affected.

6. The method according to claim 1, characterized in that The resource consumption of the underlying artificial intelligence large model is calculated by the number of tokens, and an alarm is pushed and the call is cut off when the number of tokens reaches a preset consumption threshold, specifically including: The number of tokens is used as an input parameter, and weighted calculation is performed through the weighted coefficient and historical consumption to obtain the estimated value of resource consumption of the underlying artificial intelligence model at the current moment; Determine whether the estimated value of resource consumption reaches a preset consumption threshold. If so, trigger an alarm push process and a call cut-off process. The alarm push process generates alarm information according to pre-configured alarm rules and sends it to relevant responsible persons through a message queue. The call cut-off process cuts off the call of the current MR request by using the interface control module of the underlying artificial intelligence large model. Monitor the resource consumption of the underlying artificial intelligence large model in real time, dynamically adjust the preset consumption threshold according to the changing trend of the resource consumption, and optimize the setting of the preset consumption threshold through the incremental learning algorithm.

7. The method according to any one of claims 1 to 6, characterized in that The method further comprises: According to the interface information of the underlying artificial intelligence big model configured by the user, the factory mode and strategy mode are adopted to dynamically select and create the corresponding model application interface adapter, and generate the corresponding request parameter object according to the interface specification of the model application interface adapter. The request parameter object includes the model identifier, code body content, context code content and role prompt description content.

8. A code review system based on GitLab, characterized in that: The system specifically comprises: The first review module is used to obtain the MR request submitted by the user, obtain all code files and meta information of all code files corresponding to the MR request through the GitLab API interface based on the ID information of the MR request, and generate a code file object list according to the meta information; A second audit module is used to perform symbolic processing and abstract syntax tree construction on each code file object in the code file object list, obtain code syntax structure information, and construct a code semantic dependency graph according to the code syntax structure information; A third audit module is used to determine the code problems in all code files based on the code semantic dependency graph and form a code analysis report, and modify the defective code content according to the code analysis report; A fourth audit module is used to obtain the modified current code content, and based on the code semantic dependency graph, determine the context code content with direct function call relationship or indirect function call relationship for the current code content through a depth-first search algorithm; The fifth audit module is used to desensitize the code content and comment information containing sensitive information in all code files according to the sensitive information keyword list configured by the business; The sixth audit module is used to obtain the number of tokens consumed by each MR request responded to by the underlying artificial intelligence big model interface, calculate the resource consumption of the underlying artificial intelligence big model based on the number of tokens, and push alarms and cut off calls when the number of tokens reaches a preset consumption threshold.

9. A computer device, characterized in that: include: A memory, a processor, and a computer program stored in the memory. When the computer program is executed on the processor, the method for code review based on GitLab as claimed in any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor, the code review method based on GitLab is implemented as described in any one of claims 1 to 7.

Citation Information

Cited By

  • Visual front-end code quality detection method and device and computer storage medium

    CN118916296A

  • Android application energy consumption evaluation method oriented to code reconstruction

    CN119201719A

  • Android application energy consumption evaluation method for code refactoring

    CN119201719B

  • Automatic code inspection system, method and equipment based on AI large model and medium

    CN119576392A

  • An AI large model-based automatic code review system, method, device and medium

    CN119576392B