Code detection method and code detection device, computer device, and storage medium
By detecting the commit status of the target code file and comparing it with historical strings, the associated objects are notified in a timely manner, which solves the problem of code modifications going unnoticed in multi-person development, improves code detection efficiency and avoids production problems.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA PING AN LIFE INSURANCE CO LTD
- Filing Date
- 2022-06-28
- Publication Date
- 2026-06-16
AI Technical Summary
In existing technologies, when the same interface is developed by multiple people, code modifications often go unnoticed, leading to frequent production problems. Furthermore, the need for all staff to evaluate the code before each release is a waste of manpower. Therefore, improving code inspection efficiency has become an urgent problem to be solved.
Code detection is achieved by detecting the submission status of the target code file, parsing and generating the target string and comparing it with historical strings, promptly notifying associated objects, and determining the code detection result based on the feedback information.
It improves code inspection efficiency, avoids production problems caused by code modifications, and reduces manpower waste.
Smart Images

Figure CN115202731B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a code detection method, code detection device, computer equipment, and storage medium. Background Technology
[0002] Existing application system development interfaces involve numerous business processes, often with multiple developers working on the same interface, which in turn interfaces with different developers. This frequently leads to situations where code is modified without the developers' knowledge. For example, in an SVN-based code management platform, someone might accidentally modify another developer's code module while committing their own. Alternatively, during collaborative development, there may be common code sections; developers might modify these common sections without understanding other business requirements, potentially causing serious production issues. Therefore, requiring each developer to review and evaluate all code in the current version before release is clearly too wasteful of manpower. Thus, providing a code inspection method that improves inspection efficiency has become a pressing technical problem. Summary of the Invention
[0003] The main objective of this application is to provide a code detection method, apparatus, device, and medium that can improve code detection efficiency.
[0004] To achieve the above objectives, a first aspect of this application proposes a code detection method, the method comprising:
[0005] Detect the submission status of the target code file; wherein, the submission status includes a first status that indicates the target code file has been submitted to the server;
[0006] When the submission status is the first status, the target code file is parsed to obtain at least one target code interface; wherein, each target code interface includes a target code segment and target interface information;
[0007] Generate a target string based on the target code segment;
[0008] Retrieve historical strings from the server based on the target interface information;
[0009] The target string is compared with the historical string to obtain the string comparison result;
[0010] The target object is determined from the preset object list based on the string comparison result, and the string comparison result is sent to the target object;
[0011] Obtain feedback information from the target object based on the string comparison result, and determine the code detection result based on the feedback information.
[0012] In some embodiments, after detecting the commit status of the target code file, the method further includes:
[0013] Based on the first state, the submission object of the target code file is detected to obtain the current submission object;
[0014] Retrieve associated objects from the object list based on the target code file;
[0015] Based on the currently submitted object and the associated object, send a warning message to the associated object.
[0016] In some embodiments, the warning information includes first information or second information, and sending the warning information to the associated object based on the currently submitted object and the associated object includes:
[0017] The currently submitted object and the associated object are compared to obtain the object comparison result;
[0018] If the object comparison result indicates that the currently submitted object does not exist in the associated object, then the first information is sent to the associated object;
[0019] or,
[0020] If the object comparison result indicates that the associated object contains the currently submitted object, then the code permissions of the currently submitted object and the operation permission range of the code file are obtained; the code permissions and the operation permission range are compared, and if the code permissions are not within the operation permission range, then the second information is sent to the associated object.
[0021] In some embodiments, each of the target code interfaces includes at least two code segments, and generating a target string based on the target code segments includes:
[0022] Scan all the code segments to determine the code call relationships of each code segment;
[0023] The concatenation order of each code segment is obtained based on the code call relationship;
[0024] The code segments are concatenated according to the concatenation order to obtain the target string.
[0025] In some embodiments, the string comparison result includes a first result, and the step of comparing the target string with the historical strings to obtain the string comparison result includes:
[0026] Obtain the concatenation order of the target string and obtain the preset order of the historical strings; wherein the historical strings are obtained by concatenating the historical strings in the preset order;
[0027] Compare the splicing order with the preset order;
[0028] If the splicing order is inconsistent with the preset order, the first result is obtained.
[0029] In some embodiments, the historical string includes a historical code segment, the string comparison result further includes a second result, and the step of comparing the target string with the historical string to obtain the string comparison result further includes:
[0030] If the splicing order is consistent with the preset order, then starting from the beginning position of the target string and the historical string, each target code segment and each historical code segment are compared.
[0031] If the target code segment is inconsistent with the historical code segment, the inconsistent target code segment is marked to obtain the marked code segment and the second result is obtained.
[0032] In some embodiments, comparing the target string with the historical strings to obtain a string comparison result further includes:
[0033] The marked code segment is compiled to obtain the compilation result;
[0034] The risk level of the marked code segment is determined based on the compilation results;
[0035] Add the risk level to the second result.
[0036] To achieve the above objectives, a second aspect of this application provides a code detection device, the device comprising:
[0037] A status detection module is used to detect the submission status of the target code file; wherein, the submission status includes a first status that indicates the target code file has been submitted to the server;
[0038] A parsing processing module is used to parse the target code file when the submission status is in the first state to obtain at least one target code interface; wherein each target code interface includes a target code segment and target interface information;
[0039] The generation module is used to generate a target string based on the target code segment;
[0040] The acquisition module is used to acquire historical strings from the server based on the target interface information;
[0041] The comparison module is used to compare the target string with the historical strings to obtain the string comparison result;
[0042] The sending module is used to determine the target object from a preset object list based on the string comparison result, and send the string comparison result to the target object;
[0043] The detection result determination module is used to obtain feedback information from the target object based on the string comparison result, and to determine the code detection result based on the feedback information.
[0044] To achieve the above objectives, a third aspect of this application provides a computer device, the computer device including a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for implementing communication between the processor and the memory, wherein the program, when executed by the processor, implements the method described in the first aspect.
[0045] To achieve the above objectives, a fourth aspect of the present application provides a storage medium, which is a computer-readable storage medium for computer-readable storage, wherein the storage medium stores one or more programs that can be executed by one or more processors to implement the method described in the first aspect.
[0046] The code detection method, device, computer equipment, and storage medium proposed in this application detect the submission status of a target code file. When the submission status is in the first state, the target code file is parsed to obtain at least one target code interface. Each target code interface includes a target code segment and target interface information. A target string is generated based on the target code segment. Historical strings are retrieved from the server based on the target interface information. A target object is determined from a preset object list based on the string comparison result obtained by comparing the target string with the historical strings, and the string comparison result is sent to the target object. Feedback information from the target object based on the string comparison result is obtained, and the code detection result is determined based on the feedback information. The embodiments of this application aim to associate each code interface with all developers who maintain it, i.e., associated objects. When code is submitted, such as when code is modified, or in multi-collaborative development where common parts are modified incorrectly, the modification is promptly notified to the target object based on the string comparison result. The target object includes at least one associated object, and the code detection result is determined based on the feedback information from the target object, thus achieving code detection. The embodiments of this application improve the efficiency of code detection and can also avoid production problems caused by code modifications. Attached Figure Description
[0047] Figure 1 This is a flowchart of the code detection method provided in the embodiments of this application;
[0048] Figure 2 This is another flowchart of the code detection method provided in the embodiments of this application;
[0049] Figure 3 yes Figure 1 The flowchart of step S103 in the process;
[0050] Figure 4 yes Figure 1 The flowchart of step S105 in the process;
[0051] Figure 5 yes Figure 1 The flowchart of step S105 in the process;
[0052] Figure 6 yes Figure 1 The flowchart of step S105 in the process;
[0053] Figure 7 This is a block diagram of the module structure of the code detection device provided in the embodiments of this application;
[0054] Figure 8 This is a schematic diagram of the hardware structure of the computer device provided in the embodiments of this application. Detailed Implementation
[0055] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0056] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, and the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0057] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0058] First, let's analyze some of the terms used in this application:
[0059] Artificial Intelligence (AI) is a new branch of computer science that studies, develops, and applies theories, methods, technologies, and systems to simulate, extend, and expand human intelligence. It aims to understand the essence of intelligence and produce intelligent machines that can react in a way similar to human intelligence. Research in this field includes robotics, speech recognition, image recognition, natural language processing, and expert systems. AI can simulate the information processes of human consciousness and thought. Furthermore, AI utilizes digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceiving the environment, acquiring knowledge, and using that knowledge to achieve optimal results.
[0060] Huffman coding, also known as Huffman encoding, is an encoding method, a type of variable-length coding (VLC). This method constructs codewords with the shortest average length based entirely on the probability of character occurrence, sometimes referred to as optimal coding, and generally called Huffman coding (or sometimes simply Huffman encoding).
[0061] Run-Length Encoding (RLE) compression algorithm divides data into two linear sequences: consecutive repeating data blocks and consecutive non-repeating data blocks. The principle of RLE is to use an attribute representing the number of blocks plus a data block to represent several consecutive data blocks, thereby saving storage space. Generally, RLE algorithms choose a data block length of 1 byte, and the attribute representing the number of blocks also uses 1 byte. For image files or text files with fewer than 256 colors, a 1-byte block length is suitable. There are many optimized and improved variants of the RLE algorithm, but these algorithms generally handle consecutive repeating data in the same way. For consecutively repeating data, the RLE algorithm typically uses two bytes to represent the original consecutive multi-byte repeating data.
[0062] BF algorithm (Brute Force): This is a common pattern matching algorithm. The idea of BF algorithm is to match the first character of the target string S with the first character of the pattern string T. If they are equal, then continue to compare the second character of S with the second character of T; if they are not equal, then compare the second character of S with the first character of T, and so on, until the final matching result is obtained. BF algorithm is a brute-force algorithm. First, S[1] and T[1] are compared. If they are equal, then S[2] and T[2] are compared, and so on, until T[M]; if S[1] and T[1] are not equal, then S is moved one character to the right, and then the comparison is carried out. If there exists k, 1≤k≤N, and S[k+1…k+M]=T[1…M], then the matching is successful; otherwise, it fails.
[0063] The RK algorithm, proposed by Rabin and Karp, is based on the idea that: let the pattern string be P with length m, and the main string be S with length n. The pattern string P can be viewed as an m-digit d-ary number A, and the main string S as an n-digit d-ary number. The pattern matching process involves comparing A with the value of each m-digit d-ary number S[t…t+m-1] (t=0,1,2,…,n-m+1) in the main string. Therefore, the entire pattern matching process becomes a comparison between two d-ary numbers. The hash value of the pattern string P is compared with the hash value of each substring of length |P| in the main string S; if they are different, they are definitely not equal; if they are the same, then the hash values are compared bit by bit.
[0064] Existing application system development interfaces involve numerous business processes, often with multiple developers working on the same interface, which in turn interfaces with different developers. This frequently leads to situations where code is modified without the developers' knowledge. For example, in an SVN-based code management platform, someone might accidentally modify another developer's code module while committing their own. Alternatively, during collaborative development, there may be common code sections; developers might modify these common sections without understanding other business requirements, potentially causing serious production issues. Therefore, requiring each developer to review and evaluate all code in the current version before release is clearly too wasteful of manpower. Thus, providing a code inspection method that improves inspection efficiency has become a pressing technical problem.
[0065] Based on this, the main objective of this application is to propose a code detection method, a code detection device, a computer device, and a storage medium. The aim is to link each code interface with all the developers maintaining it. When code is submitted (e.g., modified), or in collaborative development where common parts are modified incorrectly, the modification is promptly notified to the target object through string comparison results. The code detection result is then determined based on the feedback from the target object, thus achieving code detection. This application improves the efficiency of code detection and avoids production problems caused by code modifications.
[0066] The embodiments of this application can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence (AI) refers to the theories, methods, technologies, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results.
[0067] Foundational technologies for artificial intelligence generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies mainly encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.
[0068] The code detection method provided in this application relates to the field of artificial intelligence technology. The code detection method provided in this application can be applied to a terminal, a server, or software running on either a terminal or a server. In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, etc.; the server can be configured as an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application implementing the code detection method, but is not limited to the above forms.
[0069] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0070] It should be noted that in all specific embodiments of this application, when processing data related to user identity or characteristics, such as user information, user behavior data, user historical data, and user location information, user permission or consent is obtained first. Furthermore, the collection, use, and processing of this data comply with relevant laws, regulations, and standards of the relevant countries and regions. In addition, when embodiments of this application require access to sensitive personal information of users, separate permission or consent from the user is obtained through pop-ups or redirects to confirmation pages. Only after obtaining the user's separate permission or consent is the necessary user-related data for the proper functioning of the embodiments of this application obtained.
[0071] This application provides code detection methods, code detection devices, computer equipment, and storage media. The specific implementation details are provided in the following embodiments. First, the code detection method in this application is described.
[0072] Figure 1 This is an optional flowchart of the code detection method provided in the embodiments of this application. Figure 1 The method may include, but is not limited to, steps S101 to S107.
[0073] Step S101: Detect the submission status of the target code file; wherein, the submission status includes a first status used to characterize the submission of the target code file to the server;
[0074] Step S102: When the submission status is in the first state, the target code file is parsed to obtain at least one target code interface; wherein, each target code interface includes a target code segment and target interface information;
[0075] Step S103: Generate the target string based on the target code segment;
[0076] Step S104: Obtain historical strings from the server based on the target interface information;
[0077] Step S105: Compare the target string with the historical strings to obtain the string comparison result;
[0078] Step S106: Determine the target object from the preset object list based on the string comparison result, and send the string comparison result to the target object;
[0079] Step S107: Obtain feedback information from the target object based on the string comparison results, and determine the code detection result based on the feedback information.
[0080] Steps S101 to S107, as illustrated in this embodiment, associate each code interface with all target objects that maintain it. When code is submitted (e.g., modified), or in collaborative development where common parts are modified incorrectly, the modification is promptly notified to the target objects through string comparison results. The code detection result is then determined based on the feedback from the target objects, thus achieving code detection. This embodiment improves the efficiency of code detection and avoids production problems caused by code modifications.
[0081] In step S101 of some embodiments, the target code file is generally developed or processed jointly by multiple developers, who are represented as associated objects in this embodiment. In one example, the target code file is configured with an object list, which includes multiple associated objects. Each associated object's modification of the target code file needs to notify the other associated objects. In this embodiment, the submission status of the target code file is used as the basis for determining whether the target code file has been modified. It should be noted that the submission status includes a first status indicating that the target code file has been submitted to the server, and a second status indicating that the target code file has not been submitted to the server. It should also be noted that regardless of whether the target code file has been modified by associated objects, as long as the submission status of the target code file is detected as the first status, it is assumed that the target code file has been modified by an associated object, which is also called the current submission object. The target code file will then be processed to determine the final code detection result.
[0082] Please see Figure 2 , Figure 2 This is an optional flowchart of the code detection method provided in the embodiments of this application. In some embodiments, after step S101, Figure 2 The method may include, but is not limited to, steps S201 to S203:
[0083] Step S201: Obtain the current submission object based on the submission object of the detected target code file obtained from the first state;
[0084] Step S202: Obtain the associated objects from the object list based on the target code file;
[0085] Step S203: Based on the currently submitted object and associated objects, send a warning message to the associated objects.
[0086] In steps S201 to S203 of this embodiment, the currently submitted object refers to the object performing the submission operation on the target code file, but it may not necessarily be an associated object of the target code file. If the currently submitted object is not an associated object of the target code file, it is very likely that the target code file has been mistakenly modified by other unrelated objects, which will generate a warning message to remind the associated objects. Even if the currently submitted object is an associated object of the target code file, due to the different code permissions of the associated objects, if an object without operation permissions operates on the target code file, a warning message will also be generated. A warning message is sent to the associated objects to remind them. It should be noted that the email addresses of each object in the object list are stored in advance, and warning messages can be sent to the associated objects via email or other social tools.
[0087] Specifically, the warning information includes a first message, which compares the currently submitted object and its associated objects to obtain the object comparison result. If the object comparison result indicates that the associated object does not contain the currently submitted object, then the first message is sent to the associated object. In one example, the first message could be "Unknown personnel have illegally modified the code," or "The current code is at risk of being maliciously modified." The warning information also includes a second message. If the object comparison result indicates that the associated object contains the currently submitted object, then the code permissions of the currently submitted object and the scope of operation permissions for the code file are obtained. The code permissions and the scope of operation permissions are compared. If the code permissions are not within the scope of operation permissions, then the second message is sent to the associated object. In one example, the second message could be "The current code has been modified beyond its scope," or "The code permissions of the currently submitted object are insufficient."
[0088] In step S102 of some embodiments, if the submission status is in the first state, it indicates that the target code file has been submitted to the server by the current submitting object. Generally, the server parses the target file and overwrites the original historical code file based on the parsing result. However, this leaves other related objects unaware of whether the code file has been modified, or which part of the target code file has been modified. Therefore, in this embodiment, the target code file is parsed to obtain at least one target code interface. Each target code interface includes a target code segment and target interface information, to determine the modified part of the target code file based on the target code interface. Furthermore, the specific modified part of the target code file can be located based on the target code segment and target interface information, improving the efficiency of code detection.
[0089] In other embodiments, the code detection method further includes the following steps before generating the target string based on the target code segment:
[0090] Retrieve the history submission object of the history string;
[0091] If the current commit object is the same as the historical commit object, then obtain the historical modification time of the historical string and obtain the current modification time of the target string;
[0092] Calculate the modification time difference based on the historical modification time and the current modification time;
[0093] If the modification time difference is less than the preset duration threshold, the target code segment is marked as an intermediate code segment, and the intermediate code segment is saved to the preset cache space;
[0094] If the modification time difference is greater than or equal to the duration threshold, all intermediate code segments are read from the cache space, and the intermediate code segments and the target code segments are merged to obtain the updated target code segment.
[0095] Specifically, the submitted objects are compared through the above steps. If the historical and current submitted objects are identical, the modification time difference and a duration threshold are compared. If the modification time difference is less than the duration threshold, the target code segment is marked as an intermediate code segment and placed in a preset cache space. If the modification time difference is greater than or equal to the duration threshold, all intermediate code segments are read from the cache space, and these intermediate code segments are merged with the last target code segment to obtain the updated target code segment. This embodiment avoids the situation where the target code file is submitted multiple times due to multiple modifications to the code segment by the same submitted object within the duration threshold, thereby reducing the number of code checks and improving code check efficiency.
[0096] In step S103 of some embodiments, the code segment is parsed to generate a target string from the target code segment, so that subsequent string comparison can be performed.
[0097] Please see Figure 3 In some embodiments, each target code interface includes at least two code segments, and step S103 may include, but is not limited to, steps S301 to S303:
[0098] Step S301: Scan all code segments to determine the code call relationships of each code segment;
[0099] Step S302: Obtain the concatenation order of each code segment based on the code call relationship;
[0100] Step S303: Concatenate the code segments according to the concatenation order to obtain the target string.
[0101] In steps S301 to S303 of this embodiment, since each target code interface includes multiple code segments, if the order of these code segments is not fixed, even if the current submission object does not substantially modify the code segments (e.g., adjusts the order between code segments), inconsistencies will still occur during subsequent string comparisons. Therefore, the concatenation order is determined based on the code call relationship of each code segment, and the multiple code segments are concatenated according to the concatenation order to obtain the target string. This avoids inconsistent string comparison results due to adjusting the order of code segments, which would affect detection efficiency. Specifically, taking a target code interface including code segments A, B, C, D, E, F, and G as an example, where B and C both call A, D and E both call B, and F and G both call C. The concatenation order obtained according to the code call relationship is A(1), B(2), C(5), D(3), E(4), F(6), G(7), therefore the target string can be: A, B, D, E, C, F, G. It should be noted that if multiple code segments share a common call to another code segment, they are marked as parallel code segments. For example, if B and C both call A, then B and C are parallel code segments. The order in which parallel code segments are concatenated is determined according to their original order in the object code file. For example, in this example, B comes before C, so the concatenation order of B is determined to be 2, and the concatenation order of C comes after B. This embodiment of the application reduces the probability of string inconsistencies due to changes in the order of code segments by determining the concatenation order, thereby improving code detection efficiency.
[0102] It should be noted that, considering the existence of unmodifiable code segments among multiple code segments, some of these unmodifiable code segments can be skipped during string generation to improve string comparison speed. Specifically, each code segment has corresponding identification information. The code segment to be processed can be determined based on its identification information. Then, the concatenation order of the code segments to be processed is determined based on the call relationship. Finally, the code segments to be processed are concatenated according to the concatenation order to obtain the target string.
[0103] In step S104 of some embodiments, historical strings are obtained from the server based on the target interface information. Specifically, the server stores code files and can distinguish different code segments through interface information. Each code segment is stored on the server in string form. The historical string corresponding to the target code segment can be obtained from the server based on the target interface information. In one example, the server stores a compressed package of strings corresponding to each interface information. The historical string compressed package can be determined from the server based on the target interface information, and then decompressed to obtain the historical string. It should be noted that existing compression algorithms such as Huffman coding compression algorithm and RLE compression algorithm can be used to compress the string to obtain the compressed string package. Correspondingly, the compressed string package is decompressed using de-Huffman coding, de-RLE algorithm, or other decompression algorithms to obtain the historical string.
[0104] In step S105 of some embodiments, the target string is compared with the historical strings to obtain a string comparison result. Please refer to... Figure 4 In some embodiments, the string comparison result includes a first result, and step S105 may include, but is not limited to, steps S401 to S403:
[0105] Step S401: Obtain the concatenation order of the target string and obtain the preset order of the historical strings; wherein, the historical strings are obtained by concatenating the strings in the preset order.
[0106] Step S402: Compare the splicing order with the preset order;
[0107] Step S403: If the splicing order is inconsistent with the preset order, the first result is obtained.
[0108] If the concatenation order of the target string and the preset order of the historical string are inconsistent in steps S401 to S403 as shown in the embodiments of this application, it indicates that the target string and the historical string are different at least in the order of the code segments. Therefore, the first result obtained includes information that the order of the code segments is inconsistent.
[0109] Please see Figure 5 In some other embodiments, the string comparison result also includes a second result. After step S402, step S105 may also include, but is not limited to, steps S501 to S502:
[0110] Step S501: If the concatenation order is consistent with the preset order, then starting from the beginning position of the target string and the historical string, compare each target code segment with each historical code segment.
[0111] Step S502: If the target code segment is inconsistent with the historical code segment, the inconsistent target code segment is marked to obtain the marked code segment and the second result.
[0112] In steps S501 to S502 of this embodiment, when the concatenation order matches the preset order, the target string and the historical string are compared from the beginning to the end, and inconsistencies are marked to identify inconsistent target code segments. The marked code segments and the second result can be sent together to the associated object to improve the efficiency of obtaining feedback information from the associated object.
[0113] Please see Figure 6 In some other embodiments, the string comparison result also includes a second result. After step S502, step S105 may also include, but is not limited to, steps S601 to S603:
[0114] Step S601: Compile the marked code segment to obtain the compilation result;
[0115] Step S602: Determine the risk level of the marked code segment based on the compilation results;
[0116] Step S603: Add the risk level to the second result.
[0117] Steps S601 to S603, as illustrated in this embodiment, involve compiling the marked code segment according to preset test cases to obtain compilation results. The compilation results include: successful compilation and failed compilation. If the compilation result is successful, it indicates that although the marked code segment has been modified by the current submitter, the modification has not caused the basic functionality to fail. The risk level can be configured as medium or low risk, and the risk level is added to the second result and sent to the target object. If the compilation result is failed compilation, it indicates that the code segment has not only been modified, but may even cause production problems. The risk level is configured as high or very high risk, added to the second result, and sent to the target object to remind the target object of the importance of this code inspection.
[0118] It should be noted that the second result includes information about inconsistencies in the code segment content. Furthermore, both the first and second results can be referred to as inconsistency results.
[0119] In step S106 of some embodiments, the string comparison result also includes a matching result, a failed comparison result, etc. Different string comparison results have different effects on the code file. For example, if the string comparison result is a matching result, it means that the code segment has not been modified, and it is very likely that the currently submitted object has performed an erroneous operation. If the string comparison result is sent to all associated objects, it will cause a waste of resources. However, if the string comparison result is a failed comparison result, it means that the code segment has been severely modified and can no longer perform a normal string comparison. The failed comparison result needs to be sent to all associated objects, and a risk level can be added if necessary to remind all associated objects. Specifically, the email addresses of each associated object in the object list are stored in advance, and the string comparison result can be sent to the target object through the email address. It should be noted that the target object may include multiple associated objects.
[0120] It should be noted that existing string comparison algorithms, such as the BF algorithm and RK algorithm, can be used for string comparison. If the target string is exactly the same as the historical string, the comparison is considered successful; otherwise, it is considered unsuccessful. Reasons for a failed comparison, beyond the scope of the previous comparison, include: the target string being completely deleted; the target string having fewer than half the number of characters as the historical string; or the target string having more than twice the number of characters as the historical string. In one example, related objects in the object list are categorized by importance level. This allows for the determination of the corresponding importance level of the related object as the target object based on different string comparison results. It should be noted that the target object can include multiple related objects. If the string comparison result is a match, the related object with the lowest importance level is selected from the pre-defined object list as the target object, and the successful string comparison result is sent to the target object.
[0121] In step S107 of some embodiments, different string comparison results are sent to the target object, and the feedback information obtained is slightly different. For example, if a matching string comparison result is sent to the target object, the target object will give feedback that it agrees to the modification, and the code detection result is successful. If the code detection result is successful, it means that the target string submitted by the current submitting object has passed the detection, and the target string can be saved to the server and overwrite the previous historical string. By verifying each submitted target code file with other related objects, this embodiment of the application can clearly locate the current submitting object and the modified code part for each code modification, thereby improving the efficiency of code detection. Furthermore, the detection process of each submitted code can be logged so that the responsible personnel can be found in a timely manner if production problems occur later.
[0122] Please see Figure 7 This application also provides a code detection device that can implement the above-described code detection method. Figure 7 The present application provides a block diagram of the module structure of a code detection device, which includes: a detection status module 701, a parsing processing module 702, a generation module 703, an acquisition module 704, a comparison module 705, a sending module 706, and a detection result determination module 707. The system includes the following modules: a detection status module 701 for detecting the submission status of the target code file; the submission status includes a first status indicating that the target code file has been submitted to the server; a parsing processing module 702 for parsing the target code file in the first submission status to obtain at least one target code interface; each target code interface includes a target code segment and target interface information; a generation module 703 for generating a target string based on the target code segment; an acquisition module 704 for acquiring historical strings from the server based on the target interface information; a comparison module 705 for comparing the target string with historical strings to obtain a string comparison result; a sending module 706 for determining the target object from a preset object list based on the string comparison result and sending the string comparison result to the target object; and a detection result determination module 707 for obtaining feedback information from the target object based on the string comparison result and determining the code detection result based on the feedback information.
[0123] It should be noted that the specific implementation of this code detection device is basically the same as the specific implementation of the code detection method described above, and will not be repeated here.
[0124] This application also provides a computer device, which includes: a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for communication between the processor and the memory. When the program is executed by the processor, it implements the aforementioned code detection method. This computer device can be any smart terminal, including tablet computers, in-vehicle computers, etc.
[0125] Please see Figure 8 , Figure 8 The hardware structure of a computer device according to another embodiment is illustrated. The computer device includes:
[0126] The processor 801 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application.
[0127] The memory 802 can be implemented as a read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory 802 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 802 and is called and executed by the processor 801 using the code detection method of the embodiments of this application.
[0128] The 803 input / output interface is used to implement information input and output.
[0129] The communication interface 804 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0130] Bus 805 transmits information between various components of the device (e.g., processor 801, memory 802, input / output interface 803, and communication interface 804);
[0131] The processor 801, memory 802, input / output interface 803, and communication interface 804 are connected to each other within the device via bus 805.
[0132] This application embodiment also provides a storage medium, which is a computer-readable storage medium for computer-readable storage. The storage medium stores one or more programs, which can be executed by one or more processors to implement the above-described code detection method.
[0133] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0134] The code detection method, device, computer equipment, and storage medium provided in this application detect the submission status of a target code file. When the submission status is in a first state, the target code file is parsed to obtain at least one target code interface. This allows the target code file to be segmented through the target code interface, enabling faster identification of modified code sections. Each target code interface includes a target code segment and target interface information. A target string is generated based on the target code segment. Historical strings are retrieved from the server based on the target interface information. A string comparison between the target string and the historical strings is used to determine the target object from a preset object list, and the comparison result is sent to the target object. Since different string comparison results have different impacts on the code file, the target object is determined from the object list based on the comparison result to differentiate the impact of different comparison results on the relevant target objects. Feedback information from the target object based on the string comparison result is obtained, and the code detection result is determined based on the feedback information. This application aims to associate each code interface with all developers who maintain it, i.e., associated objects. When code is submitted, such as through code modification, or in collaborative development where common parts are modified incorrectly, the modification is promptly notified to the target objects (including multiple related objects) through string comparison results. The code detection result is determined based on the feedback from the target objects, thus achieving code detection. This embodiment improves the efficiency of code detection and also avoids production problems caused by code modifications.
[0135] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0136] It will be understood by those skilled in the art that Figure 1-6 The technical solutions shown do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.
[0137] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0138] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.
[0139] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0140] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0141] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0142] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0143] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0144] If the integrated unit is implemented as 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 technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0145] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.
Claims
1. A code detection method, characterized in that, The method includes: Detect the submission status of the target code file; wherein, the submission status includes a first status that indicates the target code file has been submitted to the server; When the submission status is the first status, the target code file is parsed to obtain at least one target code interface; wherein, each target code interface includes a target code segment and target interface information; Based on the first state, detect the submission object of the target code file to obtain the current submission object; Retrieve historical strings from the server based on the target interface information; Retrieve the historical submission object of the historical string; If the current submission object is the same as the historical submission object, then obtain the historical modification time of the historical string and obtain the current modification time; Calculate the modification time difference based on the historical modification time and the current modification time; If the modification time difference is less than a preset duration threshold, the target code segment is marked as an intermediate code segment, and the intermediate code segment is saved to a preset cache space; If the modification time difference is greater than or equal to the duration threshold, all intermediate code segments are read from the cache space, and the intermediate code segments and the target code segment are merged to obtain the updated target code segment; Generate a target string based on the updated target code segment; The target string is compared with the historical string to obtain the string comparison result; The target object is determined from the preset object list based on the string comparison result, and the string comparison result is sent to the target object; Obtain feedback information from the target object based on the string comparison result, and determine the code detection result based on the feedback information.
2. The method according to claim 1, characterized in that, After detecting the submission status of the target code file, the method further includes: Retrieve associated objects from the object list based on the target code file; Based on the currently submitted object and the associated object, send a warning message to the associated object.
3. The method according to claim 2, characterized in that, The warning information includes a first message or a second message. The step of sending the warning information to the associated object based on the currently submitted object and the associated object includes: The currently submitted object and the associated object are compared to obtain the object comparison result; If the object comparison result indicates that the currently submitted object does not exist in the associated object, then the first information is sent to the associated object; or, If the object comparison result indicates that the associated object contains the currently submitted object, then the code permissions of the currently submitted object and the operation permission range of the code file are obtained; the code permissions and the operation permission range are compared, and if the code permissions are not within the operation permission range, then the second information is sent to the associated object.
4. The method according to any one of claims 1 to 3, characterized in that, Each of the target code interfaces includes at least two code segments, and generating a target string based on the updated target code segments includes: Scan all the code segments to determine the code call relationships of each code segment; The concatenation order of each code segment is obtained based on the code call relationship; The code segments are concatenated according to the concatenation order to obtain the target string.
5. The method according to claim 4, characterized in that, The string comparison result includes a first result. The step of comparing the target string with the historical strings to obtain the string comparison result includes: Obtain the concatenation order of the target string and obtain the preset order of the historical strings; wherein the historical strings are obtained by concatenating the historical strings in the preset order; Compare the splicing order with the preset order; If the splicing order is inconsistent with the preset order, the first result is obtained.
6. The method according to claim 5, characterized in that, The historical string includes a historical code segment, and the string comparison result also includes a second result. The step of comparing the target string with the historical string to obtain the string comparison result further includes: If the splicing order is consistent with the preset order, then starting from the beginning position of the target string and the historical string, each target code segment and each historical code segment are compared. If the target code segment is inconsistent with the historical code segment, the inconsistent target code segment is marked to obtain the marked code segment and the second result is obtained.
7. The method according to claim 6, characterized in that, The step of comparing the target string with the historical strings to obtain the string comparison result further includes: The marked code segment is compiled to obtain the compilation result; The risk level of the marked code segment is determined based on the compilation results; Add the risk level to the second result.
8. A code detection device, characterized in that, The device includes: A status detection module is used to detect the submission status of the target code file; wherein, the submission status includes a first status that indicates the target code file has been submitted to the server; A parsing processing module is used to parse the target code file when the submission status is in the first state to obtain at least one target code interface; wherein each target code interface includes a target code segment and target interface information; The generation module is used to generate a target string based on the target code segment; The acquisition module is used to acquire historical strings from the server based on the target interface information; The comparison module is used to compare the target string with the historical strings to obtain the string comparison result; The sending module is used to determine the target object from a preset object list based on the string comparison result, and send the string comparison result to the target object; The detection result determination module is used to obtain feedback information from the target object based on the string comparison result, and to determine the code detection result based on the feedback information; Prior to generating the target string based on the target code segment, the device is further configured to: Based on the first state, detect the submission object of the target code file to obtain the current submission object; Retrieve historical strings from the server based on the target interface information; Retrieve the historical submission object of the historical string; If the current submission object is the same as the historical submission object, then obtain the historical modification time of the historical string and obtain the current modification time; Calculate the modification time difference based on the historical modification time and the current modification time; If the modification time difference is less than a preset duration threshold, the target code segment is marked as an intermediate code segment, and the intermediate code segment is saved to a preset cache space; If the modification time difference is greater than or equal to the duration threshold, all intermediate code segments are read from the cache space, and the intermediate code segments and the target code segment are merged to obtain the updated target code segment.
9. A computer device, characterized in that, The computer device includes a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for enabling communication between the processor and the memory, wherein the program, when executed by the processor, implements the steps of the method as described in any one of claims 1 to 7.
10. A storage medium, said storage medium being a computer-readable storage medium for computer-readable storage, characterized in that, The storage medium stores one or more programs, which can be executed by one or more processors to implement the steps of the method according to any one of claims 1 to 7.