Incremental code quality detection method, device, equipment and storage medium
By extracting the benchmark branch code and feature branch code, merging and detecting the code, and combining the change file list filtering and positioning incremental code information, the problem of taking into account both the efficiency and accuracy of incremental code detection is solved, and efficient and accurate quality detection is achieved.
Patent Information
- Application Number
- CN202210594801.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-27
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2042-05-27
AI Technical Summary
When performing quality inspection of incremental codes, the inspection efficiency and accuracy cannot be taken into account, which affects the development of R&D projects.
An incremental code quality detection method is proposed. By receiving code merging operation requests, the benchmark branch code and feature branch code are extracted, the change file list is obtained, the code is merged, and the incremental code information is measured based on the change file list, and the quality detection results are generated.
It improves the detection efficiency and accuracy of incremental code, avoids the code incompatibility between incremental code and benchmark branch code, and enhances the accuracy and completeness of quality detection results.
Smart Images

Figure CN114896162B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of code verification technology, and in particular to an incremental code quality detection method, device, equipment and storage medium. Background Art
[0002] With the development of artificial intelligence, by detecting common vulnerabilities and code specification issues in the code, problems in the code can be discovered early in order to improve the code quality. At present, the inventors realize that when performing quality inspection on incremental code, it is impossible to take into account both the detection efficiency and detection accuracy of the incremental code, which is not conducive to the development of R&D projects.
[0003] Therefore, how to build an accurate incremental code quality detection solution and improve detection efficiency has become a technical problem to be solved. Summary of the invention
[0004] In view of the above, it is necessary to provide an incremental code quality detection method, device, equipment and storage medium, which can not only improve the detection efficiency of incremental code, but also improve the detection accuracy.
[0005] In one aspect, the present invention provides an incremental code quality detection method, the incremental code quality detection method comprising:
[0006] Receive a code merge operation request, and extract a baseline branch code and a feature branch code according to the code merge operation request;
[0007] Obtain a list of changed files of the feature branch code;
[0008] Merge the reference branch code and the feature branch code according to the change file list to obtain a target branch code;
[0009] Perform code detection on the target branch code to obtain a code scanning result;
[0010] Filtering incremental code information from the feature branch code based on the change file list;
[0011] Locating the information position of the incremental code information in the target branch code;
[0012] A quality detection result of the incremental code information is generated according to the information position and the code scanning result.
[0013] According to a preferred embodiment of the present invention, extracting the reference branch code and the feature branch code according to the code merging operation request includes:
[0014] Parsing the message of the code merge operation request to obtain data information carried in the message;
[0015] Extracting a system identification code of the research and development system from the data information;
[0016] Obtaining the time at which the code merge operation request is received;
[0017] Filtering a plurality of system codes corresponding to the system identification code from a preset code library, and obtaining a generation time of each system code;
[0018] Determine the generated time with the smallest time difference from the receiving time as the target time, and determine the system code corresponding to the target time as the reference branch code;
[0019] Detecting a research and development user of the benchmark branch code, and obtaining a binding path corresponding to the research and development user;
[0020] The code information with the smallest time difference from the target time is obtained from the binding path as the feature branch code.
[0021] According to a preferred embodiment of the present invention, performing code detection on the target branch code to obtain a code scanning result includes:
[0022] Detecting the code type of the target branch code;
[0023] If the code type is a compiled type, compile the target branch code based on the code type to obtain a compiled code;
[0024] A code scanning tool is called to scan the compiled code to obtain the code scanning result.
[0025] According to a preferred embodiment of the present invention, filtering incremental code information from the feature branch code based on the change file list includes:
[0026] Acquire function information corresponding to the preset operation from the change file list as the function to be tested;
[0027] Parsing the feature branch code to obtain a matching relationship between multiple configuration functions and function codes;
[0028] A function code corresponding to the function to be tested is obtained according to the matching relationship as the incremental code information.
[0029] According to a preferred embodiment of the present invention, locating the information position of the incremental code information in the target branch code includes:
[0030] Writing the incremental code information into a preset template to obtain a code regular expression;
[0031] Traversing the target branch code based on the code regular expression;
[0032] Determine the information in the target branch code that successfully matches the code regular expression as the code to be located;
[0033] The line number of the code to be located is obtained from the target branch code as the information location.
[0034] According to a preferred embodiment of the present invention, generating the quality detection result of the incremental code information according to the information position and the code scanning result includes:
[0035] Extracting the target location of the problematic code in the target branch code from the code scanning result based on the preset tag;
[0036] comparing the target location with the information location;
[0037] Determine the target position that is the same as the information position as the problem position where the problem code in the incremental code information is located;
[0038] Extracting information corresponding to the problem location from the code scanning result as the problem vulnerability;
[0039] The quality inspection result is generated according to the problem location and the problem vulnerability.
[0040] According to a preferred embodiment of the present invention, the method further comprises:
[0041] Detect the vulnerability type of the problematic vulnerability;
[0042] Obtaining a solution method corresponding to the vulnerability type and the processing difficulty of the solution method from a preset solution library;
[0043] Rendering the solution according to the degree of difficulty of the processing to obtain display information;
[0044] Obtaining an operation interface for the code merging operation request;
[0045] The display information and the quality inspection results are displayed based on the operation interface.
[0046] On the other hand, the present invention further provides an incremental code quality detection device, the incremental code quality detection device comprising:
[0047] An extraction unit, configured to receive a code merge operation request, and extract a baseline branch code and a feature branch code according to the code merge operation request;
[0048] An acquisition unit, used to acquire a list of changed files of the feature branch code;
[0049] A merging unit, configured to merge the reference branch code and the feature branch code according to the change file list to obtain a target branch code;
[0050] A detection unit, used to perform code detection on the target branch code to obtain a code scanning result;
[0051] A screening unit, configured to screen incremental code information from the feature branch code based on the change file list;
[0052] A positioning unit, used to locate the information position of the incremental code information in the target branch code;
[0053] A generating unit is used to generate a quality detection result of the incremental code information according to the information position and the code scanning result.
[0054] On the other hand, the present invention further provides an electronic device, comprising:
[0055] a memory storing computer readable instructions; and
[0056] A processor executes the computer-readable instructions stored in the memory to implement the incremental code quality detection method.
[0057] On the other hand, the present invention further proposes a computer-readable storage medium, in which computer-readable instructions are stored. The computer-readable instructions are executed by a processor in an electronic device to implement the incremental code quality detection method.
[0058] It can be seen from the above technical solutions that the present invention can accurately generate the target branch code of the baseline branch code and the feature branch code based on the change file list, and then perform code detection on the target branch code globally, and then combine the code scanning result of the target branch code and the information position of the incremental code information in the target branch code to accurately filter out the quality detection result of the incremental code information from the code scanning result, instead of directly performing code detection on the incremental code information, which can avoid the situation where the incremental code information and the baseline branch code are incompatible and cannot be mined, thereby improving the accuracy and completeness of the quality detection result. In addition, the present invention does not need to repeatedly scan and detect the baseline branch code, so it can improve the efficiency of obtaining the incremental code information, thereby improving the efficiency of generating the quality detection result. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] Figure 1 It is a flow chart of a preferred embodiment of the incremental code quality detection method of the present invention.
[0060] Figure 2It is a functional module diagram of a preferred embodiment of the incremental code quality detection device of the present invention.
[0061] Figure 3 It is a structural schematic diagram of an electronic device of a preferred embodiment of the incremental code quality detection method of the present invention. DETAILED DESCRIPTION
[0062] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention is described in detail below with reference to the accompanying drawings and specific embodiments.
[0063] like Figure 1 FIG. 1 is a flowchart of a preferred embodiment of the incremental code quality detection method of the present invention. According to different requirements, the order of the steps in the flowchart can be changed, and some steps can be omitted.
[0064] The incremental code quality detection method can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0065] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0066] The incremental code quality detection method is applied to one or more electronic devices, which are devices that can automatically perform numerical calculations and / or information processing according to pre-set or stored computer-readable instructions, and whose hardware includes but is not limited to microprocessors, application specific integrated circuits (ASIC), programmable gate arrays (FPGA), digital signal processors (DSP), embedded devices, etc.
[0067] The electronic device may be any electronic product that can perform human-computer interaction with a user, such as a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), a game console, an interactive network television (IPTV), a smart wearable device, etc.
[0068] The electronic device may include a network device and / or a user device. The network device includes, but is not limited to, a single network electronic device, an electronic device group consisting of multiple network electronic devices, or a cloud consisting of a large number of hosts or network electronic devices based on cloud computing.
[0069] The network where the electronic device is located includes, but is not limited to: the Internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (VPN), etc.
[0070] S10, receiving a code merging operation request, and extracting a baseline branch code and a feature branch code according to the code merging operation request.
[0071] In at least one embodiment of the present invention, the code merging operation request carries relevant information of the R&D system that needs to perform code detection. The code merging operation request may be triggered and generated by a developer who develops the R&D system.
[0072] The reference branch code refers to the existing functional code in the research and development system, and the feature branch code refers to the code newly developed by the research and development personnel.
[0073] In at least one embodiment of the present invention, the electronic device extracting the reference branch code and the feature branch code according to the code merge operation request includes:
[0074] Parsing the message of the code merge operation request to obtain data information carried in the message;
[0075] Extracting a system identification code of the research and development system from the data information;
[0076] Obtaining the time at which the code merge operation request is received;
[0077] Filtering a plurality of system codes corresponding to the system identification code from a preset code library, and obtaining a generation time of each system code;
[0078] Determine the generated time with the smallest time difference from the receiving time as the target time, and determine the system code corresponding to the target time as the reference branch code;
[0079] Detecting a research and development user of the benchmark branch code, and obtaining a binding path corresponding to the research and development user;
[0080] The code information with the smallest time difference from the target time is obtained from the binding path as the feature branch code.
[0081] The data information stores information related to the R&D system, for example, the data information stores the system identification code and the like.
[0082] The preset code library stores code information of multiple systems. It is understandable that each system corresponds to different codes generated at multiple times. For example, the preset code library stores (system A, time: 10.30, version V1 code) and (the system A, time: 10.31, version V2 code) and so on.
[0083] The benchmark branch code refers to the code information of the latest released version in the research and development system.
[0084] The R&D users refer to the R&D personnel of the R&D system.
[0085] The binding path refers to the storage location of the code generated when the R&D user updates the R&D system.
[0086] Through the system identification code and the receiving time, the benchmark branch code can be quickly and accurately screened out from the preset code library, and then according to the research and development user of the benchmark branch code, the binding path can be accurately determined, so that according to the target time, the feature branch code can be accurately obtained from the binding path.
[0087] S11, obtaining a list of changed files of the feature branch code.
[0088] In at least one embodiment of the present invention, the change file list stores relevant information of code addition operations, code deletion operations, and code modification operations performed on the reference branch code.
[0089] In at least one embodiment of the present invention, the electronic device obtaining the list of changed files of the feature branch code includes:
[0090] Obtaining a code identifier of the feature branch code;
[0091] Traversing the list names of all lists in the preset file library based on the code identifier;
[0092] The list corresponding to the list name containing the code identifier is determined as the changed file list.
[0093] The code identifier is used to represent the feature branch code.
[0094] The preset file library stores a plurality of lists.
[0095] The changed file list can be quickly acquired from the preset file library through the code identifier.
[0096] S12, merging the reference branch code and the feature branch code according to the change file list to obtain a target branch code.
[0097] In at least one embodiment of the present invention, the target branch code refers to code information obtained by merging the reference branch code and the feature branch code.
[0098] In at least one embodiment of the present invention, the electronic device merges the reference branch code and the feature branch code according to the change file list to obtain the target branch code, including:
[0099] Obtaining the operation time of each change operation from the change file list;
[0100] Selecting a target operation from the list of changed files according to the order of the operation time from small to large;
[0101] The reference branch code and the characteristic branch code are processed based on the target operation to obtain the target branch code.
[0102] The operation time refers to the time when the change operation is executed.
[0103] The target operation may include a deletion operation, a change operation, an addition operation, and the like.
[0104] The reference branch code and the characteristic branch code can be accurately processed through the operation time, thereby improving the accuracy of the target branch code.
[0105] S13, performing code detection on the target branch code to obtain a code scanning result.
[0106] In at least one embodiment of the present invention, the code scanning result refers to the result generated after detecting the target branch code for syntax vulnerabilities and code specifications.
[0107] In at least one embodiment of the present invention, the electronic device performs code detection on the target branch code, and obtaining the code scanning result includes:
[0108] Detecting the code type of the target branch code;
[0109] If the code type is a compiled type, compile the target branch code based on the code type to obtain a compiled code;
[0110] A code scanning tool is called to scan the compiled code to obtain the code scanning result.
[0111] The code types include compiled and uncompiled types.
[0112] The compiled code refers to the code generated after compiling the target branch code. Taking Java language as an example, Maven corresponding to Java language is used for compilation. The compiled file address is replaced from the original "src / main / java / " path to the "target / classes / " path, and the suffix is replaced from the original ".java" to ".class".
[0113] The code scanning tool refers to a scanning tool used to detect problems such as syntax vulnerabilities and code specifications in the code. For example, the code scanning tool can be a sonarqube tool.
[0114] By performing type detection on the target branch code, it is possible to quickly identify whether the target branch code needs to be compiled, and then call the code scanning tool to scan the compiled code to obtain the code scanning results existing in the target branch code.
[0115] In at least one embodiment of the present invention, if the code type is a non-compiled type, the electronic device calls the code scanning tool to scan the target branch code to obtain the code scanning result.
[0116] S14, filtering incremental code information from the feature branch code based on the changed file list.
[0117] In at least one embodiment of the present invention, the incremental code information refers to code information corresponding to a preset operation in the feature branch code, wherein the preset operation includes a code addition operation and a code modification operation.
[0118] In this embodiment, since the code information corresponding to the deletion operation does not exist in the target branch code, there is no need to analyze the code information corresponding to the deletion operation.
[0119] In at least one embodiment of the present invention, the electronic device filtering the incremental code information from the feature branch code based on the change file list includes:
[0120] Acquire function information corresponding to the preset operation from the change file list as the function to be tested;
[0121] Parsing the feature branch code to obtain a matching relationship between multiple configuration functions and function codes;
[0122] A function code corresponding to the function to be tested is obtained according to the matching relationship as the incremental code information.
[0123] The multiple configuration functions include a new function, a modification function and a deletion function of the R&D system.
[0124] Through the preset operation, the function to be tested can be accurately obtained from the change file list, and then by parsing the feature branch code, the matching relationship can be fully obtained, so that the incremental code information corresponding to the function to be tested can be accurately extracted using the matching relationship.
[0125] S15, locating the information position of the incremental code information in the target branch code.
[0126] In at least one embodiment of the present invention, the information location is a specific location of the incremental code information in the target branch code, for example, the information location may be lines 100-120.
[0127] In at least one embodiment of the present invention, the electronic device locates the information position of the incremental code information in the target branch code, including:
[0128] Writing the incremental code information into a preset template to obtain a code regular expression;
[0129] Traversing the target branch code based on the code regular expression;
[0130] Determine the information in the target branch code that successfully matches the code regular expression as the code to be located;
[0131] The line number of the code to be located is obtained from the target branch code as the information location.
[0132] The preset template refers to a regular expression whose matching object is empty.
[0133] The code to be located refers to the code in the target branch code that is identical to the incremental code information.
[0134] The code regular expression generated by the incremental code information can accurately match the code to be located from the target branch code, and then the information position can be quickly determined by using the position of the code to be located in the target branch code.
[0135] S16, generating a quality detection result of the incremental code information according to the information position and the code scanning result.
[0136] In at least one embodiment of the present invention, the quality detection result is a result generated after performing syntax problem detection on the incremental code information.
[0137] It should be emphasized that in order to further ensure the privacy and security of the above-mentioned quality inspection results, the above-mentioned quality inspection results can also be stored in a blockchain node.
[0138] In at least one embodiment of the present invention, the electronic device generates a quality detection result of the incremental code information according to the information position and the code scanning result, including:
[0139] Extracting the target location of the problematic code in the target branch code from the code scanning result based on the preset tag;
[0140] comparing the target location with the information location;
[0141] Determine the target position that is the same as the information position as the problem position where the problem code in the incremental code information is located;
[0142] Extracting information corresponding to the problem location from the code scanning result as the problem vulnerability;
[0143] The quality inspection result is generated according to the problem location and the problem vulnerability.
[0144] The preset label is used to indicate the row number position.
[0145] The target position may include the position of the problem code in the reference branch code and the position of the problem code in the incremental code information.
[0146] For example, the code in lines 2-4 of the target branch code is newly added code, and the code in lines 6-8 of the target branch code is modified code, then the information location is: lines 2-4 and lines 6-8. After detection, the target location of the problematic code in the target branch code is: lines 5-7. After comparing the target location with the information, the problem location is: lines 6-7.
[0147] By comparing the target position with the information position, the problem position can be accurately determined, and then the quality detection result can be accurately generated based on the problem position.
[0148] In at least one embodiment of the present invention, the method further comprises:
[0149] Detect the vulnerability type of the problematic vulnerability;
[0150] Obtaining a solution method corresponding to the vulnerability type and the processing difficulty of the solution method from a preset solution library;
[0151] Rendering the solution according to the degree of difficulty of the processing to obtain display information;
[0152] Obtaining an operation interface for the code merging operation request;
[0153] The display information and the quality inspection results are displayed based on the operation interface.
[0154] The vulnerability types may include: code specifications, grammatical structures, etc.
[0155] The preset method library stores mapping relationships between multiple types and processing methods, as well as the processing difficulty corresponding to each processing method, wherein the processing difficulty is determined based on the annotation information of multiple R&D users.
[0156] The solution and the degree of difficulty of handling can be quickly obtained through the vulnerability type, and then the solution can be rendered according to the degree of difficulty of handling, which can improve the intuitiveness of the displayed information. Furthermore, by displaying the displayed information and the quality inspection results in the operation interface, the user responsible for the code merge operation request can quickly understand the execution status of the code merge operation request.
[0157] It can be seen from the above technical solutions that the present invention can accurately generate the target branch code of the baseline branch code and the feature branch code based on the change file list, and then perform code detection on the target branch code globally, and then combine the code scanning result of the target branch code and the information position of the incremental code information in the target branch code to accurately filter out the quality detection result of the incremental code information from the code scanning result, instead of directly performing code detection on the incremental code information, which can avoid the situation where the incremental code information and the baseline branch code are incompatible and cannot be mined, thereby improving the accuracy and completeness of the quality detection result. In addition, the present invention does not need to repeatedly scan and detect the baseline branch code, so it can improve the efficiency of obtaining the incremental code information, thereby improving the efficiency of generating the quality detection result.
[0158] like Figure 2 As shown, it is a functional module diagram of a preferred embodiment of the incremental code quality detection device of the present invention. The incremental code quality detection device 11 includes an extraction unit 110, an acquisition unit 111, a merging unit 112, a detection unit 113, a screening unit 114, a positioning unit 115, a generation unit 116, a rendering unit 117 and a display unit 118. The module / unit referred to in the present invention refers to a series of computer-readable instruction segments that can be acquired by the processor 13 and can complete fixed functions, which are stored in the memory 12. In this embodiment, the functions of each module / unit will be described in detail in subsequent embodiments.
[0159] The extraction unit 110 receives a code merging operation request, and extracts a reference branch code and a feature branch code according to the code merging operation request.
[0160] In at least one embodiment of the present invention, the code merging operation request carries relevant information of the R&D system that needs to perform code detection. The code merging operation request may be triggered and generated by a developer who develops the R&D system.
[0161] The reference branch code refers to the existing functional code in the research and development system, and the feature branch code refers to the code newly developed by the research and development personnel.
[0162] In at least one embodiment of the present invention, the extracting unit 110 extracts the reference branch code and the feature branch code according to the code merging operation request, including:
[0163] Parsing the message of the code merge operation request to obtain data information carried in the message;
[0164] Extracting a system identification code of the research and development system from the data information;
[0165] Obtaining the time at which the code merge operation request is received;
[0166] Filtering a plurality of system codes corresponding to the system identification code from a preset code library, and obtaining a generation time of each system code;
[0167] Determine the generated time with the smallest time difference from the receiving time as the target time, and determine the system code corresponding to the target time as the reference branch code;
[0168] Detecting a research and development user of the benchmark branch code, and obtaining a binding path corresponding to the research and development user;
[0169] The code information with the smallest time difference from the target time is obtained from the binding path as the feature branch code.
[0170] The data information stores information related to the R&D system, for example, the data information stores the system identification code and the like.
[0171] The preset code library stores code information of multiple systems. It is understandable that each system corresponds to different codes generated at multiple times. For example, the preset code library stores (system A, time: 10.30, version V1 code) and (the system A, time: 10.31, version V2 code) and so on.
[0172] The benchmark branch code refers to the code information of the latest released version in the research and development system.
[0173] The R&D users refer to the R&D personnel of the R&D system.
[0174] The binding path refers to the storage location of the code generated when the R&D user updates the R&D system.
[0175] Through the system identification code and the receiving time, the benchmark branch code can be quickly and accurately screened out from the preset code library, and then according to the research and development user of the benchmark branch code, the binding path can be accurately determined, so that according to the target time, the feature branch code can be accurately obtained from the binding path.
[0176] The acquiring unit 111 acquires a list of changed files of the feature branch code.
[0177] In at least one embodiment of the present invention, the change file list stores relevant information of code addition operations, code deletion operations, and code modification operations performed on the reference branch code.
[0178] In at least one embodiment of the present invention, the acquiring unit 111 acquires the change file list of the feature branch code including:
[0179] Obtaining a code identifier of the feature branch code;
[0180] Traversing the list names of all lists in the preset file library based on the code identifier;
[0181] The list corresponding to the list name containing the code identifier is determined as the changed file list.
[0182] The code identifier is used to represent the feature branch code.
[0183] The preset file library stores a plurality of lists.
[0184] The changed file list can be quickly acquired from the preset file library through the code identifier.
[0185] The merging unit 112 merges the reference branch code and the feature branch code according to the change file list to obtain a target branch code.
[0186] In at least one embodiment of the present invention, the target branch code refers to code information obtained by merging the reference branch code and the feature branch code.
[0187] In at least one embodiment of the present invention, the merging unit 112 merges the reference branch code and the feature branch code according to the change file list to obtain the target branch code, which includes:
[0188] Obtaining the operation time of each change operation from the change file list;
[0189] Selecting a target operation from the list of changed files according to the order of the operation time from small to large;
[0190] The reference branch code and the characteristic branch code are processed based on the target operation to obtain the target branch code.
[0191] The operation time refers to the time when the change operation is executed.
[0192] The target operation may include a deletion operation, a change operation, an addition operation, and the like.
[0193] The reference branch code and the characteristic branch code can be accurately processed through the operation time, thereby improving the accuracy of the target branch code.
[0194] The detection unit 113 performs code detection on the target branch code to obtain a code scanning result.
[0195] In at least one embodiment of the present invention, the code scanning result refers to the result generated after detecting the target branch code for syntax vulnerabilities and code specifications.
[0196] In at least one embodiment of the present invention, the detection unit 113 performs code detection on the target branch code, and the code scanning result obtained includes:
[0197] Detecting the code type of the target branch code;
[0198] If the code type is a compiled type, compile the target branch code based on the code type to obtain a compiled code;
[0199] A code scanning tool is called to scan the compiled code to obtain the code scanning result.
[0200] The code types include compiled and uncompiled types.
[0201] The compiled code refers to the code generated after compiling the target branch code. Taking Java language as an example, Maven corresponding to Java language is used for compilation. The compiled file address is replaced from the original "src / main / java / " path to the "target / classes / " path, and the suffix is replaced from the original ".java" to ".class".
[0202] The code scanning tool refers to a scanning tool used to detect problems such as syntax vulnerabilities and code specifications in the code. For example, the code scanning tool can be a sonarqube tool.
[0203] By performing type detection on the target branch code, it is possible to quickly identify whether the target branch code needs to be compiled, and then call the code scanning tool to scan the compiled code to obtain the code scanning results existing in the target branch code.
[0204] In at least one embodiment of the present invention, if the code type is a non-compiled type, the detection unit 113 calls the code scanning tool to scan the target branch code to obtain the code scanning result.
[0205] The screening unit 114 screens the incremental code information from the feature branch code based on the changed file list.
[0206] In at least one embodiment of the present invention, the incremental code information refers to code information corresponding to a preset operation in the feature branch code, wherein the preset operation includes a code addition operation and a code modification operation.
[0207] In this embodiment, since the code information corresponding to the deletion operation does not exist in the target branch code, there is no need to analyze the code information corresponding to the deletion operation.
[0208] In at least one embodiment of the present invention, the screening unit 114 screens the incremental code information from the feature branch code based on the change file list, including:
[0209] Acquire function information corresponding to the preset operation from the change file list as the function to be tested;
[0210] Parsing the feature branch code to obtain a matching relationship between multiple configuration functions and function codes;
[0211] A function code corresponding to the function to be tested is obtained according to the matching relationship as the incremental code information.
[0212] The multiple configuration functions include a new function, a modification function and a deletion function of the R&D system.
[0213] Through the preset operation, the function to be tested can be accurately obtained from the change file list, and then by parsing the feature branch code, the matching relationship can be fully obtained, so that the incremental code information corresponding to the function to be tested can be accurately extracted using the matching relationship.
[0214] The positioning unit 115 locates the information position of the incremental code information in the target branch code.
[0215] In at least one embodiment of the present invention, the information location is a specific location of the incremental code information in the target branch code, for example, the information location may be lines 100-120.
[0216] In at least one embodiment of the present invention, the positioning unit 115 locates the information position of the incremental code information in the target branch code, including:
[0217] Writing the incremental code information into a preset template to obtain a code regular expression;
[0218] Traversing the target branch code based on the code regular expression;
[0219] Determine the information in the target branch code that successfully matches the code regular expression as the code to be located;
[0220] The line number of the code to be located is obtained from the target branch code as the information location.
[0221] The preset template refers to a regular expression whose matching object is empty.
[0222] The code to be located refers to the code in the target branch code that is identical to the incremental code information.
[0223] The code regular expression generated by the incremental code information can accurately match the code to be located from the target branch code, and then the information position can be quickly determined by using the position of the code to be located in the target branch code.
[0224] The generating unit 116 generates a quality detection result of the incremental code information according to the information position and the code scanning result.
[0225] In at least one embodiment of the present invention, the quality detection result is a result generated after performing syntax problem detection on the incremental code information.
[0226] It should be emphasized that in order to further ensure the privacy and security of the above-mentioned quality inspection results, the above-mentioned quality inspection results can also be stored in a blockchain node.
[0227] In at least one embodiment of the present invention, the generating unit 116 generates the quality detection result of the incremental code information according to the information position and the code scanning result, including:
[0228] Extracting the target location of the problematic code in the target branch code from the code scanning result based on the preset tag;
[0229] comparing the target location with the information location;
[0230] Determine the target position that is the same as the information position as the problem position where the problem code in the incremental code information is located;
[0231] Extracting information corresponding to the problem location from the code scanning result as the problem vulnerability;
[0232] The quality inspection result is generated according to the problem location and the problem vulnerability.
[0233] The preset label is used to indicate the row number position.
[0234] The target position may include the position of the problem code in the reference branch code and the position of the problem code in the incremental code information.
[0235] For example, the code in lines 2-4 of the target branch code is newly added code, and the code in lines 6-8 of the target branch code is modified code, then the information location is: lines 2-4 and lines 6-8. After detection, the target location of the problematic code in the target branch code is: lines 5-7. After comparing the target location with the information, the problem location is: lines 6-7.
[0236] By comparing the target position with the information position, the problem position can be accurately determined, and then the quality detection result can be accurately generated based on the problem position.
[0237] In at least one embodiment of the present invention, the detection unit 113 detects the vulnerability type of the problematic vulnerability;
[0238] The acquisition unit 111 acquires a solution method corresponding to the vulnerability type and a processing difficulty level of the solution method from a preset solution library;
[0239] The rendering unit 117 renders the solution according to the processing difficulty to obtain display information;
[0240] The acquisition unit 111 acquires the operation interface of the code merging operation request;
[0241] The display unit 118 displays the display information and the quality inspection result based on the operation interface.
[0242] The vulnerability types may include: code specifications, grammatical structures, etc.
[0243] The preset method library stores mapping relationships between multiple types and processing methods, as well as the processing difficulty corresponding to each processing method, wherein the processing difficulty is determined based on the annotation information of multiple R&D users.
[0244] The solution and the degree of difficulty of handling can be quickly obtained through the vulnerability type, and then the solution can be rendered according to the degree of difficulty of handling, which can improve the intuitiveness of the displayed information. Furthermore, by displaying the displayed information and the quality inspection results in the operation interface, the user responsible for the code merge operation request can quickly understand the execution status of the code merge operation request.
[0245] It can be seen from the above technical solutions that the present invention can accurately generate the target branch code of the baseline branch code and the feature branch code based on the change file list, and then perform code detection on the target branch code globally, and then combine the code scanning result of the target branch code and the information position of the incremental code information in the target branch code to accurately filter out the quality detection result of the incremental code information from the code scanning result, instead of directly performing code detection on the incremental code information, which can avoid the situation where the incremental code information and the baseline branch code are incompatible and cannot be mined, thereby improving the accuracy and completeness of the quality detection result. In addition, the present invention does not need to repeatedly scan and detect the baseline branch code, so it can improve the efficiency of obtaining the incremental code information, thereby improving the efficiency of generating the quality detection result.
[0246] like Figure 3 , which is a schematic diagram of the structure of an electronic device of a preferred embodiment of the incremental code quality detection method of the present invention.
[0247] In one embodiment of the present invention, the electronic device 1 includes, but is not limited to, a memory 12, a processor 13, and computer-readable instructions stored in the memory 12 and executable on the processor 13, such as an incremental code quality detection program.
[0248] Those skilled in the art will understand that the schematic diagram is merely an example of the electronic device 1 and does not constitute a limitation on the electronic device 1. The electronic device 1 may include more or fewer components than shown in the diagram, or a combination of certain components, or different components. For example, the electronic device 1 may also include input and output devices, network access devices, buses, etc.
[0249] The processor 13 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. The processor 13 is the computing core and control center of the electronic device 1, and uses various interfaces and lines to connect various parts of the entire electronic device 1, and executes the operating system of the electronic device 1 and various installed applications, program codes, etc.
[0250] Exemplarily, the computer-readable instructions may be divided into one or more modules / units, which are stored in the memory 12 and executed by the processor 13 to complete the present invention. The one or more modules / units may be a series of computer-readable instruction segments capable of completing specific functions, which are used to describe the execution process of the computer-readable instructions in the electronic device 1. For example, the computer-readable instructions may be divided into an extraction unit 110, an acquisition unit 111, a merging unit 112, a detection unit 113, a screening unit 114, a positioning unit 115, a generation unit 116, a rendering unit 117, and a display unit 118.
[0251] The memory 12 can be used to store the computer-readable instructions and / or modules, and the processor 13 implements various functions of the electronic device 1 by running or executing the computer-readable instructions and / or modules stored in the memory 12, and calling the data stored in the memory 12. The memory 12 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the electronic device, etc. The memory 12 can include non-volatile and volatile memories, such as: a hard disk, a memory, a plug-in hard disk, a smart memory card (SmartMedia Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other storage devices.
[0252] The memory 12 may be an external memory and / or an internal memory of the electronic device 1. Furthermore, the memory 12 may be a memory in a physical form, such as a memory stick, a TF card (Trans-flash Card), and the like.
[0253] If the module / unit integrated in the electronic device 1 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 invention implements all or part of the processes in the above-mentioned embodiment method, and can also instruct the relevant hardware to complete it through computer-readable instructions. The computer-readable instructions can be stored in a computer-readable storage medium. When the computer-readable instructions are executed by the processor, the steps of the above-mentioned various method embodiments can be implemented.
[0254] The computer-readable instructions include computer-readable instruction codes, which may be in source code form, object code form, executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer-readable instruction code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM).
[0255] The blockchain referred to in this invention is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0256] Combination Figure 1 The memory 12 in the electronic device 1 stores computer-readable instructions to implement an incremental code quality detection method, and the processor 13 can execute the computer-readable instructions to implement:
[0257] Receive a code merge operation request, and extract a baseline branch code and a feature branch code according to the code merge operation request;
[0258] Obtain a list of changed files of the feature branch code;
[0259] Merge the reference branch code and the feature branch code according to the change file list to obtain a target branch code;
[0260] Perform code detection on the target branch code to obtain a code scanning result;
[0261] Filtering incremental code information from the feature branch code based on the change file list;
[0262] Locating the information position of the incremental code information in the target branch code;
[0263] A quality detection result of the incremental code information is generated according to the information position and the code scanning result.
[0264] Specifically, the specific implementation method of the processor 13 for the above-mentioned computer readable instructions can refer to Figure 1 The description of the relevant steps in the corresponding embodiments will not be repeated here.
[0265] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only illustrative, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.
[0266] The computer-readable storage medium stores computer-readable instructions, wherein the computer-readable instructions are used to implement the following steps when executed by the processor 13:
[0267] Receive a code merge operation request, and extract a baseline branch code and a feature branch code according to the code merge operation request;
[0268] Obtain a list of changed files of the feature branch code;
[0269] Merge the reference branch code and the feature branch code according to the change file list to obtain a target branch code;
[0270] Perform code detection on the target branch code to obtain a code scanning result;
[0271] Filtering incremental code information from the feature branch code based on the change file list;
[0272] Locating the information position of the incremental code information in the target branch code;
[0273] A quality detection result of the incremental code information is generated according to the information position and the code scanning result.
[0274] The modules described as separate components may or may not be physically separated, and the components shown as modules 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 modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0275] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0276] Therefore, no matter from which point of view, the embodiments should be regarded as illustrative and non-restrictive, and the scope of the present invention is limited by the appended claims rather than the above description, so it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any attached figure mark in the claims should not be regarded as limiting the claims involved.
[0277] In addition, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. The multiple units or devices mentioned can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.
[0278] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.
Claims
1. An incremental code quality detection method, characterized in that: The incremental code quality detection method comprises: Receiving a code merge operation request, and extracting a baseline branch code and a feature branch code according to the code merge operation request, including: parsing a message of the code merge operation request to obtain data information carried by the message; extracting a system identification code of the R&D system from the data information; obtaining the reception time of the code merge operation request; screening a plurality of system codes corresponding to the system identification code from a preset code library, and obtaining the generation time of each system code; determining the generation time with the smallest time difference from the reception time as the target time, and determining the system code corresponding to the target time as the baseline branch code; detecting a R&D user of the baseline branch code, and obtaining a binding path corresponding to the R&D user; obtaining the code information with the smallest time difference from the target time from the binding path as the feature branch code; Obtain a list of changed files of the feature branch code; Merge the reference branch code and the feature branch code according to the change file list to obtain a target branch code; Perform code detection on the target branch code to obtain a code scanning result; Filtering incremental code information from the feature branch code based on the change file list; Locating the information position of the incremental code information in the target branch code; The quality inspection result of the incremental code information is generated according to the information position and the code scanning result, including: extracting the target position of the problematic code in the target branch code from the code scanning result based on a preset label; comparing the target position with the information position; determining the target position that is the same as the information position as the problem position of the problematic code in the incremental code information; extracting information corresponding to the problem position from the code scanning result as a problem vulnerability; and generating the quality inspection result according to the problem position and the problem vulnerability.
2. The incremental code quality detection method according to claim 1, characterized in that: The performing code detection on the target branch code to obtain a code scanning result includes: Detecting the code type of the target branch code; If the code type is a compiled type, compile the target branch code based on the code type to obtain a compiled code; A code scanning tool is called to scan the compiled code to obtain the code scanning result.
3. The incremental code quality detection method according to claim 1, characterized in that: The filtering of incremental code information from the feature branch code based on the change file list includes: Acquire function information corresponding to the preset operation from the change file list as the function to be tested; Parsing the feature branch code to obtain a matching relationship between multiple configuration functions and function codes; A function code corresponding to the function to be tested is obtained according to the matching relationship as the incremental code information.
4. The incremental code quality detection method according to claim 1, characterized in that: The locating the information position of the incremental code information in the target branch code includes: Writing the incremental code information into a preset template to obtain a code regular expression; Traversing the target branch code based on the code regular expression; Determine the information in the target branch code that successfully matches the code regular expression as the code to be located; The line number of the code to be located is obtained from the target branch code as the information location.
5. The incremental code quality detection method according to claim 1, characterized in that: The method further comprises: Detect the vulnerability type of the problematic vulnerability; Obtaining a solution method corresponding to the vulnerability type and the processing difficulty of the solution method from a preset solution library; Rendering the solution according to the degree of difficulty of the processing to obtain display information; Obtaining an operation interface for the code merging operation request; The display information and the quality inspection results are displayed based on the operation interface.
6. An incremental code quality detection device, characterized in that: The incremental code quality detection device comprises: An extraction unit is used to receive a code merge operation request, and extract a baseline branch code and a feature branch code according to the code merge operation request, including: parsing a message of the code merge operation request to obtain data information carried by the message; extracting a system identification code of the R&D system from the data information; obtaining a reception time of the code merge operation request; screening a plurality of system codes corresponding to the system identification code from a preset code library, and obtaining a generation time of each system code; determining a generation time with a minimum time difference from the reception time as a target time, and determining a system code corresponding to the target time as the baseline branch code; detecting a R&D user of the baseline branch code, and obtaining a binding path corresponding to the R&D user; obtaining code information with a minimum time difference from the target time from the binding path as the feature branch code; An acquisition unit, used to acquire a list of changed files of the feature branch code; A merging unit, configured to merge the reference branch code and the feature branch code according to the change file list to obtain a target branch code; A detection unit, used to perform code detection on the target branch code to obtain a code scanning result; A screening unit, configured to screen incremental code information from the feature branch code based on the change file list; A positioning unit, used to locate the information position of the incremental code information in the target branch code; A generating unit, for generating a quality detection result of the incremental code information according to the information position and the code scanning result, comprising: extracting a target position where the problematic code in the target branch code is located from the code scanning result based on a preset label; comparing the target position with the information position; determining the target position that is the same as the information position as the problem position where the problematic code in the incremental code information is located; extracting information corresponding to the problem position from the code scanning result as a problem vulnerability; and generating the quality detection result according to the problem position and the problem vulnerability.
7. An electronic device, characterized in that: The electronic device comprises: a memory storing computer-readable instructions; and A processor executes computer-readable instructions stored in the memory to implement the incremental code quality detection method as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions are executed by a processor in an electronic device to implement the incremental code quality detection method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Incremental code defect detection method and system based on graph network model
CN113127341A
Incremental code detection method and device, medium and electronic equipment
CN114281696A