Code Quality Problem Detection and Repair Method for Microservice Continuous Integration
By automatically detecting and repairing code quality problems during the continuous integration of microservices, the problem of single detection methods in the existing technology is solved, and the quality and efficiency of continuous integration in microservices scenarios are improved.
Patent Information
- Application Number
- CN202210737640.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-27
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2042-06-27
AI Technical Summary
In the continuous integration process of the existing technology in the microservice scenario, the detection method of code quality problems is single and the ability to automatically repair, making it difficult for developers to discover and repair code quality problems in a timely manner, affecting the quality and efficiency of continuous integration.
Provide a method and system for detecting and repairing code quality problems for continuous integration of microservices. By obtaining code-related information, it automatically detects multiple quality problems, and repairs them according to repair specifications, and finally feeds the results to developers.
It realizes automatic detection and partial automatic repair of code quality problems in microservice scenarios, improves the quality and efficiency of the continuous integration process, and ensures that code quality problems are timely discovered and repaired.
Smart Images

Figure CN114968819B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of information processing. Specifically, the present invention relates to a method and system for detecting and fixing code quality problems for microservice continuous integration. Background Art
[0002] Microservices are small and autonomous services that work together. It has high cohesion and high autonomy. Microservices determine the service boundary according to the business boundary. It is both an independent entity and can exist as an operating system process. Services communicate with each other through network calls, thus strengthening the isolation between services and avoiding tight coupling. In the microservice scenario, a single application is divided into a group of small services that coordinate and cooperate with each other. Each service runs in its own independent process, and lightweight communication mechanisms are used to communicate between services. Each service is built around a specific business and can be independently deployed to production environments, pre-production environments, etc. Through the microservice architecture, complex applications can be segmented, turning a large and complex problem into multiple small and simple problems, developing a single application using a set of small services, and using lightweight mechanisms to communicate between services to achieve centralized service management.
[0003] Continuous integration is a development method in which the system continuously provides a deliverable version of software and ensures software quality. With the continuous emergence of new service technologies such as microservices, service software has evolved from a simple homogeneous system to a service ecosystem with an open environment, cross-domain scenarios, and complex operations. Traditional service theories and technologies are no longer sufficient to achieve precise matching, dynamic composition, and coupled integration among a large number of heterogeneous services. Continuous integration advocates that development team members integrate the code they have developed as early and as quickly as possible, and each integration is verified through automated builds (including static code scanning, compilation, automated testing, release, etc.), so as to detect integration errors as early as possible and avoid the risks of project delays or project failures. When requirements are unclear or change frequently, by applying continuous integration technology, the software product can always be in a working state and can be released and deployed at any time. The basic value of a continuous integration system lies in fully automated builds and automated testing. Automation helps reduce repetitive processes, saving time, cost, and effort. Automated testing is more efficient and less costly than traditional manual testing, solves highly repetitive testing tasks, changes the situation where traditional manual testing takes up a large amount of project engineering time, and can more fully test each unit in the system. The continuous integration system creates a fast quality feedback loop through automated testing, ensuring software product quality through early testing, early feedback, and early fixing. Therefore, for scenarios like microservices that require the development of multiple services and frequent requirement changes, continuous integration is a very important development method to ensure software quality.
[0004] Currently, the methods for detecting code quality issues during continuous integration are relatively single. For example, only code style detection or code security detection can be performed, and some can only perform unit tests. In addition, there are few tools that can automatically repair the code quality issues detected during continuous integration. If developers can receive relatively comprehensive code quality issue detection and repair results for the current update during the continuous integration process after pushing the code in the microservice scenario to the code repository, it will be beneficial for developers to promptly troubleshoot and repair code quality issues, thereby greatly improving the quality and efficiency of the continuous integration process in the microservice scenario. Summary of the Invention
[0005] The purpose of the present invention is to provide a method and system for detecting and repairing code quality issues for microservice continuous integration, in an attempt to solve or at least alleviate the problems mentioned above.
[0006] According to the first aspect of the present invention, there is provided a method for detecting and repairing code quality issues for microservice continuous integration, including the steps of:
[0007] In the microservice scenario, when a developer pushes code to the code repository, during the continuous integration process of the project, obtain the relevant information of the code;
[0008] Automatically detect various code quality issues according to the detection specifications;
[0009] Automatically repair some of the detected code quality issues according to the repair specifications;
[0010] Unify and feedback the detection and repair results of the code quality issues to the developer.
[0011] Furthermore, according to the method for detecting and repairing code quality issues of the present invention, the code relevant information includes: information such as project name, project version, branch name, code submission time, developer name, etc.
[0012] Furthermore, according to the method for detecting and repairing code quality issues of the present invention, the step of automatically detecting code quality issues according to the detection specifications includes: setting code detection specifications for different programming languages; determining the language type of the code to be detected; according to the language type of the code to be detected, automatically detect code quality issues according to the corresponding detection specifications.
[0013] According to the method for detecting and repairing code quality issues of the present invention, automatically detecting code quality issues according to the detection specifications includes: code style detection; code security detection; code unit testing.
[0014] According to the code quality problem detection and repair method of the present invention, the code style is detected, including: code reliability detection; code maintainability detection; code duplication rate detection.
[0015] According to the code quality problem detection and repair method of the present invention, the code security is detected, including: the number of code vulnerabilities detection; the review of code security hotspots.
[0016] According to the code quality problem detection and repair method of the present invention, unit tests are performed on the code, including: setting test cases for the corresponding code; performing unit tests on the code and recording the coverage rate.
[0017] Further, according to the code quality problem detection and repair method of the present invention, the steps of automatically repairing some detected code quality problems according to the repair specifications include: setting repair specifications for different code quality problems; automatically repairing some detected code quality problems according to the corresponding repair specifications.
[0018] According to the code quality problem detection and repair method of the present invention, the steps of automatically repairing some detected code quality problems include: performing edit and read / write operations on the code files with detected quality problems, and when code that does not conform to the specifications is scanned, modifying the code with quality problems according to the repair specifications.
[0019] Further, according to the code quality problem detection and repair method of the present invention, the steps of uniformly feeding back the detection and repair results of code quality problems to the developer include: merging the detection results of the current code quality problems, including the results of the code style detection, code security detection, and code unit tests, as well as the results of automatically repairing code quality problems, and uniformly feeding them back to the developer.
[0020] According to the second aspect of the present invention, there is provided a code quality problem detection and repair system for microservice continuous integration, including: a code style detection module, a code security detection module, a code unit test module, a code automatic error correction module, and a code feedback overview module.
[0021] Through the code style detection module, the style of the code is detected, and information on code reliability, code maintainability, and code duplication rate is obtained.
[0022] Through the code security detection module, the security of the code is detected, and information on the number of code vulnerabilities and the review of code security hotspots is obtained.
[0023] Through the code unit test module, test cases for the code are set, and unit tests are performed on the code, and information on the code coverage rate is obtained.
[0024] Through the code automatic error correction module, automatically repair some detected code quality problems.
[0025] Through the code feedback overview module, obtain and merge the detection results of code quality problems and the repair results of code quality problems, and uniformly feedback them to the developer.
[0026] Beneficial effects
[0027] According to the technical solution of the present invention, in the microservices scenario, after the developer submits the code, during the continuous integration of the project, the system will obtain the relevant information of the code, automatically detect various code quality problems according to the detection specifications, and automatically repair some detected code quality problems according to the repair specifications. Finally, the detection and repair results of the code quality problems are uniformly feedback to the developer, thereby greatly improving the quality and efficiency of the continuous integration process in the microservices scenario. Description of the drawings
[0028] Figure 1 It is a flowchart of a method for detecting and repairing code quality problems for microservices continuous integration according to an embodiment of the present invention;
[0029] Figure 2 It is a block diagram of a system for detecting and repairing code quality problems for microservices continuous integration according to an embodiment of the present invention;
[0030] Figure 3 It is a feedback style of the detection and repair results of code quality problems according to an embodiment of the present invention. Detailed implementation manners
[0031] To make the objectives, technical solutions, and advantages of the present application clearer, the following will further describe the embodiments of the present application in detail with reference to the accompanying drawings.
[0032] The embodiment of the present invention provides a method for detecting and repairing code quality problems for microservices continuous integration, and this method is applied to a code quality problem detection and repair system. The code quality problem detection and repair system includes a code style detection module, a code security detection module, a code unit test module, a code automatic error correction module, and a code feedback overview module;
[0033] As Figure 1 shown, the method for detecting and repairing code quality problems for microservices continuous integration includes the following steps:
[0034] Step S101, in the microservices scenario, when the developer pushes the code to the code repository, during the continuous integration of the project, obtain the relevant information of the code;
[0035] Specifically, the obtained code information includes information such as the project name, project version, branch name, code submission time, developer name, etc. It should be noted that only some of the code information is listed above. Those skilled in the art can understand that in practice, other information can also be added.
[0036] Step S102, after obtaining the code information, automatically detect various quality problems of the code according to the detection specifications.
[0037] Specifically, after obtaining the project code information, it is necessary to determine the language type of the code, and then detect the quality problems of the code according to the specifications corresponding to the language type. Here, it is necessary to call the code style detection module to perform the code style detection to obtain the code reliability, code maintainability, and code duplication rate detection information; it is also necessary to call the code security detection module to perform the code security detection to obtain the number of code vulnerabilities and the review information of code security hotspots; finally, it is necessary to call the code unit test module to set the test cases of the code and perform unit tests on the code to obtain the code coverage information.
[0038] Specifically, the above quality problem detection is analyzed and detected based on the pre-configured code rules. First, import the project that needs to be detected for quality problems into the system of the present invention, that is, configure the information such as the project name and the url of the project repository in the system, and then configure the environment variables and the configuration files related to the continuous integration process in the project repository. Specifically, a series of static rules related to code quality need to be included in this configuration file, which is also the basis for the subsequent quality detection of this system.
[0039] Specifically, during the quality detection process, the system of the present invention first obtains the source code through the configuration file. After obtaining the source code, it will be analyzed by the build server in the continuous integration environment according to the specified code rules. When the analysis is completed, the analysis results will be stored in the database for future reference and historical tracking. Finally, the analysis report can be viewed from a web browser or a dashboard.
[0040] Specifically, the system of the present invention supports quality detection of common programming languages. During the detection process, relevant metrics will be automatically calculated, such as the number of lines of code, and it will be verified whether the code metrics comply with the pre-configured code rules. If the analyzed source code violates the code rules or the rules exceed the predefined thresholds, a "problem" will be generated. Specifically, the content detected by the system of the present invention includes code style detection, code security detection, and code unit testing. Among them, code style detection includes reliability, maintainability, and duplication rate detection. Reliability rules, also named "bugs", will generate problems indicating errors in the code. Maintainability is related to the readability and modifiability of the code. The duplication rate represents the proportion of duplicate code in the project, and a large amount of copy-pasted code in the program will lead to bloated code. Code security detection includes the detection of the number of code vulnerabilities and the review of security hotspots. Code vulnerabilities refer to defects in the security of computer systems, which pose threats to the confidentiality, integrity, availability, access control, and monitoring mechanisms of the system or its application data. The system of the present invention will evaluate the security of the project based on the number of project vulnerabilities. Security hotspots refer to security-sensitive code segments that developers need to review. Finally, the system of the present invention will automatically perform unit tests on the project, count and display the unit test coverage rate, that is, the proportion of the covered code, and feedback the coverage of the test code to the developers.
[0041] Step S103, after detecting the quality problems of the code, if quality problems are detected, some of the detected quality problems will be automatically repaired according to the repair specifications.
[0042] Specifically, the configuration file used in the continuous integration process contains specific configurations related to both the detection and repair phases. After detecting the quality problems in the code in step S102, the detected code problems will be automatically repaired next according to the configured environment variables and the configuration file related to the continuous integration process.
[0043] Specifically, the present invention provides a unified command-line interface to check and repair project code, regardless of the programming language used. The check rules are stored in a pre-written configuration file in the build repository, allowing users to repair code problems according to specific quality requirements. At the same time, this system supports running in a non-interactive mode, which is very suitable for the continuous integration process. When a developer submits a project code, if the code is incorrect and the project execution fails, the code automatic error correction module will be called to perform read and write operations on the code file with detected quality problems. When code that does not conform to the specifications is scanned, the code with quality problems will be modified according to the corresponding repair specifications.
[0044] Specifically, the process of the system of the present invention for fixing code errors includes three steps: error location, fix generation, and fix verification. First, the code failure will be located to find information such as the file where the error occurs and the line number of the error code. Then, according to the rules that the project code needs to follow specified in the configuration file, operations such as addition, deletion, and modification are performed to modify the error variables and statements, generating corresponding fix results. After obtaining the preliminary fix, the fix results need to be verified next. Only the fixes that pass the verification can be fed back to the developer, thereby helping the developer to modify and improve. Such a process realizes intelligent automatic code fixing and ensures the continuous integration of the project.
[0045] Step S104, based on the detection results of code quality problems and the fix results of code quality problems, generate corresponding feedback and return it to the developer.
[0046] Specifically, through the code feedback overview module, obtain and merge the detection results of code quality problems and the fix results of code quality problems, and uniformly feedback them to the developer. Figure 3 It is a feedback style of the detection and fix results of code quality problems in an embodiment of the present invention.
[0047] An embodiment of the present invention provides a method for detecting and fixing code quality problems for microservice continuous integration. In the microservice scenario, after the developer submits the code, during the process of project continuous integration, the system will obtain the relevant information of the code, automatically detect various code quality problems according to the detection specifications, and automatically fix some of the detected code quality problems according to the fix specifications. Finally, the detection and fix results of the code quality problems are uniformly fed back to the developer. Compared with the existing technologies, the present invention can not only automatically detect code quality problems, but also automatically fix some of the detected quality problems, thus greatly improving the quality and efficiency of the continuous integration process in the microservice scenario.
[0048] Figure 2 It is a system for detecting and fixing code quality problems for microservice continuous integration provided by an embodiment of the present application. The system 20 includes: a code style detection module 201, a code security detection module 202, a code unit test module 203, a code automatic error correction module 204, and a code feedback overview module 205.
[0049] The code style detection module 201 performs the style detection of the code to obtain detection information on code reliability, code maintainability, and code duplication rate.
[0050] The code security detection module 202 performs the security detection of the code to obtain the number of code vulnerabilities and the review information of code security hotspots.
[0051] The code unit test module 203 sets test cases for the code and conducts unit tests on the code to obtain code coverage information.
[0052] The code automatic error correction module 204 automatically repairs some of the detected code quality problems.
[0053] The code feedback overview module 205 obtains and merges the detection results of code quality problems and the repair results of code quality problems, and uniformly feedbacks them to the developer.
[0054] An embodiment of the present invention provides a code quality problem detection and repair system for microservice continuous integration. In the microservice scenario, after the developer submits the code, during the continuous integration process of the project, the system will obtain relevant information about the code, automatically detect various code quality problems according to the detection specifications, and automatically repair some of the detected code quality problems according to the repair specifications. Finally, the detection and repair results of the code quality problems are uniformly feedbacked to the developer. Compared with the existing technologies, the present invention can not only automatically detect code quality problems, but also automatically repair some of the detected quality problems, thus greatly improving the quality and efficiency of the continuous integration process in the microservice scenario.
[0055] Although the above description of the illustrative specific embodiments of the present invention is for the convenience of those skilled in the art to understand the present invention, and it should be clear that the present invention is not limited to the scope of the specific embodiments. For those skilled in the art, as long as various changes are within the spirit and scope of the present invention defined and determined by the appended claims, these changes are obvious, and all inventions and creations using the concept of the present invention are within the scope of protection.
Claims
1. A method for detecting and fixing code quality problems for microservice continuous integration, characterized in that Including the steps: In a microservices scenario, when a developer pushes code to a code repository, during the continuous integration process of the project, relevant information about the code is obtained; Automatically detect various code quality issues based on detection specifications; Automatically repair some detected code quality issues based on repair specifications; Unify and feedback the detection and repair results of various code quality issues to the developer; After obtaining the project code information, it is necessary to determine the language type of the code, and then detect the code quality issues according to the specifications corresponding to the language type. Here, it is necessary to call the code style detection module to perform the code style detection and obtain the detection information on code reliability, code maintainability, and code duplication rate; it is also necessary to call the code security detection module to perform the code security detection and obtain the number of code vulnerabilities and the review information on code security hotspots; Finally, it is necessary to call the code unit test module, set the test cases for the code, and perform unit tests on the code to obtain the code coverage information; The above-mentioned quality issue detection is analyzed and detected based on pre-configured code rules. First, import the project to be detected for quality issues into the system, that is, configure the project name and the url information of the project repository in the system, and then configure the environment variables and the configuration files related to the continuous integration process in the project repository. This configuration file needs to contain a series of static rules related to code quality, which is also the basis for subsequent quality detection; During the quality detection process, the system first obtains the source code through the configuration file. After obtaining the source code, it will be analyzed by the build server in the continuous integration environment according to the specified code rules. When the analysis is completed, the analysis results will be stored in the database for future reference and historical tracking. Finally, the analysis report can be viewed from a web browser or dashboard; The relevant information of the code includes: project name, project version, branch name, code submission time, developer name information; The steps of automatically detecting various code quality issues based on detection specifications include: Set the code detection specifications for different programming languages; Determine the language type of the code to be detected; According to the language type of the code to be detected, automatically detect various code quality issues based on the corresponding detection specifications; Automatically detecting various code quality issues based on detection specifications includes: Code style detection; Code security detection; Code unit test; The code style detection includes: Code reliability detection; Code maintainability detection; Code duplication rate detection; The code security detection includes: Number detection of code vulnerabilities; Review of code security hotspots; The code unit test includes: Set the test cases for the corresponding code; Perform unit tests on the code and record the coverage rate; The steps of automatically repairing some detected code quality issues based on repair specifications include: Set the repair specifications for different code quality issues; Automatically repair some detected code quality issues according to the corresponding repair specifications; Perform editing, reading, and writing operations on the code files with detected quality issues. When scanning code that does not meet the specifications, modify the code with quality issues according to the repair specifications. The step of uniformly feeding back the detection and repair results of various code quality issues to the developer includes: Merge the detection results of the current code quality issues, including the results of the code style detection, code security detection, and code unit testing, as well as the results of the automatic repair of the code quality issues, and uniformly feed them back to the developer.
Citation Information
Patent Citations
Code standardization method and device, computer equipment and storage medium
CN111078568A