Sonar scanning repair method and system based on AI model
Through the Sonar scanning and repair method and system based on AI model, the time-consuming and labor-intensive problem of manually repairing Sonar bugs is solved, and fast and effective code repair is achieved, which reduces development costs and maintenance time, and improves code quality and consistency.
Patent Information
- Application Number
- CN202411331433.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2025-01-10
AI Technical Summary
In the existing technology, manually repairing Sonar bugs is time-consuming and labor-intensive, prone to omissions, high requirements for developers, difficult to control code quality, high maintenance costs, and different writing styles lead to inconsistent code quality.
Using Sonar scanning repair methods and systems based on AI model, configure Sonar scanning specifications, select and connect to the AI model, scan code through the AI model, and generate code that meets the specifications, including configuring the scanning range, analyzing code problems and providing optimization solutions. , output the optimized code.
Quickly fix scanning problems through Sonar plug-in AI model, reduce development costs, quickly respond to production quality requirements, shorten maintenance time, improve writing efficiency, reduce manual intervention needs, and improve code quality and consistency.
Smart Images

Figure CN119293796A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer software technology, and in particular to a Sonar scanning and repairing method and system based on an AI model. Background Art
[0002] Sonar Bugs usually refer to code defects or problems detected in tools such as SonarQube or SonarCloud, which may include substandard code quality, potential errors, security vulnerabilities, etc. All Sonar Bugs need to be fixed in daily code scanning, involving various trivial code style issues, including but not limited to irregular syntax, abandoned comments, etc.
[0003] In the prior art, Sonar Bugs are usually fixed manually. Every time a change is required, the developer manually writes adjustments and learns to see what kind of problem it is, how to solve it, and whether the logic involved will affect the use of other places. Therefore, there are the following disadvantages: high requirements for developers, logical problems require clear thinking and best practice experience; the level of developers is uneven, and the quality of code is often difficult to control; complex pages, obscure codes, extremely high maintenance costs, and take too long to complete the project; there are certain differences in the writing style of developers.
[0004] Based on this, a new solution is needed. Summary of the invention
[0005] The main purpose of the present invention is to provide a Sonar scanning and repairing method and system based on an AI model to address the shortcomings of the existing manual repair of Sonar Bugs, which is time-consuming, labor-intensive and prone to errors.
[0006] To achieve the above object, the present invention provides a Sonar scanning and repair method based on an AI model, comprising:
[0007] Configure the Sonar scanning specification that meets the code repository to be scanned;
[0008] Select and access AI models for scan and repair;
[0009] Set the scan scope based on the quality requirements of the project; and
[0010] The code within the scanning range is scanned by the AI model to generate a code that complies with the Sonar scanning specification.
[0011] In the Sonar scanning and repairing method based on the AI model provided by the present invention, in the step of selecting and accessing the AI model for scanning and repairing, the AI model is accessed using an API provided by Sonar-Lint.
[0012] In the Sonar scanning and repair method based on the AI model provided by the present invention, in the step of setting the scanning scope according to the quality requirements of the project, the scanning scope is set by configuring the global or current git detection of changed files.
[0013] In the Sonar scanning and repair method based on the AI model provided by the present invention, the steps of scanning the code within the scanning range by using the AI model to generate the code conforming to the Sonar scanning specification include:
[0014] Input the code within the scan range into the AI model through the API provided by Sonar-Lint;
[0015] Based on the Sonar scanning specification, the AI model is used to analyze the code within the scanning range input, and an analysis report is generated, wherein the analysis report includes problems existing in the code within the scanning range and optimization solutions;
[0016] According to the optimization scheme, optimizing the code within the scanning range;
[0017] Output the analysis report and the optimized code.
[0018] In addition, to achieve the above-mentioned purpose, the present invention also provides a Sonar scanning and repairing system based on an AI model, comprising:
[0019] The scanning specification configuration module is used to configure the Sonar scanning specifications that match the code repository to be scanned;
[0020] AI model access module, used to select and access AI models for scanning and repair;
[0021] A scanning range setting module, used to set the scanning range according to the quality requirements of the project; and
[0022] The scanning analysis module is used to scan the code within the scanning range through the AI model to generate a code that meets the Sonar scanning specification.
[0023] In the Sonar scanning and repairing system based on the AI model provided by the present invention, the AI model access module accesses the AI model using an API provided by Sonar-Lint.
[0024] In the Sonar scanning and repairing system based on the AI model provided by the present invention, the scanning range setting module sets the scanning range by configuring the global or current git detection of changed files.
[0025] In the Sonar scanning and repairing system based on the AI model provided by the present invention, the scanning analysis module includes:
[0026] An input unit, used to input the code within the scanning range into the AI model through an API provided by Sonar-Lint;
[0027] An analysis unit, configured to analyze the code within the scan range input by using the AI model based on the Sonar scan specification, and generate an analysis report, wherein the analysis report includes problems existing in the code within the scan range and optimization solutions;
[0028] An optimization unit, configured to optimize the code within the scanning range according to the optimization scheme;
[0029] An output unit is used to output the analysis report and the optimized code.
[0030] The present invention also provides a Sonar scanning and repairing device based on an AI model, comprising a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the steps of the Sonar scanning and repairing method based on the AI model as described above are implemented.
[0031] The present invention also provides a storage medium storing one or more programs, which can be executed by one or more processors to implement the steps of the Sonar scanning and repair method based on the AI model as described above.
[0032] The AI model-based Sonar scanning and repair system and method provided by the present invention have the following beneficial effects: the present invention first configures the Sonar scanning specification that conforms to the code warehouse to be scanned, selects and accesses the AI model for scanning and repair, and sets the scanning range according to the quality requirements of the project; then the code within the scanning range is scanned by the AI model to generate code that conforms to the Sonar scanning specification; thus, scanning problems can be quickly repaired through the Sonar plug-in AI model, which has the advantages of reducing development costs, quickly responding to production quality requirements, shortening maintenance time, and improving writing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art are briefly introduced below. Obviously, the drawings in the following description are only embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on the provided drawings without creative work:
[0034] Figure 1The figure is a flow chart of a Sonar scanning and repairing method based on an AI model provided in one embodiment of the present invention. DETAILED DESCRIPTION
[0035] In order to facilitate understanding of the present invention, the present invention will be described more fully below with reference to the relevant drawings. Typical embodiments of the present invention are given in the drawings. However, the present invention can be implemented in many different forms and is not limited to the embodiments described herein. On the contrary, the purpose of providing these embodiments is to make the disclosure of the present invention more thorough and comprehensive.
[0036] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in the specification of the present invention herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention.
[0037] The overall idea of the present invention is: in view of the shortcomings of the existing manual repair of Sonar Bugs, which is time-consuming, labor-intensive and prone to errors, the present invention first configures the Sonar scanning specification that meets the code warehouse to be scanned, selects and accesses the AI model for scanning and repairing, and sets the scanning range according to the quality requirements of the project; then the code within the scanning range is scanned by the AI model to generate code that meets the Sonar scanning specification; thus, the scanning problem can be quickly repaired through the Sonar plug-in AI model, which has the advantages of reducing development costs, quickly responding to production quality requirements, shortening maintenance time, and improving writing efficiency.
[0038] In order to better understand the above-mentioned technical scheme, the above-mentioned technical scheme will be described in detail below in conjunction with the accompanying drawings and specific implementation methods. It should be understood that the embodiments of the present invention and the specific features in the embodiments are detailed descriptions of the technical scheme of the present application, rather than limitations on the technical scheme of the present application. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments can be combined with each other.
[0039] Figure 1 FIG. 1 is a flow chart of a Sonar scanning and repairing method based on an AI model provided by an embodiment of the present invention. Figure 1 As shown, the Sonar scanning and repair method based on the AI model includes the following steps:
[0040] Step S1, configure the Sonar scanning specification that meets the code repository to be scanned;
[0041] Specifically, in one embodiment of the present invention, different code repositories have different scanning rules. In specific practice, it is first necessary to configure the Sonar scanning specifications that conform to the code repositories to be scanned according to the characteristics of the code repositories. Specifically, considering the complexity, scale and historical code quality of the project, the quality indicators that are focused on are clearly defined according to project requirements, such as code coverage, code duplication rate and security vulnerabilities; then, the Sonar rule set suitable for the code repositories is selected, and the default rules are adjusted to meet the specific needs of the project, wherein certain rules can be added or disabled to ensure that development is not interfered with by irrelevant warnings. By providing customized scanning rules, the actual situation of the project can be more accurately reflected to avoid false positives and missed negatives; through special configuration, specific types of problems can be better identified to promote the continuous improvement of code quality; according to changes in the project, the scanning rules can be flexibly adjusted to ensure that they always meet current needs.
[0042] In this embodiment, by configuring the standard that complies with the Sonar scanning specification, it is ensured that the generated code always complies with the best practices of the team or industry, thereby reducing human errors and inconsistencies.
[0043] Step S2: Select and access an AI model for scanning and repairing;
[0044] Specifically, in one embodiment of the present invention, the following factors need to be considered when selecting an AI model:
[0045] Functional requirements: The functions and features of different models may be different. For example, ChatGPT is good at natural language processing, while Wenxinyiyan may have more advantages in applications in certain industry fields.
[0046] Compatibility: Make sure the selected model is compatible with SonarLint and supports the required programming language and development environment;
[0047] Performance: Evaluate the model’s responsiveness and processing power to meet real-time or near-real-time code feedback requirements;
[0048] Cost: Consider the cost of using the model, including API call fees and maintenance costs.
[0049] Specifically, in one embodiment of the present invention, after selecting the AI model to be used, the API provided by Sonar-Lint is used to access the AI model. Specifically, most AI service providers will require registration and obtain an API key to ensure the security of calling the interface; configure the API key and other related parameters in the development environment to ensure that the code can access the API securely.
[0050] In this embodiment, selecting an appropriate AI model can automatically identify and fix problems in the code, significantly reducing the need for manual intervention, thereby improving the efficiency of code review and repair. At the same time, the AI model can use machine learning and data analysis technology to identify potential code defects and security vulnerabilities, providing a deeper level of analysis than traditional methods.
[0051] Step S3, setting the scanning range according to the quality requirements of the project;
[0052] Specifically, in one embodiment of the present invention, in the step of setting the scanning scope according to the quality requirements of the project, the scanning scope is set by configuring the global or current git detection of changed files. The scanning scope is set according to the quality rule requirements of the project, and the global or current git detection of changed files is simply for the global or local, and .gitignore (files to be ignored) can also be configured to ignore files separately.
[0053] In this embodiment, through global or local settings, resources can be concentrated to scan the most relevant code to avoid unnecessary time wasted on irrelevant files; local scanning can provide feedback faster, help developers find and solve problems in a timely manner, and improve development efficiency. During use, users can flexibly adjust the scan scope and rules according to project requirements to ensure that the scan strategy matches the characteristics of the project; at the same time, it can be easily configured for different development environments and team needs to enhance the applicability of the tool. Furthermore, by excluding unnecessary files (such as test files, dependent libraries, etc.), the scan results are more targeted, thereby improving the overall code quality. A clear scan scope and results make code reviews more efficient, and team members can better understand potential problems in the code.
[0054] Step S4: Scan the code within the scanning range through the AI model to generate a code that meets the Sonar scanning specification.
[0055] Specifically, in this embodiment, when SonarLint finds a code problem, the relevant code snippet and context information can be sent to the AI model through the API; after the model processes the request, it returns the analysis results and suggestions, such as code optimization, error repair, etc. At the same time, the output of the AI model can also be integrated into the SonarLint report for developers to use effectively: in the SonarLint user interface, the suggestions of the AI model are presented to developers in an easy-to-understand way, such as marking problem lines and providing code snippets with suggested repairs. Therefore, step S4 includes:
[0056] Step S41: input the code within the scanning range into the AI model through the API provided by Sonar-Lint;
[0057] Step S42: Based on the Sonar scanning specification, the AI model is used to analyze the code within the scanning range input to generate an analysis report, wherein the analysis report includes problems existing in the code within the scanning range and optimization solutions;
[0058] Step S43, optimizing the codes within the scanning range according to the optimization scheme;
[0059] Step S44: output the analysis report and the optimized code.
[0060] In this embodiment, the AI model can quickly process large-scale codes, improve analysis efficiency, and reduce the time of manual inspection. Therefore, developers can obtain feedback on code problems in real time, make timely adjustments, and shorten the development cycle. The AI model can also provide personalized optimization suggestions based on large amounts of data to improve code quality; it can continuously learn and adapt to the team's coding style to provide suggestions that are more in line with actual needs. Through automated analysis, the AI model can identify common errors and potential security risks to help developers avoid problems in advance. Through the integration of SonarLint and AI models, team members can follow unified code quality standards and reduce code problems caused by individual differences. Clear analysis reports and optimization suggestions make code reviews more efficient, allowing teams to focus on important issues.
[0061] The present invention also provides a Sonar scanning and repairing system based on an AI model, comprising:
[0062] The scanning specification configuration module is used to configure the Sonar scanning specifications that match the code repository to be scanned;
[0063] An AI model access module is used to select and access an AI model for scanning and repairing, wherein the AI model access module uses an API provided by Sonar-Lint to access the AI model;
[0064] A scanning scope setting module is used to set the scanning scope according to the quality requirements of the project, wherein the scanning scope setting module sets the scanning scope by configuring the global or current git detection of changed files;
[0065] A scanning analysis module is used to scan the code within the scanning range through the AI model to generate a code that conforms to the Sonar scanning specification. The scanning analysis module includes:
[0066] An input unit, used to input the code within the scanning range into the AI model through an API provided by Sonar-Lint;
[0067] An analysis unit, configured to analyze the code within the scan range input by using the AI model based on the Sonar scan specification, and generate an analysis report, wherein the analysis report includes problems existing in the code within the scan range and optimization solutions;
[0068] An optimization unit, configured to optimize the code within the scanning range according to the optimization scheme;
[0069] An output unit is used to output the analysis report and the optimized code.
[0070] The embodiment of the present invention further provides a Sonar scanning and repairing device based on an AI model, which may include:
[0071] Memory for storing computer programs;
[0072] The processor can implement the following steps when executing the computer program stored in the above memory:
[0073] Configure the Sonar scanning specification that meets the code repository to be scanned; select and connect the AI model for scanning and repairing; set the scanning scope according to the quality requirements of the project; and scan the code within the scanning scope through the AI model to generate code that meets the Sonar scanning specification.
[0074] The embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps can be implemented;
[0075] Configure the Sonar scanning specification that meets the code repository to be scanned; select and connect the AI model for scanning and repairing; set the scanning scope according to the quality requirements of the project; and scan the code within the scanning scope through the AI model to generate code that meets the Sonar scanning specification.
[0076] The computer-readable storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM)> a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0077] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0078] Similarly, it should be understood that in order to streamline the present disclosure and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the intention that the claimed invention requires more features than those explicitly recited in each claim. More specifically, as reflected in the claims below, inventive aspects lie in less than all the features of the individual embodiments disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present invention.
[0079] In addition, those skilled in the art will appreciate that, although some embodiments herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present invention and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.
[0080] It should be noted that the above embodiments illustrate the present invention rather than limit it, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be construed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention may be implemented by means of hardware comprising a number of different elements and by means of a suitably programmed computer. In a unit claim enumerating a number of devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc., does not indicate any order. These words may be interpreted as names.
Claims
1. A Sonar scanning and repair method based on an AI model, characterized in that: include: Configure the Sonar scanning specification that meets the code repository to be scanned; Select and access AI models for scan and repair; Set the scan scope according to the quality requirements of the project; as well as The code within the scanning range is scanned by the AI model to generate a code that complies with the Sonar scanning specification.
2. The Sonar scanning and repairing method based on the AI model as claimed in claim 1, characterized in that: In the step of selecting and accessing the AI model for scanning and repairing, the AI model is accessed using an API provided by Sonar-Lint.
3. The Sonar scanning and repairing method based on the AI model as claimed in claim 2, characterized in that: In the step of setting the scanning scope according to the quality requirements of the project, the scanning scope is set by configuring the global or current git detection of changed files.
4. The Sonar scanning and repairing method based on the AI model as claimed in claim 2, characterized in that: The steps of scanning the code within the scanning range by using the AI model to generate a code that complies with the Sonar scanning specification include: Input the code within the scan range into the AI model through the API provided by Sonar-Lint; Based on the Sonar scanning specification, the AI model is used to analyze the code within the scanning range input, and an analysis report is generated, wherein the analysis report includes problems existing in the code within the scanning range and optimization solutions; According to the optimization scheme, optimizing the code within the scanning range; Output the analysis report and the optimized code.
5. A Sonar scanning and repair system based on an AI model, characterized in that: include: The scanning specification configuration module is used to configure the Sonar scanning specifications that match the code repository to be scanned; AI model access module, used to select and access AI models for scanning and repair; A scanning range setting module, used to set the scanning range according to the quality requirements of the project; and The scanning analysis module is used to scan the code within the scanning range through the AI model to generate a code that meets the Sonar scanning specification.
6. The Sonar scanning and repairing system based on the AI model as claimed in claim 5, characterized in that: The AI model access module uses the API provided by Sonar-Lint to access the AI model.
7. The Sonar scanning and repairing system based on the AI model as claimed in claim 6, characterized in that: The scanning scope setting module sets the scanning scope by configuring the global or current git detection changed files.
8. The Sonar scanning and repairing system based on the AI model as claimed in claim 5, characterized in that: The scanning analysis module comprises: An input unit, used to input the code within the scanning range into the AI model through an API provided by Sonar-Lint; An analysis unit, configured to analyze the code within the scan range input by using the AI model based on the Sonar scan specification, and generate an analysis report, wherein the analysis report includes problems existing in the code within the scan range and optimization solutions; An optimization unit, configured to optimize the code within the scanning range according to the optimization scheme; An output unit is used to output the analysis report and the optimized code.
9. A Sonar scanning and repairing device based on an AI model, characterized in that: The method comprises a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the steps of the Sonar scanning and repair method based on the AI model as claimed in any one of claims 1 to 4 are implemented.
10. A storage medium, characterized in that: The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the Sonar scanning and repair method based on the AI model in any one of claims 1 to 4.