Code quality detection method, device, electronic device and computer storage medium

By receiving the target product name and task number, determining the code information and generating a target program list, calculating the recommendation score, the problem of inability to check the code quality in the existing technology is solved, and accurate detection and timely review of the code quality are achieved.

CN114741295BActive Publication Date: 2025-04-25BANK OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210367120.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-08
Publication Date
2025-04-25
Estimated Expiration
2042-04-08

AI Technical Summary

Technical Problem

The existing technology cannot check the quality of the code in a timely manner, resulting in the inability to determine which codes need to be reviewed, or the code cannot be fully checked to find the problem when an exception occurs.

Method used

By receiving the target product name and task number, determine the code information, including code complexity, unit test coverage, modification time, number of lines and number of function lines, generate a list of target programs, calculate the recommendation score based on the risk and complexity, and output the code list that needs to be reviewed.

Benefits of technology

It realizes accurate detection of code quality and timely obtains program codes that need to be reviewed, which improves the efficiency and quality of code management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114741295B_ABST
    Figure CN114741295B_ABST
Patent Text Reader

Abstract

The present application provides a code quality detection method, device, electronic device and computer storage medium, which can be applied to the financial field or other fields. The method includes: after receiving the target product name and the first task number; first, determining the code information according to the target product name; wherein the code information includes the second task number; then, generating a target program list according to the task to which the first task number belongs and the task to which the second task number belongs; then, for each target program in the target program list, determining the risk of the target program according to the number of function lines and the number of code lines of the target program; finally, determining the recommendation score of the target program according to the code complexity of the target program, the code unit test coverage and the risk of the target program; wherein, the higher the recommendation score of the target program, the more the code in the target program needs to be reviewed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a code quality detection method, device, electronic device and computer storage medium. Background Art

[0002] At present, in the process of program code quality management, it is impossible to check the code quality in time, so it is impossible to know whether which code needs to be reviewed, or when an exception occurs, it is necessary to comprehensively check the code to find the problem. Summary of the invention

[0003] In view of this, the present application provides a code quality detection method, device, electronic device and computer storage medium, which are used to accurately detect the code quality and promptly obtain the code of the program that needs to be reviewed.

[0004] The first aspect of the present application provides a method for detecting code quality, comprising:

[0005] Receive the target product name and the first task number;

[0006] Determine the code information according to the target product name; wherein the code information includes code complexity, code unit test coverage, code modification time, number of code lines, number of function lines and second task number;

[0007] Generate a target program list according to the tasks to which the first task number belongs and the tasks to which the second task number belongs;

[0008] For each target program in the target program list, determine the risk level of the target program according to the number of function lines and the number of code lines of the target program;

[0009] The recommendation score of the target program is determined based on the code complexity of the target program, the code unit test coverage and the risk of the target program; wherein, the higher the recommendation score of the target program, the more the code in the target program needs to be reviewed.

[0010] Optionally, determining the code information according to the target product name includes:

[0011] According to the name of the target product, query the code quality system to obtain the first code information of the product; wherein the first code information includes: code complexity and code unit test coverage;

[0012] The second code information of the product is obtained by querying in the distributed version control system according to the target product name; wherein the second code information includes: code modification time, number of code lines, number of function lines and second task number.

[0013] Optionally, generating a target program list according to the tasks to which the first task number belongs and the tasks to which the second task number belongs includes:

[0014] Filter the programs whose tasks belong to the second task number and the first task number are the same into the first program list;

[0015] Obtaining, by querying in the task management system, the version submission time corresponding to the first task number;

[0016] In the first program list, at least one target program whose submission time is later than the version submission time is screened and a target program list is generated.

[0017] Optionally, after determining the recommendation score of the target program according to the risk level of the target program, the method further includes:

[0018] Sort the recommendation scores of all target programs in descending order, output a preset number of target programs, and generate a code review list.

[0019] Optionally, after sorting the recommendation scores of all target programs in descending order, outputting a preset number of target programs, and generating a code review list, the method further includes:

[0020] Output the regression test case corresponding to each target program in the code review list.

[0021] A second aspect of the present application provides a code quality detection device, including:

[0022] A receiving unit, used for receiving a target product name and a first task number;

[0023] A first determining unit is used to determine code information according to the target product name; wherein the code information includes code complexity, code unit test coverage, code modification time, number of code lines, number of function lines and second task number;

[0024] A first generating unit, configured to generate a target program list according to the tasks to which the first task number belongs and the tasks to which the second task number belongs;

[0025] A second determining unit is used to determine the risk level of each target program in the target program list according to the number of function lines and the number of code lines of the target program;

[0026] The third determination unit is used to determine the recommendation score of the target program according to the code complexity of the target program, the code unit test coverage and the risk of the target program; wherein, the higher the recommendation score of the target program, the more the code in the target program needs to be reviewed.

[0027] Optionally, the first determining unit includes:

[0028] A first query unit is used to query the code quality system according to the target product name to obtain the first code information of the product; wherein the first code information includes: code complexity and code unit test coverage;

[0029] The second query unit is used to query the distributed version control system according to the target product name to obtain the second code information of the product; wherein the second code information includes: code modification time, number of code lines, number of function lines and second task number.

[0030] Optionally, the first generating unit includes:

[0031] A screening unit, used for screening programs to which the task to which the second task number belongs is the same as the task to which the first task number belongs, into the first program list;

[0032] A third query unit, configured to query in a task management system to obtain a version submission time corresponding to the first task number;

[0033] The first generating subunit is used to screen out at least one target program that is later than the version submission time in the first program list, and generate a target program list.

[0034] Optionally, the code quality detection device also includes:

[0035] The second generating unit is used to sort the recommendation scores of all target programs in descending order, output a preset number of target programs, and generate a code review list.

[0036] Optionally, the code quality detection device also includes:

[0037] The output unit is used to output the regression test case corresponding to each target program in the code review list.

[0038] A third aspect of the present application provides an electronic device, including:

[0039] one or more processors;

[0040] a storage device having one or more programs stored thereon;

[0041] When the one or more programs are executed by the one or more processors, the one or more processors implement the code quality detection method as described in any one of the first aspects.

[0042] A fourth aspect of the present application provides a computer storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the code quality detection method as described in any one of the first aspects is implemented.

[0043] As can be seen from the above scheme, the present application provides a method, device, electronic device and computer storage medium for detecting code quality, wherein the method for detecting code quality comprises: after receiving the target product name and the first task number; first, determining the code information according to the target product name; wherein the code information comprises code complexity, code unit test coverage, code modification time, number of code lines, number of function lines and second task number; then, generating a target program list according to the task to which the first task number belongs and the task to which the second task number belongs; then, for each target program in the target program list, determining the risk of the target program according to the number of function lines and number of code lines of the target program; finally, determining the recommendation score of the target program according to the code complexity, code unit test coverage and risk of the target program; wherein the higher the recommendation score of the target program, the more the code in the target program needs to be reviewed. Thus, the purpose of accurately detecting the code quality and timely obtaining the code of the program that needs to be reviewed is achieved. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0045] Figure 1 A specific flow chart of a code quality detection method provided in an embodiment of the present application;

[0046] Figure 2 A flowchart for determining code information provided by another embodiment of the present application;

[0047] Figure 3 A flowchart for generating a target program list provided by another embodiment of the present application;

[0048] Figure 4 A schematic diagram of a code quality detection device provided in another embodiment of the present application;

[0049] Figure 5 A schematic diagram of a first determination unit provided in another embodiment of the present application;

[0050] Figure 6 A schematic diagram of a first generating unit provided in another embodiment of the present application;

[0051] Figure 7 A schematic diagram of an electronic device for implementing a method for detecting code quality provided in another embodiment of the present application. DETAILED DESCRIPTION

[0052] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0053] It should be noted that the concepts of "first", "second", etc. mentioned in this application are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units, and the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0054] The present application embodiment provides a method for detecting code quality, such as Figure 1 As shown, the specific steps include:

[0055] S101, receiving a target product name and a first task number.

[0056] S102: Determine code information according to the target product name.

[0057] The code information includes code complexity, code unit test coverage, code modification time, number of code lines, number of function lines and second task number.

[0058] Optionally, in another embodiment of the present application, an implementation of step S102 is as follows: Figure 2 As shown, including:

[0059] S201. Query and obtain first code information of the product in a code quality system according to the name of the target product.

[0060] The first code information includes: code complexity and code unit test coverage. The code quality system may be, but is not limited to, a sonar system, etc., which is not limited here and is mainly used to scan codes.

[0061] S202: Query and obtain second code information of the product in the distributed version control system according to the target product name.

[0062] The second code information includes: code modification time, code line number, function line number and second task number. The distributed version control system can be but not limited to git, etc., which is not limited here and is mainly used to manage code.

[0063] S103 , generating a target program list according to the tasks to which the first task number belongs and the tasks to which the second task number belongs.

[0064] Optionally, in another embodiment of the present application, an implementation of step S103 is as follows: Figure 3 As shown, including:

[0065] S301, filtering programs to which the task to which the second task number belongs is the same as the task to which the first task number belongs into a first program list.

[0066] S302: Query in the task management system to obtain the version submission time corresponding to the first task number.

[0067] S303: In the first program list, filter out at least one target program that is later than the version submission time, and generate a target program list.

[0068] S104 . For each target program in the target program list, determine the risk level of the target program according to the number of function lines and code lines of the target program.

[0069] Specifically, in the implementation process of this application, the risk of the target program can be calculated using the following calculation formula:

[0070] bug_venture=modified_lines*modified_lines_weight+function_lines*function_lines_weight

[0071] Among them, bug_venture is the risk of the target program; modified_lines is the number of function lines; modified_lines_weight is the weight corresponding to the number of function lines; function_lines is the number of code lines; function_lines_weight is the weight corresponding to the number of code lines.

[0072] It should be noted that the weight corresponding to the number of function lines and the weight corresponding to the number of code lines are pre-set and changed by technical personnel or relevant authorized staff, and are not limited here.

[0073] S105 . Determine a recommendation score of the target program according to the code complexity, code unit test coverage, and risk level of the target program.

[0074] Among them, the higher the recommendation score of the target program, the more the code in the target program needs to be reviewed.

[0075] Specifically, in the implementation process of this application, the following calculation formula can be used to calculate the recommendation score of the target program:

[0076] score=complexity*weight_complexity+(1-coverage)*weight_coverage+bug_venture*bug_weight

[0077] Among them, score is the recommendation score of the target program; complexity is the code complexity; weight_complexity is the weight corresponding to the code complexity; coverage is the code unit test coverage; weight_coverage is the weight corresponding to the code unit test coverage; bug_venture*bug_weight is the weight corresponding to the risk of the target program.

[0078] It should be noted that the weight corresponding to the code complexity, the weight corresponding to the code unit test coverage, and the weight corresponding to the risk of the target program are pre-set and changed by technical personnel or relevant authorized staff, and are not mentioned here.

[0079] Optionally, in another embodiment of the present application, an implementation of the code quality detection method further includes:

[0080] Sort the recommendation scores of all target programs in descending order, output a preset number of target programs, and generate a code review list.

[0081] Among them, the preset number is pre-set and changed by technical personnel or relevant authorized staff, and is not required here.

[0082] Optionally, in another embodiment of the present application, an implementation of the code quality detection method further includes:

[0083] Output the regression test cases corresponding to each target program in the code review list.

[0084] Among them, the regression test cases corresponding to the target program are pre-stored, and the regression test cases corresponding to each target program in the code review list can be quickly obtained in the code review list, so that regression testing can be carried out at the first time, thereby reducing the risk of system production and facilitating quality management.

[0085] As can be seen from the above scheme, the present application provides a method for detecting code quality: after receiving the target product name and the first task number; first, determine the code information according to the target product name; wherein the code information includes code complexity, code unit test coverage, code modification time, number of code lines, number of function lines and second task number; then, generate a target program list according to the task to which the first task number belongs and the task to which the second task number belongs; then, for each target program in the target program list, determine the risk of the target program according to the number of function lines and number of code lines of the target program; finally, determine the recommendation score of the target program according to the code complexity, code unit test coverage and risk of the target program; wherein, the higher the recommendation score of the target program, the more the code in the target program needs to be reviewed. Thus, the purpose of accurately detecting the code quality and timely obtaining the code of the program that needs to be reviewed is achieved.

[0086] The invention name provided by the present invention can be used in the financial field or other fields, for example, it can be used in the financial program code inspection application scenario in the financial field. Other fields are any fields other than the financial field, for example, the code inspection field. The above is only an example and does not limit the application field of the invention name provided by the present invention.

[0087] In another embodiment of the present application, an implementation of a code quality detection device is as follows: Figure 4 As shown, including:

[0088] The receiving unit 401 is used to receive a target product name and a first task number.

[0089] The first determining unit 402 is used to determine the code information according to the target product name.

[0090] The code information includes code complexity, code unit test coverage, code modification time, number of code lines, number of function lines and second task number.

[0091] Optionally, in another embodiment of the present application, an implementation of the first determining unit 402 is as follows: Figure 5 As shown, including:

[0092] The first query unit 501 is used to query the code quality system according to the name of the target product to obtain the first code information of the product.

[0093] The first code information includes: code complexity and code unit test coverage.

[0094] The second query unit 502 is used to query the distributed version control system according to the target product name to obtain the second code information of the product.

[0095] The second code information includes: code modification time, code line number, function line number and second task number.

[0096] For the specific working process of the units disclosed in the above embodiments of the present application, please refer to the corresponding method embodiments, such as Figure 2 As shown, no further description is given here.

[0097] The first generating unit 403 is used to generate a target program list according to the tasks to which the first task number belongs and the tasks to which the second task number belongs.

[0098] Optionally, in another embodiment of the present application, an implementation of the first generating unit 403 is as follows: Figure 6 As shown, including:

[0099] The screening unit 601 is used to screen the programs whose tasks belong to the second task number and the first task number are the same as each other into the first program list.

[0100] The third query unit 602 is used to query in the task management system to obtain the version submission time corresponding to the first task number.

[0101] The first generating subunit 603 is used to filter out at least one target program whose version submission time is later than that in the first program list, and generate a target program list.

[0102] For the specific working process of the units disclosed in the above embodiments of the present application, please refer to the corresponding method embodiments, such as Figure 3 As shown, no further description is given here.

[0103] The second determining unit 404 is used to determine the risk level of each target program in the target program list according to the number of function lines and code lines of the target program.

[0104] The third determining unit 405 is used to determine the recommendation score of the target program according to the code complexity of the target program, the code unit test coverage and the risk of the target program.

[0105] Among them, the higher the recommendation score of the target program, the more the code in the target program needs to be reviewed.

[0106] For the specific working process of the units disclosed in the above embodiments of the present application, please refer to the corresponding method embodiments, such as Figure 1 As shown, no further description is given here.

[0107] Optionally, in another embodiment of the present application, an implementation of the code quality detection device further includes:

[0108] The second generating unit is used to sort the recommendation scores of all target programs in descending order, output a preset number of target programs, and generate a code review list.

[0109] The specific working process of the units disclosed in the above embodiments of the present application can be found in the corresponding method embodiments, which will not be repeated here.

[0110] Optionally, in another embodiment of the present application, an implementation of the code quality detection device further includes:

[0111] The output unit is used to output the regression test cases corresponding to each target program in the code review list.

[0112] The specific working process of the units disclosed in the above embodiments of the present application can be found in the corresponding method embodiments, which will not be repeated here.

[0113] As can be seen from the above scheme, the present application provides a code quality detection device: after the receiving unit 401 receives the target product name and the first task number; first, the first determination unit 402 determines the code information according to the target product name; wherein the code information includes code complexity, code unit test coverage, code modification time, number of code lines, number of function lines and the second task number; then, the first generation unit 403 generates a target program list according to the task to which the first task number belongs and the task to which the second task number belongs; the second determination unit 404 then determines the risk of the target program according to the number of function lines and number of code lines of the target program for each target program in the target program list; finally, the third determination unit 405 determines the recommendation score of the target program according to the code complexity, code unit test coverage and risk of the target program; wherein, the higher the recommendation score of the target program, the more the code in the target program needs to be reviewed. Thus, the purpose of accurately detecting the code quality and timely obtaining the code of the program that needs to be reviewed is achieved.

[0114] Another embodiment of the present application provides an electronic device, such as Figure 7 As shown, including:

[0115] One or more processors 701.

[0116] The storage device 702 stores one or more programs.

[0117] When the one or more programs are executed by the one or more processors 701, the one or more processors 701 implement the heavy metal product display method as described in any one of the above embodiments.

[0118] Another embodiment of the present application provides a computer storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the method for displaying heavy metal products as described in any one of the above embodiments is implemented.

[0119] In the above embodiments disclosed in the present application, it should be understood that the disclosed apparatus and method can also be implemented in other ways. The apparatus and method embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the apparatus, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, program segment or a part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0120] In addition, each functional module in each embodiment of the present disclosure can be integrated together to form an independent part, or each module can exist separately, or two or more modules can be integrated to form an independent part. If the function is implemented in the form of a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present disclosure is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a live broadcast device, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.

[0121] The present application can be implemented or used by professionals and technicians. Various modifications to these embodiments will be apparent to professionals and technicians in the field, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for detecting code quality, characterized in that: include: Receive the target product name and the first task number; Determine the code information according to the target product name; wherein the code information includes code complexity, code unit test coverage, code modification time, number of code lines, number of function lines and second task number; Generate a target program list according to the tasks to which the first task number belongs and the tasks to which the second task number belongs, including: filter the programs to which the second task number belongs and the first task number belong to be the same into the first program list; query the task management system to obtain the version submission time corresponding to the first task number; filter out at least one target program later than the version submission time in the first program list, and generate a target program list; For each target program in the target program list, determine the risk level of the target program according to the number of function lines and the number of code lines of the target program; The recommendation score of the target program is determined based on the code complexity of the target program, the code unit test coverage and the risk of the target program; wherein, the higher the recommendation score of the target program, the more the code in the target program needs to be reviewed.

2. The detection method according to claim 1, characterized in that: The step of determining the code information according to the target product name includes: According to the name of the target product, query the code quality system to obtain the first code information of the product; wherein the first code information includes: code complexity and code unit test coverage; The second code information of the product is obtained by querying in the distributed version control system according to the target product name; wherein the second code information includes: code modification time, number of code lines, number of function lines and second task number.

3. The detection method according to claim 1, characterized in that: After determining the recommendation score of the target program according to the risk level of the target program, the method further includes: Sort the recommendation scores of all target programs in descending order, output a preset number of target programs, and generate a code review list.

4. The detection method according to claim 3, characterized in that: After sorting the recommendation scores of all target programs in descending order, outputting a preset number of target programs, and generating a code review list, the method further includes: Output the regression test case corresponding to each target program in the code review list.

5. A code quality detection device, characterized in that: include: A receiving unit, used for receiving a target product name and a first task number; A first determining unit is used to determine code information according to the target product name; wherein the code information includes code complexity, code unit test coverage, code modification time, number of code lines, number of function lines and second task number; A first generating unit, configured to generate a target program list according to the tasks to which the first task number belongs and the tasks to which the second task number belongs; The first generating unit includes: a screening unit, a third query unit and a first generating sub-unit; The screening unit is used to screen the programs whose tasks belonging to the second task number are the same as the tasks belonging to the first task number into the first program list; The third query unit is used to query in the task management system to obtain the version submission time corresponding to the first task number; The first generating subunit is used to screen out at least one target program later than the version submission time in the first program list, and generate a target program list; A second determining unit is used to determine the risk level of each target program in the target program list according to the number of function lines and the number of code lines of the target program; The third determination unit is used to determine the recommendation score of the target program according to the code complexity of the target program, the code unit test coverage and the risk of the target program; wherein, the higher the recommendation score of the target program, the more the code in the target program needs to be reviewed.

6. The detection device according to claim 5, characterized in that: The first determining unit includes: A first query unit is used to query the code quality system according to the target product name to obtain the first code information of the product; wherein the first code information includes: code complexity and code unit test coverage; The second query unit is used to query the distributed version control system according to the target product name to obtain the second code information of the product; wherein the second code information includes: code modification time, number of code lines, number of function lines and second task number.

7. An electronic device, characterized in that: include: one or more processors; a storage device having one or more programs stored thereon; When the one or more programs are executed by the one or more processors, the one or more processors implement the code quality detection method according to any one of claims 1 to 4.

8. A computer storage medium, characterized in that A computer program is stored thereon, wherein when the computer program is executed by a processor, the method for detecting code quality as claimed in any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Test case sorting method and device

    CN108287785A

  • Code execution method and device based on assembly line, electronic equipment and medium

    CN114048135A