GIT-based automatic source code difference analysis method, device and storage medium
By establishing demand correlation and code submission information models in the demand management system, the push events of the GIT source code library are automatically analyzed, which solves the problem of relying on manual operations in the identification and tracking of source code changes in the existing technology, and realizes the identification of source code differences. Automated analysis and report generation improve the efficiency of the software development process and the speed of product launch.
Patent Information
- Application Number
- CN202410813549.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-24
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2044-06-24
AI Technical Summary
The existing GIT source code management system relies on manual operations when identifying and tracking source code changes, making the operations highly complex, time-consuming, and unable to be automated, affecting the efficiency and speed of product construction.
By establishing a demand association relationship model and a code submission information model, the push events of the GIT source code library are monitored in the demand management system, the source code difference data is automatically analyzed, an analysis report is generated and associated with the product, and automatic tracking of source code changes is realized. Identify.
It significantly improves the management and control level of the software development process, optimizes the overall efficiency, reduces manual intervention, increases the speed of product launch, and meets the security control and efficiency improvement needs of enterprises.
Smart Images

Figure CN118377725B
Abstract
Description
Technical Field
[0001] The present application relates to the field of software engineering technology, and in particular to a method, device and storage medium for automatic source code difference analysis based on GIT. Background Art
[0002] As enterprises have increasingly stringent requirements for security control of software development processes, especially in core links such as source code management, product construction and product launch, many enterprises have required that continuous integration tools must be able to automatically track and analyze the source code repository, branches, changed file lists, and number of changed code lines directly related to each built product, and provide reports to display these source code-related change data.
[0003] In current software engineering practice, source code management generally adopts a version control system based on the GIT protocol. This system submits the software source code written by developers on local computers to the GIT repository on the remote server through commit and push operations, and uses a unique commit ID to identify each commit. This mechanism provides a solid foundation for version control in the software development process.
[0004] In order to identify the source code change list, the GIT protocol provides a set of commands. However, when using these commands, there are three significant problems: First, since GIT stores source code commit records in a linear manner in time order, including all historical commit records of the entire source code library, if there is no special means, the starting point of the commit record can only be identified manually based on the commit record log. Second, it is highly dependent on manual operation, requiring users to enter a series of commands in the command line to query the commit record and manually record relevant information, which not only increases the complexity of the operation and may cause human errors, but also the processing process is very time-consuming. Third, when multiple commits contain changes to the same file, the information output by the command still needs to be manually verified and deduplicated. This manual processing method cannot be combined with continuous integration tools, resulting in the key links in the product construction process that should have been automated still requiring manual intervention, which seriously affects the overall efficiency and the speed of product launch, and is also contrary to the purpose of efficiency improvement advocated by enterprises.
[0005] Therefore, in order to solve these problems, we need to seek a more efficient and automated solution, which can reduce manual operations as much as possible while retaining the original collaborative habits of developers, and increase automated processing steps to achieve accurate tracking and identification of source code change data. This will help significantly improve the control level of the software development process, optimize overall efficiency, speed up the launch of products, better meet the demands of enterprise security control and efficiency improvement, and provide solid support for the sustainable development and competitiveness improvement of enterprises. Summary of the invention
[0006] Based on this, the embodiment of the present application provides a method, device and storage medium for automatic source code difference analysis based on GIT to solve the problems existing in the related technologies. The technical solution is as follows:
[0007] In a first aspect, an embodiment of the present application provides a method for automatically analyzing source code differences based on GIT, comprising:
[0008] Establishing a demand association relationship model, wherein the demand association relationship model is used to guide the demand association relationship table in the demand management system;
[0009] Establishing an association relationship between requirements and GIT source code libraries and branches in the requirements management system, wherein the association relationship refers to the association relationship between requirements and GIT source code libraries, source branches, target branches, and baseline commit-id, wherein GIT refers to a popular, distributed software source code version management system, the GIT source code library refers to a source code library repository stored in GIT, and the baseline commit-id refers to a commit id corresponding to a commit in the GIT source code library;
[0010] Listening to a push event of a GIT source code repository in the demand management system, wherein the push event refers to an event type in a webhook function in the GIT source code repository, indicating an action of a user pushing code to the GIT source code repository;
[0011] Establishing a code submission information model, wherein the code submission information model is used to guide the creation of a code submission information table in a demand management system;
[0012] Automatically analyze source code in the pipeline of the continuous integration system to obtain submission difference data; the first step is to create a new build pipeline in the continuous integration system, and configure the GIT source code library and branch information in the pipeline; the second step is for the pipeline to pull source code according to the configured GIT source code library and branch; the third step is to call the requirement item query interface of the requirement management system through the requirement query plug-in in the pipeline. The interface receives two parameters, the GIT source code library and the target branch, and passes them into the GIT source code library and branch configured in the pipeline respectively to obtain the requirements corresponding to the source code of this build, and then call the requirement details query interface of the requirement management system, pass in the requirement identifier, obtain the requirement details, parse the requirement details, and obtain the baseline commit-id associated with the requirement; the fourth step is to call the GIT command through the submission information query plug-in in the pipeline to calculate the new submission record list, the change file list, and the number of changed code lines in the source code of this build starting from the baseline commit-id. The GIT command called is: git log--pretty=oneline--numstat commit_id..HEAD, where commit_id should be replaced with the starting commit-id you want to query, HEAD represents the latest commit-id of the current branch, and the --stat parameter causes the command output to include the change statistics of each file in each commit, which clearly shows which files have been modified, added, or deleted; the pipeline refers to an automated continuous integration system used by software developers, and the difference data refers to the commit records between two commits in the GIT source code repository, the list of changed source code files, the number of changed code lines, the GIT source code repository, and the branch;
[0013] An analysis report is produced in the pipeline of the continuous integration system and is associated with the product. The analysis report refers to a report file that records requirements and difference data.
[0014] Establish a relationship model between requirements and GIT source code repository, source branch, target branch, and baseline. Software developers use the requirement relationship model as a guide to create a corresponding requirement relationship table in the requirement management system.
[0015] This model must follow the following three constraints: 1. The same GIT source code repository and target branch can only be associated with one requirement; 2. The same GIT source code repository and source branch can be associated with multiple requirements at the same time; 3. The same requirement can only be associated with one GIT source code repository, source branch, and target branch.
[0016] Requirements in the requirements management system support the creation of associations between requirements and GIT source code repositories, source branches, and target branches. When the association is successfully created, the requirements management system calls the GIT interface to read the commit-id of the latest commit of the source branch, and updates the commit-id as the baseline commit-id to the association.
[0017] The requirements in the requirements management system support creating branches and establishing associations on the specified GIT source code repository. When creating, select the GIT source code repository, source branch, and fill in the custom target branch name. After submission, the requirements management system uses the custom target branch name to create a new branch based on the source branch. After successful creation, the requirements management system records the association between the requirements and the GIT source code repository, source branch, and custom target branch name. After that, the requirements management system calls the GIT interface to read the commit-id of the latest submission of the source branch, and updates the commit-id as the baseline commit-id to the association.
[0018] Select the push event in the webhook configuration of the GIT source code library and view the event message body. The demand management system develops a push event listening interface based on the push event message body and configures the push event listening interface to the push event hook.
[0019] When receiving the code submission pushed by the user, the GIT source code repository will look for the push event configuration, assemble the event message body and trigger the push event after finding the matching event configuration, and call back the push event listening interface. After the demand management system receives the push event callback from the GIT source code repository, it parses the push event listening interface message body to obtain the GIT source code repository, branch and its latest commit-id pushed this time. The demand management system provides a query interface for requirement items. The requirement item query interface receives two parameters, the GIT source code repository and the source branch, and passes them into the GIT source code repository and branch parsed from the push event message body respectively, queries all associated requirements, and updates the baseline commit-id of the associated requirements to the latest commit-id. This step will ensure that the baseline commit-id associated with the requirement is always synchronized with the GIT source code repository.
[0020] Establish a code submission information model for requirements and GIT source code repository, branches, requirement identifiers, new code submission record lists, changed file lists, and changed code lines. Software developers use the submission information model as a guide to create corresponding code submission information tables in the requirement management system.
[0021] The source code is automatically analyzed in the pipeline of the continuous integration system, and the new code submission record list, change file list, number of changed code lines, requirement identification, GIT source code library, and branch merge are added for this build. Then, the new requirement change record interface of the requirement management system is called to write the data into the code submission information table of the requirement management system.
[0022] When executing the pipeline, the build command is executed, the source code is compiled and built to form a binary package, which is archived into the artifact library through the artifact archiving interface;
[0023] When executing the pipeline, the download analysis report plug-in calls the demand management system download analysis report interface. The interface will generate a submission information analysis report based on the parameters passed in by the user. After the pipeline receives the report, it stores the report and provides it to the user for download;
[0024] Write the requirements related to this build, source code related information, and analysis reports to the artifact metadata through the metadata writing interface.
[0025] In a second aspect, an embodiment of the present application provides a management device, including:
[0026] Construction unit: establishing a demand association relationship model, the demand association relationship model is used to guide the creation of a demand association relationship table in the demand management system; establishing a code submission information model, the code submission information model is used to guide the creation of a code submission information table in the demand management system;
[0027] Processing unit: used to provide a push event monitoring interface, which is used to monitor code submission events in the GIT source code library; provide a new requirement change record interface, which is used to record the submission record list, the change file list, the number of changed code lines, together with the requirement identifier, the GIT source code library, and the branch; download analysis report interface, which is used to generate a submission information analysis report according to the parameters passed in by the user;
[0028] In one possible design, the building block is specifically used for:
[0029] Establish a relationship model between requirements and GIT source code repository, source branch, target branch, and baseline. Software developers use the requirements relationship model as a guide to create a corresponding requirements relationship table in the requirements management system.
[0030] The requirement association model must comply with the following three constraints: 1. The same GIT source code repository and target branch can only be associated with one requirement; 2. The same GIT source code repository and source branch can be associated with multiple requirements at the same time; 3. The same requirement can only be associated with one GIT source code repository, source branch, and target branch.
[0031] Establish a submission information model for requirements and GIT source code repository, branches, requirement identifiers, new code submission record lists, changed file lists, and changed code lines. Software developers use the submission information model as a guide to create corresponding code submission information tables in the requirements management system.
[0032] In a possible design, the processing unit is specifically used for:
[0033] Requirements in the requirements management system support the creation of associations between requirements and GIT source code repositories, source branches, and target branches. When the association is successfully created, the requirements management system calls the GIT interface to read the commit-id of the latest commit of the source branch, and updates the commit-id as the baseline commit-id to the association.
[0034] The requirements in the requirements management system support creating branches and establishing associations on the specified GIT source code repository. When creating, select the GIT source code repository, source branch, and fill in the custom target branch name. After submission, the requirements management system uses the custom target branch name to create a new branch based on the source branch. After successful creation, the requirements management system records the association between the requirements and the GIT source code repository, source branch, and custom target branch name. After that, the requirements management system calls the GIT interface to read the commit-id of the latest submission of the source branch, and updates the commit-id as the baseline commit-id to the association.
[0035] In one possible design, the processing unit is further configured to:
[0036] Select the push event in the webhook configuration of the GIT source code library and view the event message body. The demand management system develops a push event listening interface based on the push event message body and configures the push event listening interface to the push event hook.
[0037] When receiving the code submission pushed by the user, the GIT source code repository will look for the push event configuration, assemble the event message body and trigger the push event after finding the matching event configuration, and call back the push event listening interface. After the demand management system receives the push event callback from the GIT source code repository, it parses the push event listening interface message body to obtain the GIT source code repository, branch and its latest commit-id pushed this time. The demand management system provides a query interface for requirement items. The requirement item query interface receives two parameters, the GIT source code repository and the source branch, and passes them into the GIT source code repository and branch parsed from the push event message body respectively, queries all associated requirements, and updates the baseline commit-id of the associated requirements to the latest commit-id. This step will ensure that the baseline commit-id associated with the requirement is always synchronized with the GIT source code repository.
[0038] In one possible design, the processing unit is further configured to:
[0039] In the continuous integration system, create a new build pipeline, and configure the GIT source code library and branch information for the pipeline;
[0040] When executing the pipeline, the pipeline pulls the source code according to the configured GIT source code repository and branch, and then calls the requirement item query interface of the requirement management system through the requirement query plug-in. The interface receives two parameters, the GIT source code repository and the target branch, and passes them into the GIT source code repository and branch configured by the pipeline respectively, to obtain the requirements corresponding to the source code of this build, and then calls the requirement detail query interface of the requirement management system, passes in the requirement ID, obtains the requirement details, parses the requirement details, and obtains the baseline commit-id associated with the requirement;
[0041] In the pipeline, the GIT command is called through the commit information query plug-in to calculate the new commit record list, the list of changed files, and the number of changed code lines in the source code of this build starting from the baseline commit-id. The GIT command called is: git log --pretty=oneline --numstat commit_id..HEAD, where commit_id should be replaced with the starting commit-id you want to query, HEAD represents the latest commit-id of the current branch, and the --stat parameter makes the command output include the change statistics of each file in each commit. These change statistics clearly show which files have been modified, added, or deleted;
[0042] Merge the newly added submission record list, changed file list, number of changed code lines, together with the requirement identifier, GIT source code library, and branch, then call the new requirement change record interface of the requirement management system to write the data into the code submission information table of the requirement management system.
[0043] In one possible design, the processing unit is further configured to:
[0044] When executing the pipeline, the build command is executed, the source code is compiled and built to form a binary package, which is archived into the artifact library through the artifact archiving interface;
[0045] When executing the pipeline, the download analysis report plug-in calls the demand management system download analysis report interface. The interface will generate a submission information analysis report based on the parameters passed in by the user. After the pipeline receives the report, it stores the report and provides it to the user for download;
[0046] Write the requirements related to this build, source code related information, and analysis reports to the artifact metadata through the metadata writing interface.
[0047] In a third aspect, an embodiment of the present application further provides a computer device, comprising: a memory and a processor. The memory stores instructions, and the instructions are loaded and executed by the processor to implement the method in any of the above-mentioned embodiments. The memory and the processor communicate with each other through an internal connection path.
[0048] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a computer, the method in any one of the above-mentioned embodiments is implemented.
[0049] The advantages or beneficial effects of the above technical solution include at least:
[0050] Compared with the prior art, the present invention establishes a demand association relationship model, which is used to guide the demand association relationship table in the demand management system. The demand management system is an application system for managing software development requirements in an enterprise; an association relationship is established in the demand management system, and the association relationship refers to the association relationship between the demand and the GIT source code library, the source branch, the target branch, and the baseline commit-id. GIT refers to a popular, distributed software source code management system. The GIT source code library refers to the source code library warehouse stored in GIT, and the baseline commit-id refers to the commit id corresponding to a commit in the GIT source code library; the push events of the GIT source code library are monitored in the demand management system. The push event refers to an event type in the webhook function in the GIT source code repository, which indicates the behavior of users pushing code to the GIT source code repository; a code submission information model is established, which is used to guide the creation of a code submission information table in the demand management system; the source code is automatically analyzed in the pipeline to obtain submission difference data. The pipeline refers to an automated continuous integration system used by software developers. The difference data refers to the submission records between two submissions in the GIT source code repository, the list of changed source code files, the number of changed code lines, the GIT source code repository, and the branch; an analysis report is made in the pipeline and associated with the product. The analysis report refers to a report file that records requirements and difference data. By cleverly using the demand management system, GIT, continuous integration system and its extension plug-ins, and product library, effective integration of the four system data can be achieved. This not only facilitates the automated collection of requirements, but can also be linked to the submission information in the GIT source code library, including detailed data such as changed code files and number of code lines, and the data collection process is converted from manual to automatic, thereby significantly improving the management and control level of the software development process, optimizing overall efficiency, and speeding up the launch of products, better meeting the company's demands for security management and efficiency improvement, and providing solid support for the company's sustainable development and competitiveness improvement.
[0051] The above summary is for illustrative purposes only and is not intended to be limiting in any way. In addition to the illustrative aspects, embodiments and features described above, further aspects, embodiments and features of the present application will be readily apparent by reference to the accompanying drawings and the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the accompanying drawings required for use in the embodiments will be briefly introduced below. In the accompanying drawings, unless otherwise specified, the same reference numerals throughout multiple drawings represent the same or similar parts or elements. These drawings are not necessarily drawn to scale. It should be understood that the following drawings only illustrate certain embodiments of the present application and are therefore not to be regarded as limiting the scope. For those of ordinary skill in the art, other relevant drawings can also be obtained based on these drawings without paying creative work.
[0053] Figure 1 A schematic diagram of a flow chart of a GIT-based source code difference automatic analysis method provided by the present invention;
[0054] Figure 2 An example diagram of the demand association relationship model provided by the present invention;
[0055] Figure 3 An example diagram of the timing of creating a demand association relationship and setting a baseline commit-id provided by the present invention;
[0056] Figure 4 An example diagram of the timing of creating a target branch, requiring associations, and setting a baseline commit-id provided by the present invention;
[0057] Figure 5 A timing example diagram of monitoring GIT source code repository commit events and timely updating baseline commit-id provided by the present invention;
[0058] Figure 6 An example diagram of the submission information model provided by the present invention;
[0059] Figure 7 An example diagram of the timing sequence of source code difference data automatically analyzed by the pipeline provided by the present invention;
[0060] Figure 8 An example diagram of the timing of the pipeline download analysis report provided by the present invention;
[0061] Fig. 9 A schematic diagram of the structure of a management device provided by the present invention. DETAILED DESCRIPTION
[0062] In the following, only some exemplary embodiments are briefly described. As those skilled in the art will appreciate, the described embodiments may be modified in various ways without departing from the spirit or scope of the present application. Therefore, the drawings and descriptions are considered to be exemplary and non-restrictive in nature.
[0063] The terms used in this specification are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms of "a", "said" and "the" used in this specification are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in this specification refers to and includes any or all possible combinations of one or more associated listed items. Unless otherwise specified, ordinal numbers such as "first", "second" used in this specification are used to distinguish multiple objects and are not used to limit the order, timing, priority or importance of multiple objects.
[0064] In order to facilitate understanding of the technical solution provided by the present invention, before introducing the present invention, some terms in the present invention are first explained to facilitate understanding by those skilled in the art.
[0065] The demand management system involved in the present invention refers to an application system for managing software development requirements in an enterprise.
[0066] The GIT involved in the present invention refers to a popular, distributed software source code version management tool.
[0067] The continuous integration system involved in the present invention refers to a popular, plug-in-expandable, highly automated software source code building and publishing tool.
[0068] The product library involved in the present invention refers to a centralized warehouse for storing various versions of software build products and dependent files.
[0069] The data access involved in the present invention refers to exchanging data between the demand management system, GIT, continuous integration system, and product library through a unified and standardized access interface, realizing data flow across systems and laying the foundation for automated data analysis.
[0070] This application discloses a method for automatically analyzing source code differences based on GIT. The method flow chart is as follows: Figure 1 As shown, the following steps are included:
[0071] S11. Establish a demand association relationship model, where the demand association relationship model is used to guide the creation of a demand association relationship table in a demand management system, where the demand management system is an application system for managing software development requirements in an enterprise.
[0072] In a specific implementation example, it is necessary to establish a relationship model between requirements and GIT source code library, source branch, target branch, and baseline. Software developers use the requirement relationship model as a guide to create a corresponding requirement relationship table in the requirement management system.
[0073] The requirement association model must follow the following three constraints: 1. The same GIT source code repository and target branch can only be associated with one requirement; 2. The same GIT source code repository and source branch can be associated with multiple requirements at the same time; 3. The same requirement can only be associated with one GIT source code repository, source branch, and target branch.
[0074] As an example, the field design of the demand association model is as follows Figure 2 As shown in the figure, software developers use this model to create a data requirement association table in the requirement management system.
[0075] S12. Establish an association relationship in the demand management system. The association relationship refers to the association relationship between the demand and the GIT source code repository, source branch, target branch, and baseline commit-id. GIT refers to a popular, distributed software source code management system. The GIT source code repository refers to the source code repository stored in GIT. The baseline commit-id refers to the commit id corresponding to a commit in the GIT source code repository. The association relationship is eventually written into the demand association relationship table.
[0076] In a specific implementation example, Figure 3 As shown in the processing sequence, the requirements in the requirements management system support the creation of associations between requirements and the GIT source code repository, source branches, and target branches. When the association is successfully created, the requirements management system calls the GIT interface to read the commit-id of the latest submission of the source branch, and updates the commit-id as the baseline commit-id to the association, which is finally written into the requirements association table.
[0077] In another specific implementation example, Figure 4 As shown in the processing sequence, the requirements in the requirements management system support creating branches and establishing associations on the specified GIT source code repository. When creating, select the GIT source code repository, source branch, and fill in the custom target branch name. After submission, the requirements management system uses the custom target branch name to create a new branch based on the source branch. After successful creation, the requirements management system records the association between the requirements and the GIT source code repository, source branch, and custom target branch name. After that, the requirements management system calls the GIT interface to read the commit-id of the latest submission of the source branch, and updates the commit-id as the baseline commit-id to the association relationship. The association relationship is finally written into the requirement association relationship table.
[0078] S13. Listen to the push event of the GIT source code repository in the demand management system. The push event refers to an event type in the webhook function in the GIT source code repository, indicating the behavior of the user pushing code to the GIT source code repository.
[0079] In a specific implementation example, Figure 5 As shown in the processing sequence, when the GIT source code repository receives the code submission pushed by the user, it searches for the push event configuration, assembles the event message body after finding the matching event configuration and triggers the push event, and calls back the push event listening interface. After the demand management system receives the push event callback from the GIT source code repository, it parses the push event listening interface message body to obtain the GIT source code repository, branch and its latest commit-id pushed this time. The demand management system provides a query interface for demand items. The demand item query interface receives two parameters, the GIT source code repository and the source branch, and passes them into the GIT source code repository and branch parsed from the push event message body respectively, queries all associated requirements, and updates the baseline commit-id of the associated requirements to the latest commit-id. This step will ensure that the baseline commit-id associated with the requirement is always synchronized with the GIT source code repository.
[0080] As an example, the push event listening interface specification can be as follows:
[0081] Interface address: / api / v1 / eventlistener / push
[0082] Request method: POST
[0083] Query parameters: None
[0084] Path parameters: None
[0085] Request header:
[0086] Fields Data Types Is this field required? describe Content-Type string yes The default value is application / json X-REQ-TOKEN string yes Token issued by the requirements management system X-TIMESTAMP string no Timestamp of the current requesting client
[0087] Request body parameters:
[0088] Fields Data Types Is this field required? describe eventObject object yes commit event message body
[0089] Returns:
[0090] Fields Data Types describe status int System response status code data string System response message. When the processing is successful, this field returns a success message. Here is the processing result message string System response message. When the processing fails or the system is abnormal, this field returns an error message traceId string Request tracking ID, used for error troubleshooting
[0091] S14. Establish a code submission information model, where the code submission information model is used to guide the creation of a code submission information table in the demand management system.
[0092] In a specific implementation instance, it is necessary to establish a code submission information model that includes requirements and GIT source code libraries, branches, requirement identifiers, a list of newly added code submission records, a list of changed files, and the number of changed code lines. Software developers use the submission information model as a guide to create corresponding code submission information tables in the requirements management system.
[0093] As an example, the code submission information model field design is as follows Figure 6 As shown, software developers use this model to create a code submission information table in the requirement management system.
[0094] S15. Automatically analyze source code in the pipeline of the continuous integration system to obtain submission difference data. The pipeline refers to an automated continuous integration system used by software developers. The difference data refers to the submission record between two submissions in the GIT source code repository, the list of changed source code files, the number of changed code lines, the GIT source code repository, and the branch.
[0095] In some possible implementation examples, in a continuous integration system, a new build pipeline is created, and the pipeline is configured with a GIT source code repository and branch information.
[0096] In a specific implementation example, Figure 7 As shown in the processing sequence, when the pipeline is executed, the pipeline pulls the source code according to the configured GIT source code library and branch; in the pipeline, the requirement query plug-in calls the requirement item query interface of the requirement management system, which receives two parameters, the GIT source code library and the target branch, and respectively passes the GIT source code library and branch configured by the pipeline to obtain the requirements corresponding to the source code of this build, and then calls the requirement detail query interface of the requirement management system, passes the requirement identifier, obtains the requirement details, parses the requirement details, and obtains the baseline commit-id associated with the requirement;
[0097] As an example, the requirement item query interface specification can be as follows:
[0098] Interface address: / api / v1 / demand / list
[0099] Request method: GET
[0100] Query parameters:
[0101] Fields Data Types Is this field required? describe libName string yes GIT source code repository name branch string yes Target branch name
[0102] Path parameters: None
[0103] Request header:
[0104] Fields Data Types Is this field required? describe Content-Type string yes The default value is application / json X-REQ-TOKEN string yes Token issued by the requirements management system X-TIMESTAMP string no Timestamp of the current requesting client
[0105] Request body parameters: None
[0106] Returns:
[0107] Fields Data Types describe status int System response status code data string System response message. When the processing is successful, this field returns a success message. Here is the requirement item message string System response message. When the processing fails or the system is abnormal, this field returns an error message traceId string Request tracking ID, used for error troubleshooting
[0108] As an example, the requirement details query interface specification can be as follows:
[0109] API address: / api / v1 / demand / detail
[0110] Request method: GET
[0111] Query parameters:
[0112] Fields Data Types Is this field required? describe demandId string yes Requirement Identification
[0113] Path parameters: None
[0114] Request header:
[0115] Fields Data Types Is this field required? describe Content-Type string yes The default value is application / json X-REQ-TOKEN string yes Token issued by the requirements management system X-TIMESTAMP string no Timestamp of the current requesting client
[0116] Request body parameters: None
[0117] Returns:
[0118] Fields Data Types describe status int System response status code data string System response message. When the processing is successful, this field returns a success message. Here are the requirement details message string System response message. When the processing fails or the system is abnormal, this field returns an error message traceId string Request tracking ID, used for error troubleshooting
[0119] In the pipeline, the GIT command is called through the commit information query plug-in to calculate the new commit record list, changed file list, and number of changed code lines in the source code of this build starting from the baseline commit-id. The called GIT command is: git log--pretty=oneline--numstat commit_id..HEAD, where commit_id should be replaced with the starting commit-id you want to query, HEAD represents the latest commit-id of the current branch, and the --stat parameter makes the command output include the change statistics of each file in each commit. These change statistics clearly show which files have been modified, added, or deleted.
[0120] The source code is automatically analyzed in the pipeline of the continuous integration system, and the new code submission record list, change file list, number of changed code lines, requirement identification, GIT source code library, and branch merge are added for this build. Then, the new requirement change record interface of the requirement management system is called to write the data into the code submission information table of the requirement management system.
[0121] As an example, the interface specification for adding a requirement change record can be as follows:
[0122] Interface address: / api / v1 / scm / changerecord
[0123] Request method: POST
[0124] Query parameters: None
[0125] Path parameters: None
[0126] Request header:
[0127] Fields Data Types Is this field required? describe Content-Type string yes The default value is application / json X-REQ-TOKEN string yes Token issued by the requirements management system X-TIMESTAMP string no Timestamp of the current requesting client
[0128] Request body parameters:
[0129] Fields Data Types Is this field required? describe demandId string yes Requirement ID commitRecords array <commitrecord> < / commitrecord> yes Submit record list
[0130] CommitRecord object:
[0131]
[0132] ChangeRecord Object:
[0133] Fields Data Types Is this field required? describe changeFile string yes Changed files addCount int New lines of code New lines of code delCount int Number of lines of code deleted Number of lines of code deleted
[0134] Returns:
[0135] Fields Data Types describe status int System response status code data string System response message. When the processing is successful, this field returns a success message. Here is the processing result message string System response message. When the processing fails or the system is abnormal, this field returns an error message traceId string Request tracking ID, used for error troubleshooting
[0136] S16. Create an analysis report in the pipeline of the continuous integration system and associate the analysis report with the product. The analysis report refers to a report file that records requirements and difference data.
[0137] In a specific implementation example, Figure 8 In the processing sequence shown, when executing the pipeline, the build command is executed, the source code is compiled and built to form a binary package, which is archived to the product library through the product archiving interface. The product library is a file storage tool for storing binary packages.
[0138] When executing the pipeline, the download analysis report plug-in calls the demand management system download analysis report interface. The interface will generate a submission information analysis report based on the parameters passed in by the user. After the pipeline receives the report, it stores the report and provides it to the user for download;
[0139] Write the requirements related to this build, source code related information, and analysis reports to the artifact metadata through the metadata writing interface.
[0140] As an example, the artifact archive interface specification can be as follows:
[0141] Interface address: / api / v1 / packlib / generic / upload
[0142] Request method: POST
[0143] Query parameters: None
[0144] Path parameters: None
[0145] Request header:
[0146] Fields Data Types Is this field required? describe Content-Type string yes The default value is application / json X-REQ-TOKEN string yes Token issued by the requirements management system X-TIMESTAMP string no Timestamp of the current requesting client
[0147] Request body parameters:
[0148]
[0149] Returns:
[0150] Fields Data Types describe status int System response status code data string System response message. When the processing is successful, this field returns a success message. Here is the product ID message string System response message. When the processing fails or the system is abnormal, this field returns an error message traceId string Request tracking ID, used for error troubleshooting
[0151] As an example, the download analysis report interface specification may be as follows:
[0152] API address: / api / v1 / demand / changerecord
[0153] Request method: GET
[0154] Query parameters:
[0155] Fields Data Types Is this field required? describe demandId string yes Requirement Identification
[0156] Path parameters: None
[0157] Request header:
[0158] Fields Data Types Is this field required? describe Content-Type string yes The default value is application / json X-REQ-TOKEN string yes Token issued by the requirements management system X-TIMESTAMP string no Timestamp of the current requesting client
[0159] Request body parameters: None
[0160] Returns:
[0161]
[0162] As an example, the metadata writing interface specification can be as follows:
[0163] API address: / api / v1 / packlib / metadata
[0164] Request method: POST
[0165] Query parameters:
[0166] Fields Data Types Is this field required? describe productid string yes Product identification
[0167] Path parameters: None
[0168] Request header:
[0169] Fields Data Types Is this field required? describe Content-Type string yes The default value is application / json X-REQ-TOKEN string yes Token issued by the requirements management system X-TIMESTAMP string no Timestamp of the current requesting client
[0170] Request body parameters:
[0171] Fields Data Types Is this field required? describe metadata array <kvpair> < / kvpair> yes Product identification
[0172] KVPair object:
[0173]
[0174] Returns:
[0175]
[0176] From the above description, it can be seen that compared with the prior art, the present invention establishes a demand association relationship model, which is used to guide the demand association relationship table in the demand management system, and the demand management system is an application system for managing software development requirements in an enterprise; an association relationship is established in the demand management system, and the association relationship refers to the association relationship between the demand and the GIT source code library, the source branch, the target branch, and the baseline commit-id. GIT refers to a popular, distributed software source code management system. The GIT source code library refers to the source code library warehouse stored in GIT, and the baseline commit-id refers to the commit id corresponding to a commit in the GIT source code library; the GIT source code library is monitored in the demand management system. A push event refers to an event type in the webhook function in the GIT source code repository, which indicates the behavior of a user pushing code to the GIT source code repository; a code submission information model is established, which is used to guide the creation of a code submission information table in the demand management system; source code is automatically analyzed in the pipeline to obtain submission difference data. The pipeline refers to an automated continuous integration system used by software developers. Difference data refers to submission records between two submissions in the GIT source code repository, a list of changed source code files, the number of changed code lines, the GIT source code repository, and branches; an analysis report is created in the pipeline and associated with the product. The analysis report refers to a report file that records requirements and difference data. By cleverly using the demand management system, GIT, continuous integration system and its extension plug-ins, and product library, effective integration of the four system data can be achieved. This not only facilitates the automated collection of requirements, but can also be linked to the submission information in the GIT source code library, including detailed data such as changed code files and number of code lines, and the data collection process is converted from manual to automatic, thereby significantly improving the management and control level of the software development process, optimizing overall efficiency, and speeding up the launch of products, better meeting the company's demands for security management and efficiency improvement, and providing solid support for the company's sustainable development and competitiveness improvement.
[0177] Based on the same concept, the embodiment of the present invention also provides a management device, such as Fig. 9 As shown, the management device may include: at least one memory 31 and at least one processor 32. Among them:
[0178] At least one memory 31 is used to store one or more programs.
[0179] When one or more programs are executed by at least one processor 32, the above Figure 1The source code version difference analysis method based on GIT repository is shown.
[0180] The management device may also optionally include a communication interface, and the communication interface is used to communicate with external devices and exchange data.
[0181] It should be noted that the memory 31 may include an adjustment RAM memory, and may also include a nonvolatile memory (nonvolatile memory), such as at least one disk memory.
[0182] In the specific implementation process, if the memory 31, the processor 32 and the communication interface are integrated on a chip, the memory 31, the processor 32 and the communication interface can communicate with each other through an internal interface. If the memory 31, the processor 32 and the communication interface are implemented independently, the memory 31, the processor 32 and the communication interface can be connected to each other through a bus and communicate with each other.
[0183] Based on the same inventive concept, an embodiment of the present invention further provides a computer-readable storage medium, which can store at least one program. When the at least one program is executed by a processor, the above Figure 1 The source code version difference analysis method based on GIT repository is shown.
[0184] It should be understood that a computer-readable storage medium is any data storage device that can store data or programs, which can then be read by a computer system. Examples of computer-readable storage media include read-only memory, random access memory, CD-ROM, HDD, DVD, magnetic tape, and optical data storage devices, etc.
[0185] The computer readable storage medium can also be distributed over network coupled computer systems so that the computer readable code is stored and executed in a distributed fashion.
[0186] The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, radio frequency (RF), etc., or any suitable combination of the above.
[0187] The above-mentioned embodiments only express several implementation methods of the present invention, and the description is relatively specific and detailed, but it cannot be understood as limiting the scope of the invention patent. It should be pointed out that for ordinary technicians in this field, several modifications and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention.
Claims
1. A method for automatically analyzing source code differences based on GIT, characterized in that: include: Establishing a demand association relationship model, wherein the demand association relationship model is used to guide the creation of a demand association relationship table in the demand management system; Establishing an association relationship between requirements and GIT source code libraries and branches in the requirements management system, wherein the association relationship refers to the association relationship between requirements and GIT source code libraries, source branches, target branches, and baseline commit-id, wherein GIT refers to a popular, distributed software source code version management system, the GIT source code library refers to a source code library repository stored in GIT, and the baseline commit-id refers to a commit id corresponding to a commit in the GIT source code library; Listening to a push event of a GIT source code repository in the demand management system, wherein the push event refers to an event type in a webhook function in the GIT source code repository, indicating an action of a user pushing code to the GIT source code repository; Establishing a code submission information model, wherein the code submission information model is used to guide the creation of a code submission information table in a demand management system; Automatically analyze source code in the pipeline of the continuous integration system to obtain submission difference data; the first step is to create a new build pipeline in the continuous integration system, and configure the GIT source code library and branch information for the pipeline; the second step is for the pipeline to pull source code according to the configured GIT source code library and branch; The third step is to call the requirement item query interface of the requirement management system through the requirement query plug-in in the pipeline. The interface receives two parameters, the GIT source code library and the target branch, and passes them into the GIT source code library and branch configured in the pipeline respectively, to obtain the requirements corresponding to the source code of this build, and then call the requirement details query interface of the requirement management system, pass in the requirement identifier, obtain the requirement details, parse the requirement details, and obtain the baseline commit-id associated with the requirement; the fourth step is to call the GIT command through the submission information query plug-in in the pipeline, calculate the new submission record list, the change file list, and the number of changed code lines in the source code of this build starting from the baseline commit-id, and the called GIT command is: git log--pretty=oneline--numstat commit_id..HEAD, where commit_id should be replaced with the starting commit-id you want to query, HEAD represents the latest commit-id of the current branch, and the --stat parameter causes the command output to include the change statistics of each file in each commit, which clearly shows which files have been modified, added, or deleted; the pipeline refers to an automated continuous integration system used by software developers, and the difference data refers to the commit records between two commits in the GIT source code repository, the list of changed source code files, the number of changed code lines, the GIT source code repository, and the branch; An analysis report is produced in the pipeline of the continuous integration system and is associated with the product. The analysis report refers to a report file that records requirements and difference data.
2. The method according to claim 1, characterized in that Establish a demand association model, including: Establish a relationship model between requirements and GIT source code repository, source branch, target branch, and baseline. Software developers use the requirements relationship model as a guide to create a corresponding requirements relationship table in the requirements management system. The requirement association model must comply with the following three constraints:
1. The same GIT source code repository and target branch can only be associated with one requirement; 2. The same GIT source code repository and source branch can be associated with multiple requirements at the same time; 3. The same requirement can only be associated with one GIT source code repository, source branch, and target branch.
3. The method according to claim 1, characterized in that: Establish the relationship between requirements and GIT source code libraries and branches in the requirements management system, including: Requirements in the requirements management system support the creation of associations between requirements and GIT source code repositories, source branches, and target branches. When the association is successfully created, the requirements management system calls the GIT interface to read the commit-id of the latest commit of the source branch, and updates the commit-id as the baseline commit-id to the association. The association is eventually written into the requirements association table. The requirements in the requirements management system support creating branches and establishing associations on the specified GIT source code repository. When creating, select the GIT source code repository, source branch, and fill in the custom target branch name. After submission, the requirements management system uses the custom target branch name to create a new branch based on the source branch. After successful creation, the requirements management system records the association between the requirements and the GIT source code repository, source branch, and custom target branch name. After that, the requirements management system calls the GIT interface to read the commit-id of the latest submission of the source branch, and updates the commit-id as the baseline commit-id to the association relationship. The association relationship is finally written into the requirement association relationship table.
4. The method according to claim 1, characterized in that: Listen to the commit events of the GIT source code repository in the demand management system, including: Select the push event in the webhook configuration of the GIT source code library and view the event message body. The demand management system develops a push event listening interface based on the push event message body and configures the push event listening interface to the push event hook. When receiving the code submission pushed by the user, the GIT source code repository will look for the push event configuration, assemble the event message body and trigger the push event after finding the matching event configuration, and call back the push event listening interface. After the demand management system receives the push event callback from the GIT source code repository, it parses the push event listening interface message body to obtain the GIT source code repository, branch and its latest commit-id pushed this time. The demand management system provides a query interface for requirement items. The requirement item query interface receives two parameters, the GIT source code repository and the source branch, and passes them into the GIT source code repository and branch parsed from the push event message body respectively, queries all associated requirements, and updates the baseline commit-id of the associated requirements to the latest commit-id. This step will ensure that the baseline commit-id associated with the requirement is always synchronized with the GIT source code repository.
5. The method according to claim 1, characterized in that Establish a code submission information model, including: Establish a code submission information model for requirements and GIT source code repository, branches, requirement identifiers, new code submission record lists, changed file lists, and changed code lines. Software developers use the submission information model as a guide to create corresponding code submission information tables in the requirement management system.
6. The method according to claim 1, characterized in that Automatically analyze source code in the pipeline of the continuous integration system to obtain difference data, including: The source code is automatically analyzed in the pipeline of the continuous integration system, and the new code submission record list, change file list, number of changed code lines, requirement identification, GIT source code library, and branch merge are added for this build. Then, the new requirement change record interface of the requirement management system is called to write the data into the code submission information table of the requirement management system.
7. The method according to claim 1, characterized in that Produce analysis reports in the pipeline of the continuous integration system and associate all data with the products, including: When executing the pipeline, the build command is executed, the source code is compiled and built to form a binary package, which is archived into the artifact library through the artifact archiving interface; When executing the pipeline, the download analysis report plug-in calls the demand management system download analysis report interface. The interface will generate a submission information analysis report based on the parameters passed in by the user. After the pipeline receives the report, it stores the report and provides it to the user for download; Write the requirements related to this build, source code related information, and analysis reports to the artifact metadata through the metadata writing interface.
8. A management device, characterized in that: include: at least one memory and at least one processor; The at least one memory is used to store one or more programs; When the one or more programs are executed by the at least one processor, the method according to any one of claims 1 to 7 is implemented.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one program; when the at least one program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
