Code quality detection method and device, electronic equipment and computer program product
By seamlessly integrating the R&D management platform with continuous integration tools, and utilizing the network hook mechanism to automatically create code quality inspection tasks corresponding to environment branches, the problem of manual intervention in the traditional inspection process is solved, achieving end-to-end automation and environment adaptability of code quality inspection.
Patent Information
- Application Number
- CN202510859685.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-24
- Publication Date
- 2025-10-31
AI Technical Summary
Traditional code quality inspection processes lack a seamless integration mechanism with code merge events, making true end-to-end automation impossible. Technical personnel need to manually trigger continuous integration tools to create inspection tasks.
By seamlessly integrating the R&D management platform with continuous integration tools, and using the network hook mechanism to send event message bodies, code quality inspection tasks corresponding to environment branches are automatically created, and code quality inspection tools are invoked to perform inspections.
It achieves end-to-end automation of code quality inspection, improves the environmental adaptability and flexibility of inspection tasks, reduces manual intervention, and increases the degree of automation.
Smart Images

Figure CN120872779A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software testing technology, and in particular to a code quality testing method, apparatus, electronic device, and computer program product. Background Technology
[0002] With the increasing popularity of Agile development and DevOps concepts, more and more software technology teams are adopting a combination of continuous integration tools and code quality inspection tools to automate code quality inspection. However, traditional processes require technical personnel to manually create code quality inspection tasks in continuous integration tools, lacking a seamless integration mechanism with code merge events, and thus failing to achieve true end-to-end automation of code quality inspection. Summary of the Invention
[0003] In view of this, embodiments of this application provide a code quality inspection method, apparatus, electronic device, and computer program product, which can build a seamless connection mechanism with code merging events, thereby achieving true end-to-end automation of code quality inspection.
[0004] The first aspect of this application provides a code quality detection method, including: When a code merge request event is detected on the R&D management platform, an event message body is sent to the continuous integration tool through the R&D management platform. The event message body contains the environment branch to which the merged code belongs, corresponding to the code merge request event. Receive event message bodies through continuous integration tools and create code quality inspection tasks corresponding to the environment branches; Execute code quality inspection tasks through continuous integration tools to call code quality inspection tools to complete the quality inspection operation of merged code.
[0005] In the technical solution of this application embodiment, when a code merge request event is detected on the R&D management platform, an event message body is sent to the continuous integration tool through the R&D management platform. This event message body contains the environment branch to which the merged code belongs, corresponding to the code merge request event. Then, the continuous integration tool receives the event message body and creates a code quality inspection task corresponding to the environment branch. Finally, the continuous integration tool executes the code quality inspection task to call the code quality inspection tool to complete the quality inspection operation of the merged code. The above process is achieved by the R&D management platform automatically sending an event message body to the continuous integration tool when a code merge event is detected, triggering the continuous integration tool to create a code quality inspection task, and then calling the code quality inspection tool based on the code quality inspection task to complete the code quality inspection operation. With this setup, when a code merge event occurs, the continuous integration tool can be automatically triggered to create a code quality inspection task, eliminating the need for technicians to manually create the task in the continuous integration tool. This demonstrates that a seamless integration mechanism with code merge events has been built, achieving true end-to-end automation of code quality inspection. Furthermore, the event message body contains the environment branch to which the code belongs, and the continuous integration tool creates a code quality inspection task corresponding to that environment branch. This allows for the creation of different code quality inspection tasks for different environment branches, thereby effectively improving the environment adaptability and flexibility of creating code quality inspection tasks.
[0006] In one implementation of this application, creating a code quality inspection task corresponding to an environment branch includes: If the environment branch is the development environment, then create a code quality inspection task corresponding to the development environment; If the environment branch is a test environment, then create a code quality inspection task corresponding to the test environment; If the environment branch is the production environment, a code quality inspection task corresponding to the production environment will be created after receiving the task creation instruction input by the user, or a code quality inspection task corresponding to the production environment will be created after the scheduled task set by the continuous integration tool is triggered.
[0007] In one implementation of this application, creating a code quality inspection task corresponding to an environment branch includes: Determine the product information that the merged code will target; Create a code quality inspection task that is adapted to the product information and corresponds to the environment branch.
[0008] In another implementation of this application's embodiments, creating a code quality inspection task corresponding to an environment branch includes: Determine who wrote the merged code; The code quality level of the writer is determined based on the writer's historical code quality test results; Create code quality inspection tasks that are adapted to the code quality level and correspond to the environment branch.
[0009] In one implementation of this application, a code quality inspection task is performed using a continuous integration tool to call the code quality inspection tool to complete the quality inspection operation of the merged code, including: By using the predefined pipeline scripts of the continuous integration tool, the merged code is pulled, and the installation of dependencies and compilation and build operations are performed on the merged code to obtain the build artifacts and source code analysis results of the merged code. The continuous integration tool submits the build artifacts and source code analysis results to the first server of the code quality inspection tool, and receives the quality inspection results of the merged code returned by the first server.
[0010] In one implementation of this application, after receiving the quality inspection result of the merged code returned by the first server, the method further includes: If the quality inspection results meet the preset conditions, a code release task corresponding to the environment branch will be created using the continuous integration tool; Execute code release tasks using continuous integration tools to release the merged code to a second server corresponding to the environment branch.
[0011] In one implementation of this application, sending an event message body to a continuous integration tool through a research and development management platform includes: Configure network hooks through the service hook interface of the R&D management platform and specify the URL address of the continuous integration tool. Network hooks are an event notification mechanism based on HTTP callbacks. Send an event message body to a URL address via a web hook.
[0012] A second aspect of this application provides a code quality detection apparatus, comprising: The message body sending module is used to send an event message body to the continuous integration tool through the R&D management platform when a code merge request event is detected. The event message body contains the environment branch to which the merged code belongs corresponding to the code merge request event. The task creation module is used to receive event message bodies through continuous integration tools and create code quality inspection tasks corresponding to the environment branches; The code quality inspection module is used to perform code quality inspection tasks through continuous integration tools, and to call the code quality inspection tools to complete the quality inspection operation of the merged code.
[0013] A third aspect of this application provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the code quality detection method provided in the first aspect of this application.
[0014] A fourth aspect of this application provides a computer program product that, when run on an electronic device, causes the electronic device to execute the code quality detection method provided in the first aspect of this application.
[0015] A fifth aspect of this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the code quality detection method provided in the first aspect of this application.
[0016] It is understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 This is a flowchart of a code quality detection method provided in an embodiment of this application; Figure 2 This is a schematic diagram of a code quality detection result provided in an embodiment of this application; Figure 3 This is a schematic diagram of the operation flow of the code quality detection method provided in this application embodiment in a practical application scenario; Figure 4 This is a schematic diagram of the structure of a code quality detection device provided in an embodiment of this application; Figure 5 This is a schematic diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0019] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application can also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail. Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only for distinguishing descriptions and should not be construed as indicating or implying relative importance.
[0020] Currently, many software technology teams combine continuous integration tools with code quality inspection tools to automate the code quality inspection process. However, the traditional process requires technical personnel to manually trigger or maintain dedicated scripts in the continuous integration tool after the code is merged into the code repository. This lacks a seamless integration mechanism with the code merge event and fails to achieve true end-to-end automation of code quality inspection.
[0021] To address the aforementioned technical problems, this application proposes a code quality inspection method, apparatus, electronic device, and computer program product, capable of constructing a seamless integration mechanism with code merging events, thereby achieving true end-to-end automation of code quality inspection. For more specific technical implementation details of the embodiments of this application, please refer to the various method embodiments described below.
[0022] It should be understood that the implementing entity of the various method embodiments proposed in this application can be various types of electronic devices, such as mobile phones, tablets, desktop computers, wearable devices, augmented reality (AR) / virtual reality (VR) devices, laptops, ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), large-screen TVs, etc. The embodiments of this application do not impose any restrictions on the specific type of electronic device.
[0023] Please see Figure 1 This illustration shows a code quality detection method provided in an embodiment of this application, comprising: 101. When a code merge request event is detected on the R&D management platform, an event message body is sent to the continuous integration tool through the R&D management platform. The event message body contains the environment branch to which the merged code belongs, corresponding to the code merge request event. The execution entity of this method embodiment is an electronic device equipped with a research and development management platform, continuous integration tools, and code quality inspection tools. The research and development management platform is an integrated software system designed for enterprises to efficiently manage the entire product development lifecycle. It achieves collaborative management of requirements, projects, resources, quality, and knowledge through a unified platform. The research and development management platform used in this method embodiment may include, but is not limited to, Coding, PingCode, Worktile, and GitLab platforms, etc. The continuous integration tool is the core system for automating the code integration process in software development. It is used to automatically trigger the build, testing, and verification process after developers submit new code, ensuring that code changes can be quickly and securely merged into the main branch. The continuous integration tools used in this method embodiment may include, but are not limited to, Jenkins, GitHub Actions, CircleCI, and TeamCity, etc. Code quality inspection tools are software systems used to automatically check source code defects, security vulnerabilities, coding standard compliance, and maintainability issues. Through static or dynamic analysis techniques, they help development teams to promptly identify and fix code problems during the development phase, thereby improving code robustness. The code quality inspection tools used in this method embodiment may include, but are not limited to, SonarQube, ESLint, PMD, FindBugs (SpotBugs), Pylint, CodeClimate, DeepSource, Coverity, etc.
[0024] Typically, after developers modify a piece of code, they push it to the development management platform for manual review. Once approved, the code is merged into the original code under the corresponding environment branch and finally stored in a code repository. The environment branch refers to a Git branch created based on the software deployment environment. Its purpose is to isolate code changes across different environments, ensuring environment stability and deployment controllability. Common environment branches include development, testing, pre-release, and production environments, etc.
[0025] When a code merge event occurs, the Coding platform and other R&D management platforms can detect that the Merge Request event has been triggered. At this time, the R&D management platform will send an event message body to the continuous integration tool. This event message body contains the environment branch to which the merged code belongs.
[0026] In one implementation of this application, sending an event message body to a continuous integration tool through a research and development management platform includes: (1) Configure network hooks through the service hook interface of the R&D management platform and specify the URL address of the continuous integration tool. The network hooks are event notification mechanisms based on HTTP callbacks. (2) Send an event message body to the URL address via a network hook.
[0027] R&D management platforms typically feature service hook functionality. A service hook is an event-driven communication mechanism that allows one system to automatically send real-time notifications to another system when a specific event occurs. Through the service hook interface of the R&D management platform, web hooks can be configured. Web hooks are an event notification mechanism based on HTTP callbacks, enabling real-time event notifications and data transmission between applications. Their working principle is that when a specific event occurs in one system (the service provider), it automatically sends an HTTP request (usually a POST request) to a pre-configured URL address in another system (the subscriber), thereby triggering subsequent operations on the receiver. Based on this working principle, web hooks can be configured in the service hook interface of the R&D management platform, specifying the URL address of the continuous integration tool. In this way, the R&D management platform acts as the service provider, and the continuous integration tool acts as the subscriber. Using the configured web hook, when the R&D management platform detects that a code merge request event has been triggered, it will automatically send an HTTP request to the URL address of the continuous integration tool. The event message body is in POST format and typically includes information such as the environment branch to which the merged code belongs, the code repository identifier, and the code author. It can be seen that by introducing network hooks, data interaction between the development management platform and continuous integration tools can be easily achieved.
[0028] 102. Receive event message bodies through continuous integration tools and create code quality inspection tasks corresponding to the environment branches; After receiving an event message from the R&D management platform, the continuous integration tool parses the message, extracts the corresponding environment branch, and automatically creates a code quality inspection task for that branch. Considering that different environment branches have different application environments, their quality inspection requirements and objectives also differ, and therefore, the quality inspection process for code in different environment branches may also vary. Based on this, after obtaining the environment branch to which the merged code belongs by parsing the event message, the continuous integration tool creates a code quality inspection task corresponding to that branch. This allows for the creation of targeted code quality inspection tasks for different environment branches, effectively improving the environment adaptability and flexibility of code quality inspection task creation. In practice, code quality inspection tasks for each environment branch can be pre-designed and stored, such as code quality inspection tasks for the development environment, testing environment, pre-release environment, production environment, and so on.
[0029] In one implementation of this application, creating a code quality inspection task corresponding to an environment branch includes: (1) If the environment branch is the development environment, then create a code quality inspection task corresponding to the development environment; (2) If the environment branch is the test environment, then create a code quality inspection task corresponding to the test environment; (3) If the environment branch is the production environment, a code quality inspection task corresponding to the production environment will be created after receiving the task creation instruction input by the user, or a code quality inspection task corresponding to the production environment will be created after the scheduled task set by the continuous integration tool is triggered.
[0030] If the merged code belongs to a development environment branch, the continuous integration tool automatically creates a code quality inspection task corresponding to the development environment. If the merged code belongs to a testing environment branch, the continuous integration tool automatically creates a code quality inspection task corresponding to the testing environment. If the merged code belongs to a pre-release environment branch, the continuous integration tool automatically creates a code quality inspection task corresponding to the pre-release environment. This enables a fully automated code quality inspection and deployment process across development, testing, and pre-release environments. Unlike other environment branches, code in the production environment requires quality inspection and deployment to be completed during user downtime. Based on this characteristic, if the merged code belongs to a production environment branch, one approach is for the user to manually trigger the code quality inspection and deployment process, i.e., the user manually inputs a task creation command, and the continuous integration tool creates a code quality inspection task corresponding to the production environment upon receiving the command. Another approach is to use the scheduled task function of the continuous integration tool. Scheduled tasks can be set through the configuration interface of the continuous integration tool, and the code quality inspection task corresponding to the production environment is created only when the scheduled task is triggered (i.e., after the scheduled time arrives). With this configuration, the continuous integration tool can create code quality inspection tasks that are adapted to the actual environment branch.
[0031] In one implementation of this application, creating a code quality inspection task corresponding to an environment branch includes: (1) Determine the product information to which the merged code applies; (2) Create code quality inspection tasks that are adapted to product information and correspond to the environment branch.
[0032] As described above, since the quality inspection processes for code in different environment branches may differ, it is necessary to create separate code quality inspection tasks to adapt to the corresponding processes. Besides the environment branch factor, the actual product the code targets is also a relevant factor affecting the quality inspection process; that is, the quality inspection processes required for code targeting different products may differ. Based on this, we can first determine the product information targeted by the merged code, such as product name, product type, and product model. Then, using continuous integration tools, we can create code quality inspection tasks that are both adapted to this product information and correspond to the environment branch. Code quality inspection tasks adapted to different product information can be pre-designed and stored. For example, assuming the product information targeted by the merged code is an aerosol generator, we can create code quality inspection tasks adapted to aerosol generators and corresponding to the environment branch using continuous integration tools. This setup allows us to create code quality inspection tasks that are adapted to both the product information and the environment branch, significantly improving the flexibility and practicality of creating code quality inspection tasks.
[0033] In another implementation of this application's embodiments, creating a code quality inspection task corresponding to an environment branch includes: (1) Determine the author of the merged code; (2) Determine the code quality level of the writer based on the writer's historical code quality test results; (3) Create code quality detection tasks that are adapted to the code quality level and correspond to the environment branch.
[0034] In many cases, the code quality level of the code writer is also a significant factor influencing the quality inspection process. When the code quality level is high, a simplified and lenient quality inspection process can be used, while when the code quality level is low, a complex and rigorous process is required. Based on this, we can first identify the writer of the merged code, then obtain that writer's historical code quality inspection results. These historical results allow us to accurately determine the writer's code quality level; for example, higher historical code quality results generally indicate a higher writer's code quality level, and vice versa. Finally, we use continuous integration tools to create code quality inspection tasks that are both tailored to the code quality level and correspond to the environment branch. These tasks, tailored to different code quality levels, can be pre-designed and stored. This setup allows us to create code quality inspection tasks that are compatible with both the writer's code quality level and the environment branch, significantly improving the flexibility and practicality of creating code quality inspection tasks.
[0035] 103. Execute code quality inspection tasks through continuous integration tools to call the code quality inspection tools to complete the quality inspection operation of the merged code.
[0036] Next, the created code quality inspection task is executed through the continuous integration tool to start the code quality inspection process. Under the processing logic of the code quality inspection task, the code quality inspection tool is invoked to perform quality inspection operations on the merged code and obtain the corresponding quality inspection results.
[0037] In one implementation of this application, a code quality inspection task is performed using a continuous integration tool to call the code quality inspection tool to complete the quality inspection operation of the merged code, including: (1) By using the predefined pipeline script of the continuous integration tool, pull the merged code, and perform the installation of dependencies and compilation and build operations for the merged code, the build artifacts and source code analysis results of the merged code are obtained. (2) Submit the build artifacts and source code analysis results to the first server of the code quality inspection tool through the continuous integration tool, and receive the quality inspection results of the merged code returned by the first server.
[0038] Continuous integration tools can employ defined pipeline operations, executing predefined pipeline scripts to pull merged code from the corresponding code repository and perform dependency installation and compilation operations for the merged code, thereby obtaining the build artifacts and source code analysis results of the merged code. The continuous integration tool then submits the build artifacts and source code analysis results to the server of a code quality inspection tool, designated as the first server. The first server scans the merged code, analyzes it based on the build artifacts and source code analysis results, and returns the quality inspection results. These results may include project-related metrics such as the number of vulnerabilities, code duplication rate, code coverage, and lines of code, as well as the quality gate status. Taking Jenkins continuous integration tool and SonarQube code quality inspection tool as examples, Jenkins continuous integration tool can utilize the `withSonarQubeEnv` block included in the pipeline to call the SonarScanne plugin to submit the build artifacts and source code analysis results to the SonarQube server, wait for the SonarQube server's quality gate status to return, and finally generate a SonarQube code quality inspection report.
[0039] As an example, Figure 2 This is a schematic diagram of a code quality detection result provided in an embodiment of this application. Figure 2 The code quality check result shown is in error status, indicating that the code quality does not meet the requirements. Figure 2It displays multiple project-related metrics, including code security issues, reliability issues, maintainability issues, acceptability issues, code coverage, code duplication rate, and security hotspots. Through... Figure 2 The interface shown allows users to easily and clearly view whether the code has passed quality checks, as well as the actual values of various project-related metrics.
[0040] In one implementation of this application, after receiving the quality inspection result of the merged code returned by the first server, the method further includes: (1) If the quality inspection results meet the preset conditions, then create a code release task corresponding to the environment branch through the continuous integration tool; (2) Execute code release tasks through continuous integration tools to release the merged code to the second server corresponding to the environment branch.
[0041] If the quality check results of the merged code meet the preset conditions, it means the merged code can be released. However, the release requirements for code in different environment branches usually differ, such as needing to be released to different servers. Therefore, a code release task corresponding to the environment branch can be created using continuous integration tools to initiate the code release process. Under the processing logic of the code release task, the merged code is released to the server corresponding to the environment branch, denoted as the second server. For example, if the environment branch to which the merged code belongs is the development environment, a code release task corresponding to the development environment is created, and the merged code is released to the server corresponding to the development environment; if the environment branch to which the merged code belongs is the testing environment, a code release task corresponding to the testing environment is created, and the merged code is released to the server corresponding to the testing environment; if the environment branch to which the merged code belongs is the production environment, a code release task corresponding to the production environment is created, and the merged code is released to the server corresponding to the production environment, and so on. If the quality check results of the merged code do not meet the preset conditions, it means the merged code cannot be released temporarily. In this case, relevant personnel can be notified to modify the code and perform the quality check again until the quality check results meet the preset conditions. This setting allows for the automatic creation of code release tasks that adapt to the environment branch, thereby improving the flexibility and practicality of creating code release tasks.
[0042] As an example, Figure 3 This is a schematic diagram illustrating the operation flow of the code quality detection method provided in this application embodiment under a practical application scenario. Figure 3In the process, if a code merge event occurs, the development management platform will send an event message body to the continuous integration tool. This event message body carries information such as the environment branch to which the code belongs. After receiving the event message body, the continuous integration tool will parse it to obtain the environment branch information, automatically create an appropriate code quality inspection task according to the actual environment branch, and execute it. When executing the code quality inspection task, the continuous integration tool will call the code quality inspection tool's server to scan the code and obtain the code quality inspection results returned by the server. Figure 3 The entire process shown requires no manual operation, achieving true end-to-end automation of code quality inspection.
[0043] In the technical solution of this application embodiment, when a code merge request event is detected on the R&D management platform, an event message body is sent to the continuous integration tool through the R&D management platform. This event message body contains the environment branch to which the merged code belongs, corresponding to the code merge request event. Then, the continuous integration tool receives the event message body and creates a code quality inspection task corresponding to the environment branch. Finally, the continuous integration tool executes the code quality inspection task to call the code quality inspection tool to complete the quality inspection operation of the merged code. The above process is achieved by the R&D management platform automatically sending an event message body to the continuous integration tool when a code merge event is detected, triggering the continuous integration tool to create a code quality inspection task, and then calling the code quality inspection tool based on the code quality inspection task to complete the code quality inspection operation. With this setup, when a code merge event occurs, the continuous integration tool can be automatically triggered to create a code quality inspection task, eliminating the need for technicians to manually create the task in the continuous integration tool. This demonstrates that a seamless integration mechanism with code merge events has been built, achieving true end-to-end automation of code quality inspection. Furthermore, the event message body contains the environment branch to which the code belongs, and the continuous integration tool creates a code quality inspection task corresponding to that environment branch. This allows for the creation of different code quality inspection tasks for different environment branches, thereby effectively improving the environment adaptability and flexibility of creating code quality inspection tasks.
[0044] In summary, the embodiments of this application, by deeply integrating the code source triggering of the R&D management platform with the pipeline script of the continuous integration tool, can automatically create code quality inspection tasks adapted to the environment branch, eliminating the need for manual triggering of the code quality inspection process and greatly improving the degree of automation.
[0045] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0046] The above mainly describes a code quality detection method; the following will describe a code quality detection device.
[0047] Please see Figure 4 This application illustrates a code quality detection device according to an embodiment of the present application, comprising: The message body sending module 401 is used to send an event message body to the continuous integration tool through the R&D management platform when a code merge request event is detected in the R&D management platform. The event message body contains the environment branch to which the merged code belongs corresponding to the code merge request event. The task creation module 402 is used to receive event message bodies through continuous integration tools and create code quality inspection tasks corresponding to the environment branches; The code quality inspection module 403 is used to perform code quality inspection tasks through continuous integration tools, and to call the code quality inspection tools to complete the quality inspection operation of the merged code.
[0048] In one implementation of this application, the task creation module includes: The development environment task creation unit is used to create code quality inspection tasks corresponding to the development environment if the environment branch is the development environment. The test environment task creation unit is used to create a code quality inspection task corresponding to the test environment if the environment branch is a test environment; The production environment task creation unit is used to create a code quality inspection task corresponding to the production environment after receiving a task creation instruction from the user if the environment branch is the production environment, or to create a code quality inspection task corresponding to the production environment after a scheduled task set by the continuous integration tool is triggered.
[0049] In one implementation of this application, the task creation module includes: The production line information determination unit is used to determine the product information to which the merged code is applied. The first task creation unit is used to create code quality inspection tasks that are adapted to product information and correspond to the environment branch.
[0050] In another implementation of this application's embodiments, the task creation module includes: The writer identification unit is used to identify the writer of the merged code; The code quality level determination unit is used to determine the code quality level of the writer based on the writer's historical code quality inspection results; The second task creation unit is used to create code quality inspection tasks that are adapted to the code quality level and correspond to the environment branch.
[0051] In one implementation of this application, the code quality detection module includes: The pipeline operation unit is used to execute the pull and merged code through the predefined pipeline scripts of the continuous integration tool, as well as the installation of dependencies and compilation and build operations for the merged code, to obtain the build artifacts and source code analysis results of the merged code; The quality inspection result receiving unit is used to submit the build artifacts and source code analysis results to the first server of the code quality inspection tool through the continuous integration tool, and to receive the quality inspection results of the merged code returned by the first server.
[0052] In one implementation of this application, the code quality inspection device further includes: The release creation module is used to create a code release task corresponding to the environment branch through continuous integration tools if the quality inspection results meet the preset conditions. The code deployment module is used to execute code deployment tasks through continuous integration tools to deploy the merged code to a second server corresponding to the environment branch.
[0053] In one implementation of this application, the message body sending module includes: The network hook configuration unit is used to configure network hooks through the service hook interface of the R&D management platform and specify the URL address of the continuous integration tool. The network hook is an event notification mechanism based on HTTP callback. The message body sending unit is used to send event message bodies to URL addresses via network hooks.
[0054] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the code quality detection method described in any of the above embodiments.
[0055] This application also provides a computer program product that, when run on an electronic device, causes the electronic device to execute the code quality detection method as described in any of the above embodiments.
[0056] Figure 5 This is a schematic diagram of an electronic device provided in an embodiment of this application. Figure 5 As shown, the electronic device 5 of this embodiment includes: a processor 50, a memory 51, and a computer program 52 stored in the memory 51 and executable on the processor 50. When the processor 50 executes the computer program 52, it implements the steps in the embodiments of the various code quality detection methods described above, for example... Figure 1Steps 101-103 are shown. Alternatively, when the processor 50 executes the computer program 52, it implements the functions of each module / unit in the above-described device embodiments, for example, implementing... Figure 4 The functions of modules 401-403 of the device shown.
[0057] The computer program 52 can be divided into one or more modules / units, which are stored in the memory 51 and executed by the processor 50 to complete this application. The one or more modules / units can be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program 52 in the electronic device 5.
[0058] The processor 50 may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0059] The memory 51 can be an internal storage unit of the electronic device 5, such as a hard disk or memory. The memory 51 can also be an external storage device of the electronic device 5, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc. Furthermore, the memory 51 can include both internal and external storage units of the electronic device 5. The memory 51 is used to store the computer program and other programs and data required by the electronic device. The memory 51 can also be used to temporarily store data that has been output or will be output.
[0060] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0061] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0062] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0063] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0064] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between devices or units through some interfaces, and may be electrical, mechanical, or other forms.
[0065] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments of this application, depending on actual needs.
[0066] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0067] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.
[0068] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. A code quality detection method, characterized in that, include: When a code merge request event is detected on the R&D management platform, an event message body is sent to the continuous integration tool through the R&D management platform. The event message body contains the environment branch to which the merged code belongs corresponding to the code merge request event. The continuous integration tool receives the event message body and creates a code quality inspection task corresponding to the environment branch. The continuous integration tool is used to perform the code quality inspection task, thereby invoking the code quality inspection tool to complete the quality inspection operation of the merged code.
2. The method as described in claim 1, characterized in that, The creation of the code quality inspection task corresponding to the environment branch includes: If the environment branch is a development environment, then create a code quality inspection task corresponding to the development environment; If the environment branch is a test environment, then create a code quality inspection task corresponding to the test environment; If the environment branch is a production environment, a code quality inspection task corresponding to the production environment will be created after receiving the task creation instruction input by the user, or a code quality inspection task corresponding to the production environment will be created after the scheduled task set by the continuous integration tool is triggered.
3. The method as described in claim 1, characterized in that, The creation of the code quality inspection task corresponding to the environment branch includes: Determine the product information to which the merged code applies; Create a code quality inspection task that is adapted to the product information and corresponds to the environment branch.
4. The method as described in claim 1, characterized in that, The creation of the code quality inspection task corresponding to the environment branch includes: Identify the author of the merged code; Based on the author's historical code quality test results, the author's code quality level is determined; Create a code quality inspection task that is adapted to the code quality level and corresponds to the environment branch.
5. The method as described in claim 1, characterized in that, The step of executing the code quality inspection task through the continuous integration tool, in order to invoke the code quality inspection tool to complete the quality inspection operation of the merged code, includes: The continuous integration tool uses a predefined pipeline script to pull the merged code, and performs dependency installation and compilation operations on the merged code to obtain the build artifacts and source code analysis results of the merged code. The continuous integration tool submits the build artifacts and the source code analysis results to the first server of the code quality inspection tool, and receives the quality inspection results of the merged code returned by the first server.
6. The method as described in claim 5, characterized in that, After receiving the quality inspection result of the merged code returned by the first server, the method further includes: If the quality inspection results meet the preset conditions, then the continuous integration tool creates a code release task corresponding to the environment branch. The code release task is executed using the continuous integration tool to release the merged code to the second server corresponding to the environment branch.
7. The method according to any one of claims 1 to 6, characterized in that, The step of sending an event message body to the continuous integration tool through the R&D management platform includes: Configure the network hook through the service hook interface of the R&D management platform and specify the URL address of the continuous integration tool. The network hook is an event notification mechanism based on HTTP callback. The event message body is sent to the URL address via the network hook.
8. A code quality inspection device, characterized in that, include: The message body sending module is used to send an event message body to the continuous integration tool through the R&D management platform when a code merge request event is detected in the R&D management platform. The event message body contains the environment branch to which the merged code belongs corresponding to the code merge request event. The task creation module is used to receive the event message body through the continuous integration tool and create a code quality inspection task corresponding to the environment branch; The code quality inspection module is used to execute the code quality inspection task through the continuous integration tool, so as to call the code quality inspection tool to complete the quality inspection operation of the merged code.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the code quality detection method as described in any one of claims 1 to 7.
10. A computer program product, characterized in that, When the computer program product is run on an electronic device, the electronic device performs the code quality detection method as described in any one of claims 1 to 7.