Code detection method and device, equipment, medium and product
By responding to access control allocation requests during code detection, determining demand information and selecting target quality inspection templates, the problems of high code detection cost and low efficiency in the existing technology are solved, and efficient and accurate code quality assurance is achieved.
Patent Information
- Application Number
- CN202510706419.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-29
- Publication Date
- 2025-09-12
AI Technical Summary
The configuration files used for code detection in the prior art are costly, inefficient, and prone to errors, especially when the configuration files need to be manually updated under each production line after the quality requirements are modified.
By responding to access control allocation requests, determining code detection requirement information, selecting the target quality inspection template from the quality inspection template based on object information and preset access control configuration, and executing code detection tasks, code quality and security are ensured.
It improves the efficiency and accuracy of code detection, reduces configuration errors, reduces costs, and ensures the quality and security of code under different pipelines.
Smart Images

Figure CN120631755A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer processing technology, and in particular to a code detection method, device, equipment, medium and product. Background Art
[0002] During the software or product development process, in order to ensure the stability of the software or product, it is usually necessary to test the code quality from the development stage to the release stage.
[0003] Currently, code quality is usually tested by manually configuring configuration files for testing code for software or products produced under different scenario pipelines.
[0004] This approach is not only costly and inefficient, but also prone to configuration errors. Furthermore, when quality standards are revised, configuration information needs to be modified in the configuration files of each production line, and related configuration files need to be updated, further increasing costs. Summary of the Invention
[0005] The present invention provides a code detection method, device, equipment, medium and product to improve the efficiency, accuracy and reliability of code detection and achieve the technical effect of ensuring code quality.
[0006] According to one aspect of the present invention, a code detection method is provided, the method comprising:
[0007] In response to an access control allocation request including object information, determining code detection requirement information corresponding to the access control allocation request; wherein the object information includes project attribute information corresponding to the pipeline to be deployed or code attribute information of the code to be merged; and the code detection requirement information includes at least an access control configuration type;
[0008] In the case where the access control configuration type is a preset type, determining a target quality inspection template from at least one to-be-selected quality inspection template based on the code detection requirement information and the object information; the to-be-selected quality inspection template includes at least one code access control and detection parameters of the code access control;
[0009] Based on the target quality inspection template, a code detection task corresponding to the access control allocation request is executed.
[0010] According to another aspect of the present invention, there is provided a code detection device, the device comprising:
[0011] An information determination module, configured to, in response to an access control allocation request including object information, determine code detection requirement information corresponding to the access control allocation request; wherein the object information includes project attribute information corresponding to a pipeline to be deployed or code attribute information of a code to be merged; and the code detection requirement information includes at least an access control configuration type;
[0012] a target quality inspection template determination module, configured to determine a target quality inspection template from at least one to-be-selected quality inspection template based on the code detection requirement information and the object information when the access control configuration type is a preset type; the to-be-selected quality inspection template includes at least one code access control and detection parameters of the code access control;
[0013] A code detection module is used to perform a code detection task corresponding to the access control allocation request based on the target quality inspection template.
[0014] According to another aspect of the present invention, an electronic device is provided, comprising:
[0015] at least one processor; and a memory communicatively connected to the at least one processor; wherein,
[0016] The memory stores a computer program that can be executed by the at least one processor. The computer program is executed by the at least one processor so that the at least one processor can perform the code detection method described in any embodiment of the present invention.
[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the code detection method according to any embodiment of the present invention when executed.
[0018] According to another aspect of the present invention, a computer program product is provided, comprising a computer program, which implements the code detection method according to any embodiment of the present invention when executed by a processor.
[0019] The technical solution of the embodiment of the present invention determines the code detection requirement information corresponding to the access control allocation request by responding to the access control allocation request including object information; the object information includes the engineering attribute information corresponding to the pipeline to be deployed or the code attribute information of the code to be merged; the code detection requirement information includes at least the access control configuration type; when the access control configuration type is a preset type, based on the code detection requirement information and the object information, a target quality inspection template is determined from at least one quality inspection template to be selected; the quality inspection template to be selected includes at least one code access control and the detection parameters of the code access control; based on the target quality inspection template, a code detection task corresponding to the access control allocation request is executed, which solves the problem of configuring code detection configuration files under different scenario pipelines in the prior art, and there is a problem of eliminating In order to solve the problems of high cost, low efficiency and prone to configuration errors, it is realized that when an access control allocation request including object information is received, the code detection requirement information corresponding to the access control allocation request is determined; the code detection requirement information at least includes the access control configuration type; when the access control configuration type is a preset type, by comprehensively considering the engineering attribute information corresponding to the pipeline to be deployed or the code attribute information of the code to be merged, as well as the code detection requirement information and the object information, the target quality inspection template that is most suitable for the object information and the code detection requirement information is screened out from at least one quality inspection template to be selected, and then the target quality inspection template is used to perform the code detection task corresponding to the access control allocation request, thereby improving the efficiency and accuracy of code detection and achieving the technical effect of ensuring code quality and security.
[0020] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present invention, nor is it intended to limit the scope of the present invention. Other features of the present invention will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0022] Figure 1 This is a flowchart of a code detection method provided according to the first embodiment of the present invention;
[0023] Figure 2 This is a flowchart of a code detection method provided according to the first embodiment of the present invention;
[0024] Figure 3 This is a schematic diagram of the structure of a code detection device provided according to Embodiment 3 of the present invention;
[0025] Figure 4 It is a structural diagram of an electronic device for implementing the code detection method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0026] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0027] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0028] Example 1
[0029] Figure 1 This is a flowchart of a code detection method provided according to the first embodiment of the present invention. This embodiment is applicable to the case of detecting codes. The method can be executed by a code detection device. The code detection device can be implemented in the form of hardware and / or software. The code detection device can be configured in a computing device. Figure 1 As shown, the method includes:
[0030] S110 : In response to the access control allocation request including the object information, determine code detection requirement information corresponding to the access control allocation request; the code detection requirement information at least includes the access control configuration type.
[0031] The "access control allocation request" may refer to a program or instruction for requesting the allocation of code access control. Code access control refers to a method or strategy for verifying code quality before merging, used to check code quality and security, including, but not limited to, unit testing, integration testing, checking code compliance with specifications, and checking for security vulnerabilities and potential risks. Object information includes project attribute information corresponding to the pipeline to be deployed or code attribute information of the code to be merged. The pipeline to be deployed refers to the pipeline of the software development project to be created. This pipeline can be a circuit formed by connecting various stages of software development (such as code compilation, testing, building, and deployment) in series or in parallel, used to achieve automated delivery from original code submission to the corresponding environment. Project attribute information can refer to information related to the software development project, such as project name, project level, development language, development framework, business type, etc. The code to be merged refers to the code that needs to be merged into its main branch. Code attribute information can refer to features and properties related to the code to be merged, such as code version, language, framework, business module, etc. Code testing requirement information refers to relevant requirements for code testing. Code inspection requirements include, but are not limited to, code compliance, security vulnerability detection, code compatibility in a specific network environment, submission to a code repository or production environment after development, and access control configuration type. The access control configuration type can be used to indicate whether the final QA template is selected from a pre-determined set of QA templates or whether a custom QA template is used.
[0032] In this embodiment, when a pipeline creation request is received, it can be considered that a access control allocation request has been received. In this case, the access control allocation request is parsed to extract the project attribute information and code detection requirement information corresponding to the pipeline to be deployed from the access control allocation request. Alternatively, when a code merge request is received, it can be considered that a access control allocation request has been received. In this case, the access control allocation request is parsed to extract the code attribute information and code detection requirement information of the code to be merged from the access control allocation request. Based on the code detection requirement information and object information, the code access control is determined, ensuring that the code or project obtains the corresponding code access control before processing, ensuring the security and convenience of subsequent code processing, and ensuring code quality.
[0033] It should be noted that the code detection requirement information can be extracted from the access control allocation request or obtained based on the analysis of the object information. In this embodiment, in response to the access control allocation request including the object information, the code detection requirement information corresponding to the access control allocation request is determined, including: in response to the access control allocation request including the object information, the access control allocation request is parsed to obtain the code detection requirement information; the code detection requirement information also includes the network type and code deployment environment information used by the pipeline; if the code deployment environment information does not include deployment information on whether to deploy to the production environment, then determining at least one branch in the development process corresponding to the access control allocation request; if at least one branch includes a branch corresponding to the deployment information, then updating the included deployment information to the code deployment environment information.
[0034] Among them, the network type used by the pipeline refers to the type of network environment relied upon during code construction, testing and deployment, such as intranet, extranet, hybrid network, etc. Code deployment environment information refers to relevant information about the environment in which the code is deployed, including but not limited to the development environment (used for development and testing), the test environment (used to simulate the production environment for final testing), and the production environment (the environment in which the code is actually run). A branch refers to an independent thread in code control, and different branches can be used to develop different functions or fix different problems. For example, branches include but are not limited to the master branch (the main branch of the engineering project), the dev branch (the main branch for daily development work), the feature branch (the branch for developing new functions), the test branch (test branch), the release branch (release branch), etc. Deployment information refers to information related to the environment in which the code is deployed, such as whether it is deployed to the production environment.
[0035] Specifically, when receiving the access control allocation request, the access control allocation request is parsed using a parsing tool, interface or function to extract information such as the network type used by the pipeline in the code detection requirement information and the code deployment environment information. Check whether the code deployment environment information includes deployment information on whether it is deployed to the production environment. If it is included, the information is used directly for subsequent processing. If it is not included, at least one branch in the development process corresponding to the access control allocation request can be determined based on the code submission information in the access control allocation request (such as the submitted branch name, the submitted code path, etc.), and then determine whether these branches contain branches corresponding to the deployment information. If a branch corresponding to the deployment information on whether it is deployed to the production environment is found in the branch (for example, a release branch), the deployment information of the branch is added to the code deployment environment information. If the corresponding branch is not found, it means that there is no need to deploy the code to the production environment.
[0036] The advantage of this setting is that by checking the code deployment environment information obtained after parsing the access control allocation request, it is determined whether the deployment information to the production environment is included. If it is not included, it can be parsed from the branch to ensure the accuracy of the subsequent determination of the code access control and ensure that the code deployment process meets the expected development process and environment requirements.
[0037] It should also be noted that if the code deployment environment information does not include information about whether to deploy to the production environment, the deployment information can also be determined based on the project name. For example, if the project name includes AA, it is considered to be deployed to the production environment, and if the project name includes BB, it is considered to be deployed to the test environment. The included deployment information is added to the code deployment environment information.
[0038] In this embodiment, the project attribute information and code attribute information may include multiple query information to determine code access based on the multiple query information, thereby improving the accuracy of code access determination. Optionally, the project attribute information includes at least one of the following query information: the project name and project level of the pipeline to be deployed, the code development language, the code version, the code development framework, and the code business type. The code attribute information includes at least one of the following query information: the project name and project level of the pipeline project to which the code to be merged belongs, the code development language, the code development framework, the code version, and the code business type.
[0039] The project name uniquely identifies the project and distinguishes different projects. Each project can be considered a production line used to produce the corresponding software or product. The project level refers to the importance and priority of the project, such as "high," "medium," or "normal." The code development language refers to the programming language used in the project. The code version refers to the current version number of the code. The code development framework refers to the code library or toolset that provides the infrastructure and common functionality for the project's software or product. Examples of code development frameworks include, but are not limited to, web development frameworks, mobile development frameworks, back-end development frameworks, front-end development frameworks, and microservices frameworks. The code business type describes the purpose or functional classification of the code. Examples include, but are not limited to, business logic code, data access code, interface code, test code, configuration code, and tool code. Alternatively, the code business type can be the business area to which the project belongs, such as e-commerce, education, or sports. Determining code access control using multiple query information improves the accuracy of code access control while ensuring code quality and security.
[0040] S120: When the access control configuration type is a preset type, determine a target quality inspection template from at least one quality inspection template to be selected based on the code detection requirement information and the object information.
[0041] Among them, the preset type may refer to the type that supports determining the code access control from the quality inspection template to be selected. The quality inspection template to be selected may be pre-configured and used for code quality inspection during the pipeline process and quality inspection during code merging. The quality inspection template to be selected includes one or more code access controls and detection parameters for the code access controls. Each code access control can be considered as a detection rule, such as code format check, unit test coverage check, security vulnerability scanning, code complexity check, etc. The detection parameters of the code access control refer to the specific required parameters for detecting the code. For example, the detection parameters may be a code line limit, a code complexity threshold, a pass rate threshold, a repetition rate threshold, a security vulnerability level, etc.
[0042] In this embodiment, it is possible to detect whether the access control configuration type is a preset type. If not, a custom access control configuration may be prompted. If so, based on the code detection requirement information and object information, a quality inspection template that meets the requirements is screened out from all quality inspection templates to be selected as a target quality inspection template. If the screened target quality inspection templates include multiple, then a target quality inspection template can be determined based on the quality inspection integrity, quality inspection reliability, matching degree between the quality inspection template and the code detection requirement information and object information, priority of the quality inspection template, etc., so as to apply the code access and detection parameters in the target quality inspection template to the pipeline or code. For example, if the code detection requirement information includes the network type of the external network, then a quality inspection template containing the code access for detecting network security is screened out.
[0043] For example, see Figure 2 When creating a pipeline, you can input code inspection requirement information and object information into the quality access control configuration module. The quality access control configuration module identifies the corresponding pipeline scenario based on the code inspection requirement information and object information. The target quality inspection template corresponding to the identified pipeline scenario is used. For example, the target quality inspection template includes access control A, access control B, and access control C. This is used to perform quality control on the code during code building, code deployment, and code submission in the pipeline scenario based on the target quality inspection template.
[0044] In this embodiment, it is also supported to build a target detection template based on code detection requirement information and object information when the access control allocation request pipeline creates a request and the access control configuration type is a custom type.
[0045] In this way, it is convenient to dynamically build target detection templates that suit the project needs based on the special needs of the project, combining code detection requirement information and object information, and flexibly configure code access and detection parameters to ensure the quality and security of the code involved in the pipeline process.
[0046] To ensure the quality of code submitted to the production environment and merged into the main branch, you can prioritize code inspection requirement information over project attribute information. Code attribute information takes precedence over code inspection requirement information. This allows you to search for quality inspection templates based on the priority of the query information, ensuring that the target quality inspection template preferentially meets the query information with higher priority. Optionally, the priority of each query information in the code inspection requirement information and object information can be determined based on the code quality requirements of different process nodes.
[0047] Based on this, in the process of determining the target quality inspection template from at least one quality inspection template to be selected based on the code detection requirement information and object information: determine the query information with the highest priority from the code detection requirement information and object information, and based on the query information, search from at least one quality inspection template to be selected whether there is a first quality inspection template that matches the query information; if so, determine the query information with the next priority from the code detection requirement information and object information, and use the at least one first quality inspection template found as the quality inspection template to be selected, so as to re-execute the operation of searching whether there is a first quality inspection template that matches the query information based on the query information and the quality inspection template to be selected; and determine the target quality inspection template based on the first quality inspection template finally found.
[0048] In this embodiment, the query information with the highest priority in the code detection requirement information and object information can be analyzed, and then, the query information can be used to find a quality inspection template that matches the query information from the initial quality inspection templates to be selected, and the found quality inspection template can be used as the first quality inspection template. Furthermore, the first quality inspection template at this time can be used as the quality inspection template to be selected. After determining the query information of the next priority, the quality inspection template that matches the current query information can be found from these quality inspection templates to be selected at this time, and used as the first quality inspection template again. By continuously lowering the priority of the query information, the range of the quality inspection templates to be selected is gradually narrowed, and the first quality inspection template finally found is used as the target quality inspection template. At this time, the target quality inspection template satisfies multiple query information with higher priorities, ensuring that the code of the corresponding process node meets the quality requirements.
[0049] It should be noted that if no matching quality inspection template is found, the priority can be lowered and the quality inspection template can be searched again using the query information with the second highest priority. After each search, the first quality inspection template found is used as the new set of quality inspection templates to be selected. Use the query information of the next priority to continue searching for the first matching quality inspection template. This quality inspection template can be used as the target quality inspection template until all query information is used up or only the last matching quality inspection template is left. It should also be noted that if there are still multiple matching quality inspection templates after screening all query information, a final target quality inspection template can be selected based on other rules (such as the default priority of the template, etc.).
[0050] Furthermore, before determining the target quality inspection template from at least one quality inspection template to be selected based on the code detection requirement information and object information, the quality inspection template to be selected can also be determined in advance, and the method can be: determining multiple quality inspection scenarios to be selected and the quality inspection templates to be filled corresponding to the quality inspection scenarios to be selected; for each quality inspection template to be filled, configuring at least one code access control in the quality inspection template to be filled based on the current detection level, obtaining the detection parameters corresponding to at least one code access control, and adding the detection parameters to the associated position of the corresponding code access control to obtain the quality inspection template to be selected under the current detection level.
[0051] The "to-be-filled quality inspection template" refers to the quality inspection template corresponding to the quality inspection scenario to be selected. These templates include the corresponding code gates, but specific inspection parameters have not yet been configured. The "to-be-selected quality inspection template" refers to the template obtained by adding inspection parameters to at least one code gate in the quality inspection template to be filled. For example, the code gates in the to-be-selected quality inspection template include but are not limited to Gate A, Gate B, and Gate C. The inspection parameters for Gate A include but are not limited to the number of gates, repetition rate, and pass rate. The to-be-selected quality inspection scenario is related to the object information and code inspection requirement information. In other words, the to-be-selected quality inspection scenario can refer to multiple possible quality inspection scenarios determined based on the code inspection requirement information and object information. Each quality inspection scenario corresponds to specific code inspection requirements and project properties. For example, quality inspection scenarios for different business types, different network types used in different pipelines, different project levels, or different development stages. Different quality inspection scenarios require different inspection content, and accordingly, the corresponding code gates and, therefore, the corresponding quality inspection templates are also different. The inspection level refers to the strictness or priority of the code inspection, and can also be set based on the code inspection requirement information and object information. The associated position can be the position in the code access control corresponding to the value of each detection item as the key. This value is the detection parameter. For example, access control A includes detection items such as access control open status, access control blocked status, notification method, and repetition rate. The position corresponding to the value of access control open status is the associated position. This value (detection parameter) can be 1, indicating that a code scan is required; the detection coefficient corresponding to access control blocked status can be 0, indicating that the entire process is blocked if the detection fails.
[0052] In this embodiment, the quality inspection templates to be filled in can be configured to correspond to different quality inspection scenarios to be selected, and at this time, the quality inspection templates to be filled contain some code access control. For a certain quality inspection template to be filled, the corresponding detection parameters can be configured for the detection items in each code access control in the quality inspection template to be filled according to different detection levels, and the detection parameters are used as the values corresponding to the detection items and added to the associated positions to obtain multiple quality inspection templates to be selected under the quality inspection template to be filled. For example, the higher the detection level, the higher the detection requirement corresponding to the detection coefficient. Alternatively, the quality inspection template to be filled and the detection level can be determined according to the quality inspection scenario to be selected, and then the corresponding detection coefficient can be configured for each code access control in the quality inspection template to be filled according to the detection level. So that according to the code detection requirement information and object information, the one that best meets the requirements can be selected from the generated quality inspection templates to be selected as the target quality inspection template for code detection.
[0053] For example, the quality inspection templates to be selected configured for different quality inspection scenarios to be selected may include but are not limited to at least one of the following:
[0054] One approach is to select a QC scenario where the pipeline is submitted to the production environment after completion. The QC template corresponding to this scenario includes all code access control types, with the access control blocking status configured as "blocked." Blocking means that the entire pipeline task is blocked if a test fails. This approach ensures the quality of code submitted to the production environment.
[0055] Alternatively, if the selected QA scenario includes pull requests for code merging, this means that the developed code needs to be merged into the main branch. The corresponding QA template includes all code access control types, with the access control blocking status configured as blocked. This means that code merging is blocked if the check fails. This approach ensures the quality of the code merged into the main branch.
[0056] Another option is: if the quality inspection scenario to be selected includes deploying the code to a test environment through a pipeline, then the quality inspection template to be selected corresponding to this scenario can be configured with code access control as needed, or not configured.
[0057] Of course, the detection parameters can also be input into the quality inspection template to be selected when executing the pipeline to achieve code detection of the corresponding code access control.
[0058] It should also be noted that if the configuration information in the quality inspection template to be selected changes, you can synchronize the quality inspection template to be selected for all pipeline creation or code merging when the access control configuration type is the preset type with one click, that is, all configuration information in this template will be changed synchronously, avoiding manual configuration modification in the pipeline of each development environment, reducing the possibility of errors, and improving the convenience and flexibility of code access control modification.
[0059] S130: Execute a code detection task corresponding to the access control allocation request based on the target quality inspection template.
[0060] In this embodiment, after determining the target quality inspection template, the code access control and detection parameters in the target quality inspection template can be applied to the actual code inspection task corresponding to the access control allocation request. After the code inspection task is completed, an inspection result is generated, which includes information such as whether the code passed the inspection, a list of detected issues, and detailed information about each issue (such as the problem location, description, and severity). The inspection results are then fed back to inform the user whether the code passed the inspection and any issues that need to be fixed.
[0061] It should be noted that when the access control allocation request is different, the corresponding target quality inspection template may be different, and the way of executing the code detection task is also different. Optionally, based on the target quality inspection template, executing the code detection task corresponding to the access control allocation request includes at least two implementation methods:
[0062] One implementation method may be: when the access control allocation request includes a pipeline creation request, creating a pipeline task based on the pipeline creation request; and performing code quality inspection based on a target quality inspection template during execution of the pipeline task.
[0063] Among them, a pipeline creation request refers to a request used to indicate the need to create a new pipeline task. A series of tasks defined in a pipeline, for example, pipeline tasks include at least a code compilation task, a code deployment task, and a task of transferring code to the production environment. The code compilation task refers to compiling the code into an executable file or intermediate file. The code deployment task refers to deploying the compiled code to a specified environment (such as a test environment). The task of transferring code to the production environment refers to submitting the code to the production environment to complete the release.
[0064] In this embodiment, when a pipeline creation request is received, a target quality inspection template can be determined based on the engineering attribute information and code detection requirement information corresponding to the pipeline to be deployed. At the same time, the pipeline configuration information, such as the pipeline name, environment configuration, task steps, etc., can be extracted from the pipeline creation request, and the pipeline task can be initialized based on the extracted configuration information. The pipeline task is started, and the tasks of code compilation, code deployment, and code transfer to the production environment are executed in sequence. In the process of executing the pipeline task, a series of quality inspection operations are performed on the code to be tested according to the target quality inspection template. For example, before or after executing the code compilation task, the target quality inspection template is inserted so that the target quality inspection template detects the code before and after compilation. Before executing the code deployment task, the target quality inspection template is inserted so that the target quality inspection template detects the code before deployment. Before the task of transferring the code to the production environment, the target quality inspection template is inserted so that the target quality inspection template detects the code before it is transferred to the production environment. If the code passes the test, the subsequent pipeline tasks will continue to be executed. If the code fails the test, the access control blocking status in the target quality inspection template can be used to determine whether to stop the pipeline task and notify the user to fix the problem, or just prompt the user to continue executing the pipeline task.
[0065] In this way, code inspection tasks can be efficiently performed in pipeline tasks based on target quality inspection templates to ensure code quality and security.
[0066] One implementation method may be: when the access control allocation request includes a code merge request, determine the code to be merged corresponding to the code merge request; perform quality inspection on the code to be merged based on the target quality inspection template, and merge the code to be merged after passing the quality inspection.
[0067] In this embodiment, when a code merge request is received, a target quality inspection template is determined based on the code attribute information and code inspection requirement information of the code to be merged. Furthermore, the target quality inspection template is used to perform a quality inspection on the code to be merged, and a quality inspection result is obtained. If the quality inspection result is passed, the code to be merged is merged into its main branch code.
[0068] The benefit of this setup is that, when the access control allocation request includes a code merge request, the code to be merged is quality-checked to ensure that the code meets the established quality standards before the merge operation is performed. This ensures the quality and stability of the code merged into the main branch. To ensure code security, after the code to be merged is determined, security checks can also be performed on the code to prevent code tampering.
[0069] The technical solution of this embodiment determines the code detection requirement information corresponding to the access control allocation request by responding to the access control allocation request including object information; the object information includes the engineering attribute information corresponding to the pipeline to be deployed or the code attribute information of the code to be merged; the code detection requirement information includes at least the access control configuration type; when the access control configuration type is a preset type, based on the code detection requirement information and the object information, a target quality inspection template is determined from at least one quality inspection template to be selected; the quality inspection template to be selected includes at least one code access control and the detection parameters of the code access control; based on the target quality inspection template, the code detection task corresponding to the access control allocation request is executed, which solves the problem of configuring the configuration file of code detection under the pipeline of different scenarios in the prior art, which consumes a lot of time. The problems of high cost, low efficiency and easy configuration errors are solved by determining the code detection requirement information corresponding to the access control allocation request when receiving the access control allocation request including object information; the code detection requirement information includes at least the access control configuration type; when the access control configuration type is a preset type, by comprehensively considering the engineering attribute information corresponding to the pipeline to be deployed or the code attribute information of the code to be merged, as well as the code detection requirement information and the object information, the target quality inspection template that is most suitable for the object information and the code detection requirement information is screened out from at least one quality inspection template to be selected, and then the target quality inspection template is used to perform the code detection task corresponding to the access control allocation request, thereby improving the efficiency and accuracy of code detection and achieving the technical effect of ensuring code quality and security.
[0070] Example 2
[0071] As an alternative embodiment to the above embodiment, in order to make those skilled in the art further understand the technical solution of the embodiment of the present invention, a specific application scenario example is given. For details, please refer to the following specific content.
[0072] In this embodiment, the code quality inspection process can be incorporated into the pipeline, and an independent quality access control configuration module can be established to support the configuration of code access control for different pipeline scenarios. When creating pipelines for different scenarios, the project attribute information and code inspection requirement information corresponding to the pipeline to be deployed can be used to directly match the target quality inspection template corresponding to the corresponding pipeline scenario. At the same time, the code access control in the target quality inspection template can be remotely configured and updated. When the pipeline performs inspections, it automatically performs quality inspections according to the updated target quality inspection template.
[0073] Exemplarily, the target quality inspection template returned by the quality gate configuration module includes:
[0074] {Access Control A:{
[0075] Access control open status: 1
[0076] Access control blocking status: 1
[0077] Notification method: 1
[0078] Access control configuration value: {pass rate: 100; coverage rate: 80}}
[0079] Access Control B: {
[0080] Access control open status: 1
[0081] Access blocking status: 0
[0082] Notification method: 1
[0083] Access control configuration value: {Number of access controls: 0; Repeat rate: 10}}}
[0084] Among them, the access control opening status includes two states: open and closed, indicating whether the code is scanned; the access control blocking status includes two states: blocked and only prompted, indicating whether the entire process is blocked after failure; the access control configuration value refers to the detailed parameters of each code access.
[0085] The technical solution of this embodiment improves configuration flexibility and facilitates management by configuring corresponding quality inspection templates for different pipeline environments. At the same time, it enables direct matching to the target quality inspection template each time a new pipeline is created, improving the accuracy and flexibility of code quality inspection.
[0086] Example 3
[0087] Figure 3 : is a schematic diagram of the structure of a code detection device provided according to the third embodiment of the present invention. Figure 3 As shown, the device includes: an information determination module 210, a target quality inspection template determination module 220 and a code detection module 230.
[0088] Among them, the information determination module 210 is used to determine the code detection requirement information corresponding to the access control allocation request in response to the access control allocation request including object information; wherein, the object information includes engineering attribute information corresponding to the pipeline to be deployed or code attribute information of the code to be merged; the code detection requirement information includes at least the access control configuration type; the target quality inspection template determination module 220 is used to determine the target quality inspection template from at least one quality inspection template to be selected based on the code detection requirement information and the object information when the access control configuration type is a preset type; the quality inspection template to be selected includes at least one code access and the detection parameters of the code access; the code detection module 230 is used to perform the code detection task corresponding to the access control allocation request based on the target quality inspection template.
[0089] The technical solution of this embodiment determines the code detection requirement information corresponding to the access control allocation request by responding to the access control allocation request including object information; the object information includes the engineering attribute information corresponding to the pipeline to be deployed or the code attribute information of the code to be merged; the code detection requirement information includes at least the access control configuration type; when the access control configuration type is a preset type, based on the code detection requirement information and the object information, a target quality inspection template is determined from at least one quality inspection template to be selected; the quality inspection template to be selected includes at least one code access control and the detection parameters of the code access control; based on the target quality inspection template, the code detection task corresponding to the access control allocation request is executed, which solves the problem of configuring the configuration file of code detection under the pipeline of different scenarios in the prior art, which consumes a lot of time. The problems of high cost, low efficiency and easy configuration errors are solved by determining the code detection requirement information corresponding to the access control allocation request when receiving the access control allocation request including object information; the code detection requirement information includes at least the access control configuration type; when the access control configuration type is a preset type, by comprehensively considering the engineering attribute information corresponding to the pipeline to be deployed or the code attribute information of the code to be merged, as well as the code detection requirement information and the object information, the target quality inspection template that is most suitable for the object information and the code detection requirement information is screened out from at least one quality inspection template to be selected, and then the target quality inspection template is used to perform the code detection task corresponding to the access control allocation request, thereby improving the efficiency and accuracy of code detection and achieving the technical effect of ensuring code quality and security.
[0090] Based on the above device, optionally, the information determination module 210 includes:
[0091] A code detection requirement information determining unit, configured to respond to an access control allocation request including object information, parse the access control allocation request to obtain code detection requirement information; wherein the code detection requirement information also includes the network type and code deployment environment information used by the pipeline;
[0092] a branch determination unit, configured to determine at least one branch in the development process corresponding to the access control allocation request if the code deployment environment information does not include deployment information indicating whether the code is deployed to a production environment;
[0093] A deployment information determining unit is configured to update the code deployment environment information with the included deployment information if at least one of the branches includes a branch corresponding to the deployment information.
[0094] Based on the above device, optionally, the project attribute information includes at least one query information of the project name and project level of the pipeline to be deployed, the code development language, the code version, the code development framework, and the code business type; the code attribute information includes at least one query information of the project name and project level of the pipeline project to which the code to be merged belongs, the code development language, the code version, the code development framework, and the code business type;
[0095] The priority of the code detection requirement information is higher than the priority of the engineering attribute information; the priority of the code attribute information is higher than the priority of the code detection requirement information.
[0096] Based on the above device, optionally, the target quality inspection template determination module 220 includes:
[0097] a first quality inspection template determining unit, configured to determine query information with the highest priority from the code detection requirement information and the object information, and search, based on the query information, from at least one quality inspection template to be selected to determine whether there is a first quality inspection template that matches the query information;
[0098] a re-execution unit, configured to, if yes, determine query information of a next priority from the code detection requirement information and the object information, and use at least one of the first quality inspection templates found as a to-be-selected quality inspection template, so as to re-execute an operation of searching for a first quality inspection template that matches the query information based on the query information and the to-be-selected quality inspection template;
[0099] The target quality inspection template determining unit is configured to determine the target quality inspection template based on the first quality inspection template found last.
[0100] Based on the above device, optionally, the code detection module 230 includes:
[0101] A pipeline task creation unit, configured to create a pipeline task based on the pipeline creation request when the access control allocation request includes a pipeline creation request; wherein the pipeline task includes at least a code compilation task, a code deployment task, and a task of transferring the code to a production environment;
[0102] A quality detection unit is used to perform code quality detection based on the target quality inspection template during the execution of the pipeline task.
[0103] Based on the above device, optionally, the code detection module 230 includes:
[0104] a to-be-merged code determining unit, configured to, when the access control allocation request includes a code merging request, determine a to-be-merged code corresponding to the code merging request;
[0105] The merging processing unit is used to perform quality inspection on the codes to be merged based on the target quality inspection template, so as to perform merging processing on the codes to be merged after passing the quality inspection.
[0106] On the basis of the above device, optionally, the device further includes:
[0107] A to-be-filled quality inspection template determination unit, configured to determine a plurality of to-be-selected quality inspection scenarios and to-be-filled quality inspection templates corresponding to the to-be-selected quality inspection scenarios; wherein the to-be-selected quality inspection scenarios are related to object information and code detection requirement information;
[0108] The unit for determining the quality inspection template to be selected is used to configure at least one code access control in the quality inspection template to be filled based on the current detection level for each quality inspection template to be filled, obtain the detection parameters corresponding to at least one code access control, and add the detection parameters to the associated position of the corresponding code access control to obtain the quality inspection template to be selected under the current detection level.
[0109] The code detection device provided in the embodiment of the present invention can execute the code detection method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0110] Example 4
[0111] Figure 4 1 is a block diagram of an electronic device for implementing the code detection method of an embodiment of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0112] like Figure 4As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory 12 and a random access memory 13, that is communicatively connected to the at least one processor 11. The memory stores a computer program that can be executed by the at least one processor. The processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory 12 or the computer program loaded from the storage unit 18 into the random access memory 13. The random access memory 13 can also store various programs and data required for the operation of the electronic device 10. The processor 11, the read-only memory 12, and the random access memory 13 are connected to each other via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0113] Multiple components in the electronic device 10 are connected to the I / O interface 15, including an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a magnetic disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0114] The processor 11 may be any general-purpose and / or specialized processing component with processing and computing capabilities. Examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the code detection method.
[0115] In some embodiments, the code detection method can be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 10 via the read-only memory 12 and / or the communication unit 19. When the computer program is loaded into the random access memory 13 and executed by the processor 11, one or more steps of the code detection method described above can be performed. Alternatively, in other embodiments, the processor 11 can be configured to perform the code detection method in any other appropriate manner (for example, by means of firmware).
[0116] Various embodiments of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0117] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer program is executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer program may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0118] In the context of the present invention, computer-readable storage medium can be a tangible medium that can contain or store a computer program for use with an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. Computer-readable storage medium can include but is not limited to electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, computer-readable storage medium can be a machine-readable signal medium. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device or any suitable combination of the foregoing.
[0119] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0120] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0121] A computing system may include clients and servers. The clients and servers are typically remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers, creating a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host. This server is a hosting product within the cloud computing service ecosystem that addresses the management difficulties and limited scalability of traditional physical hosting and VPS services.
[0122] In particular, according to an embodiment of the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present invention includes a computer program product that includes a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication unit 19, or installed from the storage unit 18, or installed from the read-only memory 12. When the computer program is executed by the processor 11, the above-mentioned functions defined in the method of the embodiment of the present invention are performed.
[0123] An embodiment of the present invention further provides a computer program product, including a computer program, which, when executed by a processor, implements the code detection method provided by any embodiment of the present invention.
[0124] The computer program product may be implemented by writing computer program code for performing the operations of the present invention in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0125] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in the present invention can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved. This is not limited herein.
[0126] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.
Claims
1. A code detection method, characterized in that: include: In response to an access control allocation request including object information, determining code detection requirement information corresponding to the access control allocation request; wherein the object information includes project attribute information corresponding to the pipeline to be deployed or code attribute information of the code to be merged; and the code detection requirement information includes at least an access control configuration type; In the case where the access control configuration type is a preset type, determining a target quality inspection template from at least one to-be-selected quality inspection template based on the code detection requirement information and the object information; the to-be-selected quality inspection template includes at least one code access control and detection parameters of the code access control; Based on the target quality inspection template, a code detection task corresponding to the access control allocation request is executed.
2. The method according to claim 1, characterized in that The step of determining, in response to the access control allocation request including the object information, code detection requirement information corresponding to the access control allocation request includes: In response to the access control allocation request including the object information, the access control allocation request is parsed to obtain code detection requirement information; wherein the code detection requirement information also includes the network type and code deployment environment information used by the pipeline; If the code deployment environment information does not include deployment information of whether to deploy to a production environment, determining at least one branch in a development process corresponding to the access control allocation request; If at least one of the branches includes a branch corresponding to the deployment information, the included deployment information is updated into the code deployment environment information.
3. The method according to claim 1, characterized in that The project attribute information includes at least one query information of the project name and project level of the pipeline to be deployed, the code development language, the code version, the code development framework, and the code business type; the code attribute information includes at least one query information of the project name and project level of the pipeline project to which the code to be merged belongs, the code development language, the code version, the code development framework, and the code business type; The priority of the code detection requirement information is higher than the priority of the engineering attribute information; the priority of the code attribute information is higher than the priority of the code detection requirement information.
4. The method according to claim 3, characterized in that The determining a target quality inspection template from at least one to-be-selected quality inspection template based on the code detection requirement information and the object information includes: Determine query information with the highest priority from the code detection requirement information and the object information, and search, based on the query information, from at least one quality inspection template to be selected to determine whether there is a first quality inspection template that matches the query information; If so, determining query information of the next priority from the code detection requirement information and the object information, and using at least one of the first quality inspection templates found as a to-be-selected quality inspection template, so as to re-execute the operation of searching for a first quality inspection template that matches the query information based on the query information and the to-be-selected quality inspection template; Based on the first quality inspection template found last, a target quality inspection template is determined.
5. The method according to claim 1, wherein The executing, based on the target quality inspection template, a code detection task corresponding to the access control allocation request includes: In the case where the access control allocation request includes a pipeline creation request, creating a pipeline task based on the pipeline creation request; wherein the pipeline task includes at least a code compilation task, a code deployment task, and a task of transferring the code to a production environment; During the execution of the pipeline task, code quality inspection is performed based on the target quality inspection template.
6. The method according to claim 1, wherein The executing, based on the target quality inspection template, a code detection task corresponding to the access control allocation request includes: In a case where the access control allocation request includes a code merging request, determining a code to be merged corresponding to the code merging request; Based on the target quality inspection template, the code to be merged is quality inspected, so as to merge the code to be merged after passing the quality inspection.
7. The method according to claim 1, characterized in that Before determining a target quality inspection template from at least one to-be-selected quality inspection template based on the code detection requirement information and the object information, the method further includes: Determining multiple quality inspection scenarios to be selected and quality inspection templates to be filled in corresponding to the quality inspection scenarios to be selected; wherein the quality inspection scenarios to be selected are related to object information and code detection requirement information; For each of the quality inspection templates to be filled, a configuration operation is performed on at least one code access control in the quality inspection template to be filled based on the current detection level to obtain detection parameters corresponding to at least one code access control, and the detection parameters are added to the associated position of the corresponding code access control to obtain the quality inspection template to be selected under the current detection level.
8. A code detection device, characterized in that: include: An information determination module, configured to, in response to an access control allocation request including object information, determine code detection requirement information corresponding to the access control allocation request; wherein the object information includes project attribute information corresponding to a pipeline to be deployed or code attribute information of a code to be merged; and the code detection requirement information includes at least an access control configuration type; a target quality inspection template determination module, configured to determine a target quality inspection template from at least one to-be-selected quality inspection template based on the code detection requirement information and the object information when the access control configuration type is a preset type; the to-be-selected quality inspection template includes at least one code access control and detection parameters of the code access control; A code detection module is used to perform a code detection task corresponding to the access control allocation request based on the target quality inspection template.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor. The computer program is executed by the at least one processor to enable the at least one processor to perform the code detection method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the code detection method according to any one of claims 1 to 7 when executed.