Method and device for analyzing code change influence, electronic equipment and storage medium
By converting the code into an abstract syntax tree and building a service call relationship, the scope of impact of code changes is automatically analyzed, and the problems of low efficiency and poor accuracy of manual evaluation in the existing technology are solved, and efficient and comprehensive code change impact analysis is achieved.
Patent Information
- Application Number
- CN202411742586.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-03-25
AI Technical Summary
In the prior art, technicians manually evaluate the impact range of code changes, which are less efficient and have poor accuracy.
By converting the new version code and the old version code into an abstract syntax tree, and building a service call relationship, automatically comparing the code change information, and determining the scope of impact of code changes on the software system.
Improves the efficiency and accuracy of analyzing the impact of code changes, ensures the comprehensiveness of the analysis of code changes, and reduces the time and cost of manual evaluation.
Smart Images

Figure CN119690800A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data analysis technology, and in particular to a method, device, electronic device and storage medium for analyzing the impact of code changes. Background Art
[0002] In the process of software development and maintenance, code changes are a normal task. For software systems, code changes may trigger a chain reaction, which in turn affects the operation of the software system.
[0003] Currently, technical personnel are usually responsible for assessing the impact of code changes. This method is time-consuming, labor-intensive, and error-prone, and the efficiency and accuracy of analyzing the impact of code changes are low. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a method, device, electronic device and storage medium for analyzing the impact of code changes to solve the problems of low efficiency and poor accuracy in analyzing the impact of code changes in the method of having technicians evaluate the scope of impact of code changes.
[0005] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:
[0006] A first aspect of an embodiment of the present invention discloses a method for analyzing the impact of a code change, the method comprising:
[0007] Pull a new version of code corresponding to the old version of code, where the new version of code is a code branch merged into the old version of code;
[0008] Convert the new version code into a first abstract syntax tree;
[0009] Build service call relationships;
[0010] Comparing the first abstract syntax tree with a second abstract syntax tree converted from the old version code to obtain code change information;
[0011] The impact scope of the code change on the software system is determined based on the service call relationship and the code change information.
[0012] From the above content, it can be seen that this solution converts the new version code and the old version code that need to be compared into a first abstract syntax tree and a second abstract syntax tree, and constructs a service call relationship; based on the service call relationship, combined with the code change information between the first abstract syntax tree and the second abstract syntax tree to identify the scope of impact of the code change on the software system, it helps to comprehensively and accurately analyze the impact of the code change on the software system.
[0013] Preferably, determining the impact scope of the code change on the software system according to the service call relationship and the code change information includes:
[0014] Parsing the impact of the code change information on a specified object to identify a first impact scope, wherein the specified object includes at least a function and a class;
[0015] Analyzing the impact of the code change information on upstream and downstream services based on the service call relationship to identify a second impact range;
[0016] The first impact scope and the second impact scope are combined to determine the impact scope of the code change on the software system.
[0017] From the above content, it can be seen that the first impact scope of the code change information is obtained by identifying the impact of the code change information on functions and classes, and the second impact scope is obtained by identifying the impact of the code change information on upstream and downstream services through service call relationships. The first impact scope and the second impact scope are merged to obtain the overall impact scope of the code change on the software system. The impact scope of the code change on the software system is evaluated from two aspects: "the impact of code changes on functions and classes" and "the impact of code changes on upstream and downstream services" to ensure the comprehensiveness of the code change impact analysis.
[0018] Preferably, building a service call relationship includes:
[0019] Parsing target information from the first abstract syntax tree, the target information at least including: external interface information, external interface calling information, class relationship and / or message interaction information;
[0020] A service call relationship is constructed according to the target information.
[0021] Preferably, converting the new version code into a first abstract syntax tree includes:
[0022] A specified parser is called to convert the new version code into a first abstract syntax tree.
[0023] It can be seen from the above content that appropriate parsing is selected to accurately convert the new version code into the first abstract syntax tree, thereby ensuring the accuracy of the comparison between the new version code and the old version code.
[0024] Preferably, after determining the impact scope of the code change on the software system, the method further includes:
[0025] Use change heat maps and / or impact trees to show the scope of impact of code changes on the software system.
[0026] It can be seen from the above content that using an intuitive change heat map and / or impact tree to display the impact scope of code changes on the software system allows users to intuitively check the impact scope of code changes.
[0027] Preferably, it also includes:
[0028] Receive analysis requests sent by the code management platform when a code merge event is detected;
[0029] Verifying the validity of the analysis request;
[0030] When the analysis request passes the validity verification, the step of pulling a new version code corresponding to the old version code is performed.
[0031] Preferably, it also includes:
[0032] Generate a code change report, the code change report at least including: the code change information, the impact of the code change on the software system;
[0033] Send the code change report and / or code change notification information to a designated person.
[0034] It can be seen from the above content that sending the code change report and / or code change notification information to the designated personnel enables the designated personnel to pay attention to the impact scope of the code change in a timely manner and ensure the stable operation of the software system.
[0035] A second aspect of an embodiment of the present invention discloses a device for analyzing the impact of a code change, the device comprising:
[0036] A pulling unit, used to pull a new version code corresponding to an old version code, wherein the new version code is a code branch merged into the old version code;
[0037] A conversion unit, configured to convert the new version code into a first abstract syntax tree;
[0038] Construction unit, used to build service call relationship;
[0039] A comparison unit, used for comparing the first abstract syntax tree with a second abstract syntax tree converted from the old version code to obtain code change information;
[0040] A determination unit is used to determine the impact scope of the code change on the software system according to the service call relationship and the code change information.
[0041] Preferably, the determining unit includes:
[0042] A first identification subunit is used to analyze the impact of the code change information on a specified object to identify a first impact range, wherein the specified object includes at least a function and a class;
[0043] A second identification subunit is used to analyze the impact of the code change information on upstream and downstream services based on the service call relationship to identify a second impact range;
[0044] The merging subunit is used to merge the first impact scope and the second impact scope to determine the impact scope of the code change on the software system.
[0045] Preferably, the building block comprises:
[0046] A parsing subunit, configured to parse target information from the first abstract syntax tree, wherein the target information includes at least: external interface information, external interface calling information, class relationship and / or message interaction information;
[0047] The construction subunit is used to construct a service call relationship according to the target information.
[0048] Preferably, the conversion unit is specifically used for:
[0049] A specified parser is called to convert the new version code into a first abstract syntax tree.
[0050] Preferably, the device further comprises:
[0051] The display unit is used to display the impact scope of code changes on the software system by using a change heat map and / or an impact tree.
[0052] Preferably, the device further comprises:
[0053] A receiving unit, used to receive an analysis request sent by the code management platform when a code merging event is detected;
[0054] A verification unit is used to verify the validity of the analysis request; when the analysis request passes the validity verification, the pulling unit is executed.
[0055] Preferably, the device further comprises:
[0056] A report generating unit, used to generate a code change report, wherein the code change report includes at least: the code change information and the impact scope of the code change on the software system;
[0057] The notification unit is used to send the code change report and / or code change notification information to a designated person.
[0058] A third aspect of an embodiment of the present invention discloses an electronic device, comprising: a processor and a memory, wherein the processor and the memory are connected via a communication bus; wherein the processor is used to call and execute a program stored in the memory; and the memory is used to store a program, wherein the program is used to implement the method for analyzing the impact of code changes disclosed in the first aspect of the embodiment of the present invention.
[0059] A fourth aspect of an embodiment of the present invention discloses a computer-readable storage medium, in which computer-executable instructions are stored. The computer-executable instructions are used to execute the method for analyzing the impact of code changes disclosed in the first aspect of the embodiment of the present invention.
[0060] Based on the above-mentioned embodiment of the present invention, a method, device, electronic device and storage medium for analyzing the impact of code changes are provided. The method is: pull the new version code corresponding to the old version code; convert the new version code into a first abstract syntax tree; construct a service call relationship; compare the first abstract syntax tree and the second abstract syntax tree converted from the old version code to obtain code change information; determine the impact range of the code change on the software system according to the service call relationship and the code change information. In this scheme, the new version code and the old version code to be compared are respectively converted into the first abstract syntax tree and the second abstract syntax tree reflecting the code structure, and a service call relationship is constructed. The first abstract syntax tree and the second abstract syntax tree are compared to obtain code change information reflecting the difference information between the new version code and the old version code. The service call relationship is used to comprehensively analyze the impact of code change information on the classes, methods, and entrances of the software system, which can not only improve the efficiency of code change impact analysis, but also ensure the comprehensiveness of code change impact analysis to avoid missing analysis. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0062] Figure 1 A flowchart of a method for analyzing the impact of code changes provided by an embodiment of the present invention;
[0063] Figure 2 A flowchart for determining the impact range of a code change on a software system provided by an embodiment of the present invention;
[0064] Figure 3 An example diagram of the overall architecture of a method for analyzing the impact of code changes provided by an embodiment of the present invention;
[0065] Figure 4 A structural block diagram of a device for analyzing the impact of code changes provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0066] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0067] In this application, the terms "comprises", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element.
[0068] In the process of software development and maintenance, code changes are a normal task, but they face the following challenges: how to ensure code quality, code stability, and code functional correctness. For software systems, code changes may trigger a chain reaction, which in turn affects the operation of the software system. For example, for software systems of large projects, a small code change may trigger a chain reaction, which in turn affects the operation of other parts of the software system and even causes unpredictable problems.
[0069] The inventor has found through research that currently, it is usually the technicians who evaluate the scope of impact of code changes. Specifically, when a code change occurs, the technicians manually evaluate the scope of impact of the code change according to the actual situation of the code and personal experience; however, the manual evaluation of the scope of impact of code changes requires the technicians to spend a lot of time to analyze the content of the code in detail, and "missed analysis" and "wrong analysis" are prone to occur during the analysis process, which will result in low efficiency and poor accuracy in analyzing the impact of code changes.
[0070] Therefore, the embodiment of the present invention provides a method, device, electronic device and storage medium for analyzing the impact of code changes, and compares a first abstract syntax tree obtained by converting a new version of the code with a second abstract syntax tree obtained by converting an old version of the code to obtain code change information. Based on the code change information and the constructed service call relationship, the scope of the impact of the code change on the software system is automatically evaluated, and the technical staff is no longer required to manually evaluate the scope of the impact of the code change, so as to improve the efficiency and accuracy of analyzing the impact of the code change.
[0071] It should be noted that in order to better understand the contents of the subsequent embodiments, some terms are explained here: in the code management process, the development of new functions will adopt new branches, and "branch" is equivalent to version; when the new function is completed, the code will have a new branch (or a new version), and the new code branch must be merged into the old code branch (the last released code). This process is called code merging or version merging; a note information will be provided during each code merge process. The note information is used to characterize the purpose of the new code branch, and the note information is also called submission information.
[0072] See also Figure 1 , shows a flow chart of a method for analyzing the impact of code changes provided by an embodiment of the present invention, the method comprising:
[0073] Step S101: Pull the new version code corresponding to the old version code.
[0074] It should be noted that the pre-built code management platform can trigger a code merge event (i.e., a new code branch is merged into an old code branch). After the code management platform detects a code merge event, it will send an analysis request to start the analysis process of the impact of code changes.
[0075] In some embodiments, before executing step S101, an analysis request sent by the code management platform when a code merge event is detected is received. The analysis request is used to trigger an analysis process of the impact of code changes. The analysis request is a webhook or an application programming interface (API) request.
[0076] The analysis request is validated; when the analysis request passes the validity verification, step S101 is executed.
[0077] In the specific implementation of step S101, when the analysis request passes the validity verification, a new code branch and submission information are obtained, and then the latest code corresponding to the new code branch is pulled from the remote warehouse. The latest code is called the new version code.
[0078] For example: Use version control system tools such as Git to pull new version codes from remote warehouses.
[0079] It should be noted that the code merge event is used to merge the new code branch into the old code branch, so there is a corresponding relationship between the new version code and the old version code (the code corresponding to the old code branch), that is, the new version code is the code branch merged into the old version code.
[0080] In some embodiments, after the new version code is pulled, a temporary directory is created on the local file system to store the new version code, ensuring that there is sufficient disk space to store the new version code.
[0081] Step S102: Convert the new version code into a first abstract syntax tree.
[0082] In the specific implementation process of step S102, a designated parser is called to convert the new version code into a first abstract syntax tree, which is recorded as AST.
[0083] The specified parser mentioned above is any one of the following programming language parsers: Python's AST module, Java's ANTLR.
[0084] In the specific implementation, in order to accurately convert the new version code into the first abstract syntax tree, it is necessary to select a designated parser according to the actual situation of the new version code. For example, when the new version code is Python code, you can select Python's AST module to convert the new version code into the first abstract syntax tree; when the new version code is Java code, you can select Java's ANTLR to convert the new version code into the first abstract syntax tree; by selecting a suitable parser (designated parser), it is ensured that the new version code can be accurately converted into the first abstract syntax tree.
[0085] In some embodiments, after converting the new version code into a first abstract syntax tree, the first abstract syntax tree is traversed to collect node data of the first abstract syntax tree, and the node data includes node and node relationship information; further, the node data includes but is not limited to: code structure information, functions, parameters, and function call links.
[0086] The node data of the first abstract syntax tree is stored in a graph database, so as to better represent the complex relationship between the nodes of the first abstract syntax tree.
[0087] Step S103: Constructing a service call relationship.
[0088] In the specific implementation of step S103, target information is parsed from the first abstract syntax tree, and the target information at least includes: external interface information, external interface calling information, class relationship and / or message interaction information; and a service calling relationship is constructed according to the target information.
[0089] Specifically, the nodes of the first abstract syntax tree are analyzed to obtain information that can be used to construct the calling relationship between services. The information that can be used to construct the calling relationship between services is called target information.
[0090] For example: parse the target information such as external interface information, calling external interface information, class relationship, message interaction information, etc. from the nodes of the first abstract syntax tree, and then build a service call relationship based on these target information. The service call relationship is the call relationship between services (such as microservices).
[0091] The service call relationship reflects the mutual call relationship between services. For example, the a1 interface of service A calls the b1 interface of service B. The aforementioned process is the service call relationship.
[0092] For another example: Service A sends message a, and service B consumes message a through a message queue such as Kafka to perform business processing. The aforementioned process is also a service call relationship.
[0093] Step S104: Compare the first abstract syntax tree with the second abstract syntax tree converted from the old version code to obtain code change information.
[0094] It should be noted that when the old version code is released, the old version code has been converted into a second abstract syntax tree in advance, and the node data of the second abstract syntax tree is stored in the graph database.
[0095] In the process of implementing step S104, based on the node data of the first abstract syntax tree and the second abstract syntax tree, an AST comparison tool (such as Gumtree) is called to compare the first abstract syntax tree and the second abstract syntax tree to obtain code change information between the new version code and the old version code.
[0096] Specifically, the AST comparison tool is called to compare the first abstract syntax tree and the second abstract syntax tree based on factors such as node type, node attributes, number of child nodes, etc., to analyze and mark the code change information (also called change points or difference points) between the new version code and the old version code.
[0097] Among them, code change information includes but is not limited to any one or more of the following: deleted code, newly added code, changed classes (indicating which classes have changed), changed functions (indicating which functions have changed), changed return values, changed function logic, no changes and only added comment information.
[0098] Step S105: Determine the impact scope of the code change on the software system based on the service call relationship and the code change information.
[0099] In the process of implementing step S105, the impact scope of the code change on the software system is determined based on the service call relationship constructed in step S103 and the code change information obtained in step S104.
[0100] It should be noted that the scope of impact of code changes on the software system can be divided into: the scope of impact of code changes on specified objects such as functions and classes (called the first scope of impact), and the scope of impact of code changes on upstream and downstream services (called the second scope of impact).
[0101] In the process of analyzing the impact scope of code changes on the software system, when a function or class is found to have changed, the "dependencies between classes and / or functions" are used to determine which functions or classes will be affected by the changed function or class, thereby identifying the first impact scope of the code change on specified objects such as functions and classes;
[0102] According to the calling relationship between services in the service calling relationship, identify the second impact scope of the code change on the upstream and downstream services;
[0103] By comprehensively identifying the first impact scope and the second impact scope, we can get the impact scope of the code change on the software system at the overall level.
[0104] In some embodiments, after determining the impact scope of the code change on the software system, the impact scope of the code change on the software system is displayed using a change heat map and / or an impact tree.
[0105] For example, in the user interface, a change heat map and / or impact tree are used to visualize the impact of the determined code changes on the software system.
[0106] In other embodiments, after determining the scope of impact of the code change on the software system, a code change report is generated, which includes at least: code change information, the scope of impact of the code change on the software system, recommended actions, etc.; the code change report and / or code change notification information is sent to designated personnel.
[0107] For example: generate a code change report, send the code change report and code change notification to designated personnel such as developers and / or testers via email, and remind the designated personnel to pay attention to the impact of the code change.
[0108] In an embodiment of the present invention, a first abstract syntax tree converted from a new version of the code is compared with a second abstract syntax tree converted from an old version of the code to obtain code change information. Based on the code change information and the constructed service call relationship, the impact of the code change on the software system is automatically evaluated, and the impact of the code change is no longer manually evaluated by technicians, thereby improving the efficiency and accuracy of analyzing the impact of code changes.
[0109] For the above-mentioned embodiments of the present invention Figure 1 Step S105 involves determining the impact of the code change on the software system, see Figure 2 , showing a flowchart of determining the impact range of a code change on a software system provided by an embodiment of the present invention, Figure 2 The steps include:
[0110] Step S201: Analyze the impact of code change information on a specified object to identify a first impact range.
[0111] It should be noted that the specified object includes at least a function and a class.
[0112] In the specific implementation of step S201, the impact of the code change information on specified objects such as functions and classes is analyzed, so as to identify the first impact scope (equivalent to identifying the impact scope inside the code).
[0113] It should be noted that the calls between codes are mutually dependent relationships. When the code completes a function, it is usually completed by multiple classes and / or functions. There is a dependency relationship between the multiple classes and / or functions that complete a function.
[0114] In the process of parsing the impact of code change information on specified objects such as functions and classes, when it is parsed that a function or class has changed, through the dependency relationship mentioned above, it is possible to determine which functions or classes will be affected by the changed function or class, thereby identifying the first impact range.
[0115] Step S202: Analyze the impact of the code change information on upstream and downstream services based on the service call relationship to identify a second impact range.
[0116] In the process of specifically implementing step S202, based on the service call relationship, the impact of the code change information on the upstream and downstream services is analyzed, so as to identify the second impact scope (equivalent to identifying the impact scope of the external service).
[0117] Among them, "upstream and downstream services" refer to upstream services and downstream services of code change information (such as changed interfaces, messages, etc.).
[0118] Step S203: Merge the first impact scope and the second impact scope to determine the impact scope of the code change on the software system.
[0119] In the specific implementation of step S203, after the first impact scope and the second impact scope are identified, the first impact scope and the second impact scope are merged to determine the impact scope of the code change on the entire software system.
[0120] In the embodiment of the present invention, the first impact scope of the code change on the internal code and the second impact scope of the code change on the external service are identified respectively by using the code change information and the service call relationship, and the first impact scope and the second impact scope are combined to obtain the impact scope of the code change on the software system at the overall level. As can be seen from the foregoing content, the impact scope of the code change on the internal code and the external service is analyzed separately, and the impact scope is analyzed from multiple perspectives, thereby ensuring the comprehensiveness of the code change impact analysis.
[0121] The above embodiments of the present invention Figure 1 and Figure 2 How to analyze the impact of code changes has been described in detail in order to further understand the above embodiments of the present invention. Figure 1 and Figure 2 The following content is Figure 3 The overall architecture example diagram of a method for analyzing the impact of code changes is shown, which illustrates an embodiment of the present invention from an overall aspect. Figure 3 Includes steps S301 to S309.
[0122] Step S301: The developer initiates a code merge event on the code management platform to start merging the old version code and the new version code.
[0123] Step S302: The code management platform sends an analysis request.
[0124] Step S303: Use GitLib to pull the new version code from the remote repository.
[0125] Step S304: Store the new version code in the local file system.
[0126] Step S305: Perform static code analysis on the new version code.
[0127] In the specific implementation of step S305 , the new version code is converted into a first abstract syntax tree, and the first abstract syntax tree is traversed to collect node data of the first abstract syntax tree.
[0128] Step S306: Store the node data of the first abstract syntax tree in a graph database (AST database).
[0129] It should be noted that if it is the first time to perform static code parsing on the code, the subsequent step S307 is not performed, and only the node data of the first abstract syntax tree is stored in the graph database.
[0130] Step S307: Call an AST comparison tool to compare the first abstract syntax tree with the second abstract syntax tree to obtain code change information between the new version code and the old version code; and analyze the impact of the code change information on the specified object to identify the first impact range.
[0131] Step S308: Analyze the impact of the code change information on upstream and downstream services based on the service call relationship to identify the second impact scope; and combine the first impact scope and the second impact scope to evaluate the impact scope of the code change on the entire software system.
[0132] Step S309: Output the impact of the code change on the entire software system through visualization, notification, report, etc.
[0133] After identifying the scope of impact of the code change on the entire software system, in order to enable the scope of impact of the code change on the entire software system to be displayed to designated personnel intuitively and promptly, in the process of specifically implementing step S309, the scope of impact of the code change on the entire software system is output in a variety of forms, including visualization, notification and / or reporting.
[0134] Specifically, the impact scope of the determined code change on the software system is displayed in a visual style such as a change heat map and / or an impact tree, and code change notification information and the generated code change report are sent; for example: code change notification information is sent to developers, and code change reports are displayed to testers, and the impact scope of the code change on the software system is displayed.
[0135] It can be understood that the scope of impact of code changes on software systems is divided into: the first scope of impact of code changes on the code internally and the second scope of impact of code changes on external services;
[0136] When using visual styles such as change heat maps and / or impact trees to display the impact scope of the determined code change on the software system, in the change heat map and / or impact tree, the first impact scope and the second impact scope can be displayed separately through different display styles, and the first impact scope and the second impact scope can also be displayed separately through different display interfaces, thereby assisting designated personnel to clearly and quickly check the first impact scope and the second impact scope.
[0137] Accordingly, when the code change notification information and the generated code change report are sent to the designated personnel, the first impact scope and the second impact scope are highlighted respectively in different display styles, thereby assisting the designated personnel to quickly locate and view the first impact scope and the second impact scope.
[0138] It should be noted that Figure 3 The execution principle of each step in the above-mentioned embodiment of the present invention can be referred to. Figure 1 and Figure 2 The content will not be repeated here.
[0139] In summary Figures 1 to 3 As can be seen from the content, the process of analyzing the impact of code changes in the embodiment of the present invention can be divided into the following three parts:
[0140] (1) Parsing the abstract syntax tree:
[0141] In order to accurately convert the code into an abstract syntax tree, a specified programming language parser is selected according to the actual situation of the code to convert the code into an abstract syntax tree, and comments, document strings and other parts that do not affect the execution logic but may contain important information are processed during the conversion process.
[0142] (2) Analysis of code structure components:
[0143] After converting the code into an abstract syntax tree, parse the expressions, statements, function definitions, class definitions, etc. in the abstract syntax tree, and mark the types and properties (such as scope, parameter list, and return value type, etc.) of the expressions, statements, function definitions, class definitions, etc. in the abstract syntax tree; identify and mark key nodes such as function calls, variable declarations, and variable references in the code; and the parsing of the code structure components can be completed through the above processing.
[0144] (3) Identification of the impact of code changes:
[0145] Compare the abstract syntax trees of the new and old versions of the code to identify the newly added, modified, or deleted code or elements between the new and old versions of the code; analyze the changes in functions between the new and old versions of the code (such as parameter changes, return value changes, internal logic changes), and analyze how the changes in functions affect other parts that call "the changed function."
[0146] In general, applying the embodiments of the present invention to analyze the impact of code changes will achieve the following results:
[0147] Beneficial effects:
[0148] Automated analysis: When the code changes, the embodiments of the present invention can automatically analyze the scope of impact of the code change on the software system, eliminating the need for technical personnel to spend time analyzing the impact of the code change, reducing the time and cost of evaluating the scope of impact of the code change, and improving development efficiency.
[0149] Comprehensiveness: By building service call relationships, we can deeply analyze the impact of code changes on various classes, methods, entries, and service call relationships in the software system, thereby analyzing the impact of code changes on internal and external services of the code to ensure the comprehensiveness of the analysis.
[0150] Accuracy: Combining Git and source code analysis technology, it can accurately identify the location and content of code changes, and accurately compare the change points before and after the code changes to improve the accuracy of the analysis.
[0151] Visual presentation: The analysis results of the code change impact are presented to designated personnel in a visual manner, so that designated personnel can intuitively understand the scope of the code change impact.
[0152] High integration convenience: The embodiments of the present invention can be integrated into the existing development process (such as CI / CD process) to realize automatic triggering of code change impact analysis and feedback of the results of code change impact analysis.
[0153] Reduce risks: By identifying the impact of code changes in advance, the development team can fix potential problems before the code is released, reducing the risk of online accidents.
[0154] Corresponding to the method for analyzing the impact of code changes provided by the above embodiment of the present invention, see Figure 4 , the embodiment of the present invention also provides a structural block diagram of a device for analyzing the impact of code changes, the device comprising: a pulling unit 100, a conversion unit 200, a construction unit 300, a comparison unit 400 and a determination unit 500;
[0155] The pulling unit 100 is used to pull a new version code corresponding to the old version code, where the new version code is a code branch merged into the old version code.
[0156] The conversion unit 200 is used to convert the new version code into a first abstract syntax tree.
[0157] In a specific implementation, the conversion unit 200 is specifically used to: call a specified parser to convert the new version code into a first abstract syntax tree.
[0158] The construction unit 300 is used to construct a service call relationship.
[0159] The comparison unit 400 is used to compare the first abstract syntax tree with the second abstract syntax tree converted from the old version code to obtain code change information.
[0160] The determination unit 500 is used to determine the impact scope of the code change on the software system according to the service call relationship and the code change information.
[0161] In an embodiment of the present invention, a first abstract syntax tree converted from a new version of the code is compared with a second abstract syntax tree converted from an old version of the code to obtain code change information. Based on the code change information and the constructed service call relationship, the impact of the code change on the software system is automatically evaluated, and the impact of the code change is no longer manually evaluated by technicians, thereby improving the efficiency and accuracy of analyzing the impact of code changes.
[0162] Preferably, combined Figure 4 As shown in the figure, the determination unit 500 includes a first identification subunit, a second identification subunit and a merging subunit, and the execution principle of each subunit is as follows:
[0163] The first identification subunit is used to analyze the impact of the code change information on the specified object to identify a first impact range, and the specified object at least includes a function and a class.
[0164] A second identification subunit is used to analyze the impact of the code change information on the upstream and downstream services based on the service call relationship to identify the second impact range;
[0165] The merging subunit is used to merge the first impact scope and the second impact scope to determine the impact scope of the code change on the software system.
[0166] In an embodiment of the present invention, code change information and service call relationships are used to identify a first impact scope of the code change on the internal code and a second impact scope of the code change on external services, respectively. The impact scope of the code change on the entire software system can be evaluated by combining the first impact scope and the second impact scope, thereby ensuring the comprehensiveness of the code change impact analysis.
[0167] Preferably, combined Figure 4 The content shown, the construction unit 300 includes a parsing subunit and a construction subunit, and the execution principle of each subunit is as follows:
[0168] The parsing subunit is used to parse the target information from the first abstract syntax tree, where the target information at least includes: external interface information, external interface calling information, class relationship and / or message interaction information.
[0169] The construction subunit is used to construct a service call relationship according to the target information.
[0170] Preferably, combined Figure 4 The device also includes:
[0171] The display unit is used to display the impact scope of code changes on the software system by using a change heat map and / or an impact tree.
[0172] Preferably, combined Figure 4 The device also includes:
[0173] A receiving unit, used to receive an analysis request sent by the code management platform when a code merging event is detected;
[0174] The verification unit is used to verify the validity of the analysis request; when the analysis request passes the validity verification, the pulling unit 100 is executed.
[0175] Preferably, combined Figure 4 The device also includes:
[0176] A report generation unit, used to generate a code change report, the code change report at least includes: code change information, the impact of the code change on the software system;
[0177] The notification unit is used to send a code change report and / or code change notification information to a designated person.
[0178] Preferably, an embodiment of the present invention further provides an electronic device, comprising: a processor and a memory, the processor and the memory being connected via a communication bus; wherein the processor is used to call and execute a program stored in the memory; the memory is used to store the program, and the program is used to implement the method for analyzing the impact of code changes provided in the above method embodiment.
[0179] Preferably, an embodiment of the present invention further provides a computer-readable storage medium, in which computer-executable instructions are stored, and the computer-executable instructions are used to execute the method for analyzing the impact of code changes provided in the above method embodiment.
[0180] In summary, the embodiments of the present invention provide a method, device, electronic device and storage medium for analyzing the impact of code changes, and compare a first abstract syntax tree obtained by converting a new version of the code with a second abstract syntax tree obtained by converting an old version of the code to obtain code change information. Based on the code change information and the constructed service call relationship, the scope of the impact of the code change on the software system is automatically evaluated, and the technical staff is no longer required to manually evaluate the scope of the impact of the code change, thereby improving the efficiency and accuracy of analyzing the impact of the code change.
[0181] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.
[0182] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0183] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for analyzing the impact of code changes, characterized in that: The method comprises: Pull a new version of code corresponding to the old version of code, where the new version of code is a code branch merged into the old version of code; Convert the new version code into a first abstract syntax tree; Build service call relationships; Comparing the first abstract syntax tree with a second abstract syntax tree converted from the old version code to obtain code change information; The impact scope of the code change on the software system is determined based on the service call relationship and the code change information.
2. The method according to claim 1, characterized in that The determining, based on the service call relationship and the code change information, the impact scope of the code change on the software system includes: Parsing the impact of the code change information on a specified object to identify a first impact scope, wherein the specified object includes at least a function and a class; Analyzing the impact of the code change information on upstream and downstream services based on the service call relationship to identify a second impact range; The first impact scope and the second impact scope are combined to determine the impact scope of the code change on the software system.
3. The method according to claim 1, characterized in that Build a service call relationship, including: Parsing target information from the first abstract syntax tree, the target information at least including: external interface information, external interface calling information, class relationship and / or message interaction information; A service call relationship is constructed according to the target information.
4. The method according to claim 1, characterized in that Converting the new version code into a first abstract syntax tree includes: A specified parser is called to convert the new version code into a first abstract syntax tree.
5. The method according to any one of claims 1 to 4, characterized in that: After determining the scope of impact of the code change on the software system, it also includes: Use change heat maps and / or impact trees to show the scope of impact of code changes on the software system.
6. The method according to any one of claims 1 to 4, characterized in that: Also includes: Receive analysis requests sent by the code management platform when a code merge event is detected; Verifying the validity of the analysis request; When the analysis request passes the validity verification, the step of pulling a new version code corresponding to the old version code is performed.
7. The method according to any one of claims 1 to 4, characterized in that: Also includes: Generate a code change report, the code change report at least including: the code change information, the impact of the code change on the software system; Send the code change report and / or code change notification information to a designated person.
8. A device for analyzing the impact of code changes, characterized in that: The device comprises: A pulling unit, used to pull a new version code corresponding to an old version code, wherein the new version code is a code branch merged into the old version code; A conversion unit, configured to convert the new version code into a first abstract syntax tree; Construction unit, used to build service call relationship; A comparison unit, used for comparing the first abstract syntax tree with a second abstract syntax tree converted from the old version code to obtain code change information; A determination unit is used to determine the impact scope of the code change on the software system according to the service call relationship and the code change information.
9. An electronic device, characterized in that: include: A processor and a memory, wherein the processor and the memory are connected via a communication bus; wherein the processor is used to call and execute a program stored in the memory; The memory is used to store a program, and the program is used to implement the method for analyzing the impact of code changes as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to execute the method for analyzing the impact of code changes described in any one of claims 1-7.
Citation Information
Cited By
Structured processing method and device for software engineering elements, electronic equipment and medium
CN121455449A