A DevOps-based intelligent code checking method and system
By using LLM models to perform intelligent code inspection in the DevOps environment, combined with Prompt and knowledge base technology, the problem of insufficient detection capabilities of traditional static code inspection tools is solved, and more accurate and comprehensive code quality analysis is achieved, which is adapted to the DevOps environment. Rapid iterating demands improves software development efficiency and quality.
Patent Information
- Application Number
- CN202411271719.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-11
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2044-09-11
AI Technical Summary
Traditional static code inspection tools have limited detection capabilities when facing complex logic vulnerabilities, performance issues, security issues and business compliance issues, and are difficult to meet the needs of rapid iteration and frequent delivery in the DevOps environment. They lack mature intelligent and dynamic code. Check the solution.
Using intelligent code inspection methods based on LLM models, we use Prompt technology, LLM model fine-tuning and knowledge base technology, combining semantic understanding and reasoning capabilities to conduct code style inspection, defect inspection and vulnerability inspection, providing dynamic analysis and comprehensive code quality analysis.
It improves the comprehensiveness and accuracy of code inspection, can detect complex logic vulnerabilities and security issues, reduces the cost of user-defined rules, is suitable for rapid development processes in the DevOps environment, and improves the efficiency and quality of software development.
Smart Images

Figure CN118819630B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the fields of DevOps and artificial intelligence technology, and in particular to a DevOps-based intelligent code checking method and system. Background Art
[0002] In the software development process, code quality control and assurance are key links to ensure the stability and security of software systems. Traditional code checking methods mainly rely on static analysis tools, which usually check the code through pattern matching based on predefined rule sets. These static analysis tools can detect some common syntax errors and simple logic problems, but their detection capabilities are greatly limited when faced with complex logic vulnerabilities, performance issues, security issues, and business compliance issues.
[0003] As the complexity and scale of software systems continue to increase, traditional static code checking methods based on rule matching can no longer meet the needs of modern software development. Especially in the DevOps environment, the rapid iteration and frequent delivery of development and operation require code checking tools to provide more comprehensive and accurate code quality analysis in a shorter time. However, existing static code checking tools are difficult to adapt to this efficient development process due to their inherent limitations.
[0004] In recent years, the rapid development of artificial intelligence technology, especially LLM (Large Language Model), has brought new opportunities to the field of code checking. The LLM model has strong semantic understanding and reasoning capabilities, and can understand the logical structure and contextual relationship of the code at a higher level, thereby achieving more accurate code analysis. In addition, through Prompt technology, LLM model fine-tuning technology and knowledge base technology, LLM can quickly learn and adapt to different code checking needs, providing flexible and efficient code checking solutions.
[0005] Despite this, there is currently no mature solution that can apply LLM to the field of code checking, especially to achieve intelligent and dynamic code checking in the DevOps environment. Therefore, there is an urgent need for an intelligent code checking method and system that can combine the semantic understanding and reasoning capabilities of LLM and adapt to the needs of the DevOps environment to improve the comprehensiveness and accuracy of code checking, thereby improving the efficiency and quality of software development. Summary of the invention
[0006] The embodiment of the present application provides a DevOps-based intelligent code checking method and system to solve the problems existing in the related technologies. The technical solution is as follows:
[0007] In a first aspect, an embodiment of the present application provides a DevOps-based intelligent code checking method, comprising:
[0008] Step 1: The pipeline pulls the code from the code base to the local machine;
[0009] Step 2: The code inspection module obtains the code inspection type configured by the user from the pipeline, and the code inspection type includes code style inspection, code defect inspection and code vulnerability inspection; the code vulnerability inspection refers to analyzing the security vulnerabilities existing in the code dependency according to the vulnerability information of CVE and NVD vulnerability libraries;
[0010] Step 3: Use regular expressions to extract the code language type from the file extension;
[0011] Step 4: Use the code language type and code check type to construct a query request, and call the Prompt module interface to obtain the Prompt prompt word;
[0012] Step 5: Use the code language type, code check type, and checked code content to construct a query request, and call the knowledge base interface to obtain relevant coding standards, security standards, business standards, and security vulnerability knowledge;
[0013] Step 6: Format the code content, prompt words and knowledge base data and combine them to obtain model input data;
[0014] Step 7: Input the model data, input the LLM model fine-tuned for code checking, and obtain the generated content of the LLM model;
[0015] Step 8: Convert the LLM model content into structured inspection results according to the output format configured in Prompt;
[0016] Step 9: Write the code inspection results to the database.
[0017] Preferably, the code style check includes the following contents: checking whether the coding standard, naming standard and readability of the code meet the requirements.
[0018] Preferably, the code defect check includes the following contents: checking whether the code has logic loopholes, performance problems, security loopholes or code defects.
[0019] Preferably, the code vulnerability check includes the following contents: checking whether the dependencies introduced by the code engineering have security vulnerabilities, and whether the dependency versions are too low or have stopped maintenance.
[0020] Preferably, calling the Prompt module interface to obtain the Prompt prompt word includes the following steps: training the Prompt instruction library for different language types, each language type including three types of Prompt prompt words: code style check, code defect scan and code vulnerability check; the code check module obtains the Prompt prompt word from the Prompt instruction library according to the code language type and the code check type.
[0021] Preferably, the calling of the knowledge base interface to obtain relevant coding specification knowledge, security specification knowledge, and business specification knowledge includes the following steps: the knowledge base maintains coding specifications, security specifications, and business specification documents for different language types; the code checking module obtains the coding specifications and code style documents of the specified language type from the knowledge base according to the code language type.
[0022] Preferably, the LLM model fine-tuned for code checking includes the following contents: code style fine-tuning, pulling the user code library code to fine-tune the LLM model, so that the content generated by the LLM model is closer to the user's code style; security vulnerability fine-tuning, regularly pulling vulnerability information from the CVE and NVD security vulnerability libraries, using the vulnerability information to fine-tune the LLM model, so that the LLM model remembers security vulnerabilities in different languages.
[0023] Preferably, the LLM model can be DeepSeek, Qwen, Llama, Yi.
[0024] Preferably, writing the code checking result into the database according to the LLM model content comprises the following steps: setting the format specification of the LLM model generated content in the Prompt word; converting the LLM generated content into the checking result using a regular expression according to the format specification; and saving the checking result into the database.
[0025] In a second aspect, the embodiment of the present application further provides a DevOps-based intelligent code checking system, including:
[0026] Code checking module: obtains the pipeline local code, prompt words and coding specifications of the knowledge base, then generates LLM model input data and sends it to the LLM model, and finally formats the LLM model generated content and stores it in the database;
[0027] Prompt module: trains prompt instruction libraries for different language types. Each language type contains three types of prompt words: code style check, code defect scan, and code vulnerability check.
[0028] Knowledge base module: The knowledge base maintains coding standards, security standards, and business standard documents for different language types, and supports text retrieval using vector retrieval and full-text retrieval;
[0029] Model operation module: Integrates a variety of different LLM models, including but not limited to DeepSeek, Qwen, Llama, and Yi, and provides a unified model API to the outside world;
[0030] Model fine-tuning module: Pull the user code library code to fine-tune the code style of the LLM model, so that the content generated by the LLM model is closer to the user's code style; regularly pull vulnerability information from the CVE and NVD security vulnerability libraries, and use the vulnerability information to fine-tune the LLM model to make the LLM model remember security vulnerabilities in different languages.
[0031] The advantages or beneficial effects of the above technical solution include at least:
[0032] Compared with the traditional code checking method, the present invention innovatively introduces the LLM model for code checking. By utilizing the semantic understanding and reasoning capabilities of LLM, the code checking module has a powerful dynamic analysis capability, and can understand the code logic in combination with the code context, thereby detecting complex logic vulnerabilities, performance issues, security issues, business compliance issues, and security vulnerability code issues. These functions are not achievable by traditional rule-matching-based code checking tools, thereby further helping R&D personnel improve code quality and reduce code defects.
[0033] The present invention helps the LLM model to quickly learn code-related knowledge through Prompt technology, LLM model fine-tuning technology and knowledge base technology: the user can adjust the behavior of the LLM model through Prompt prompt words, help the LLM model dynamically learn code knowledge through knowledge base retrieval, and let the LLM model remember security vulnerabilities and learn user code through fine-tuning; compared with the traditional method that relies on rule matching, the present invention has lower usage costs and more flexible rules. Users can flexibly define inspection rules without having to learn the rules and codes of various code inspection tools, thereby helping users to quickly improve code quality in combination with their own scenarios.
[0034] The present invention innovatively uses the LLM model to perform dynamic code checking, which is completely different in principle from the traditional static checking based on rule matching. The dynamic checking based on the LLM model can be simultaneously applicable to three types of code checking: code style checking, code defect scanning and code vulnerability checking, providing a comprehensive code checking solution.
[0035] The above summary is for illustrative purposes only and is not intended to be limiting in any way. In addition to the illustrative aspects, embodiments and features described above, further aspects, embodiments and features of the present application will be readily apparent by reference to the accompanying drawings and the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the accompanying drawings required for use in the embodiments will be briefly introduced below. In the accompanying drawings, unless otherwise specified, the same reference numerals throughout multiple drawings represent the same or similar parts or elements. These drawings are not necessarily drawn to scale. It should be understood that the following drawings only illustrate certain embodiments of the present application and are therefore not to be regarded as limiting the scope. For those of ordinary skill in the art, other relevant drawings can also be obtained based on these drawings without paying creative work.
[0037] Figure 1 Smart code inspection flow chart for DevOps;
[0038] Figure 2 This is a module diagram of the DevOps intelligent code inspection system;
[0039] Figure 3 Module diagram for model running module;
[0040] Figure 4 Module diagram of the model fine-tuning module. DETAILED DESCRIPTION
[0041] In the following, only some exemplary embodiments are briefly described. As those skilled in the art will appreciate, the described embodiments may be modified in various ways without departing from the spirit or scope of the present application. Therefore, the drawings and descriptions are considered to be exemplary and non-restrictive in nature.
[0042] This application discloses a DevOps-based intelligent code inspection method, the flow chart of which is as follows: Figure 1 As shown, the following steps are included:
[0043] Step 1: The pipeline pulls the code from the code repository to the local. The pipeline code pull plug-in pulls the specified branch / tag from the code repository according to the configured code repository address, login credentials, and branch / tag, and then pulls the code to the local workspace of the pipeline. Subsequent pipeline tasks will load the code files from the local workspace.
[0044] Step 2: The code inspection module obtains the code inspection type configured by the user from the pipeline. The user configures the code inspection type when arranging the pipeline. The code inspection type is passed to the code inspection module as an environment variable during runtime. The code inspection module obtains the code inspection type from the environment variable and performs the corresponding code inspection task.
[0045] Step 3: Use regular expressions to extract the code language type from the file suffix name; the code inspection module loads the local code file from the pipeline local workspace, traverses the local code file and uses regular expressions to obtain the language type;
[0046] Step 4: Use the code language type and code check type to construct a query request, and call the Prompt library interface to obtain the Prompt prompt word;
[0047] Step 5: Use the code language, code inspection type, and inspected code content to construct a query request, and call the knowledge base interface to obtain relevant coding specifications, security specifications, business specifications, and security vulnerability knowledge; the knowledge base uses vector retrieval and full-text retrieval to perform a hybrid retrieval of the knowledge base knowledge, and then reorders the hybrid retrieval results so that the results most relevant to the code are at the front, thereby improving the accuracy of the LLM model code inspection results;
[0048] Step 6: Format the code content, prompt words and knowledge base data and combine them to obtain model input data. The LLM model has a maximum token limit when generating content. Model input data that exceeds the maximum input token number will be truncated to ensure that the LLM model can output complete inspection results.
[0049] Step 7: Input the model data, input the LLM model fine-tuned for code checking, and obtain the generated content of the LLM model; the LLM model uses streaming transmission when generating the inspection content, and the code inspection module parses the returned data while the LLM model returns the data to generate the inspection results, thereby speeding up the code inspection;
[0050] Step 8: Convert the LLM model content into structured inspection results according to the output format configured in the Prompt. The Prompt prompt will provide a reference format for the generated content, and the LLM model will output the inspection content according to the reference format. The code inspection module will parse the inspection content output by the LLM model according to the reference format and then convert it into structured inspection results.
[0051] Step 9: Write the code inspection results to the database.
[0052] This application discloses a DevOps-based intelligent code inspection system. Figure 2 The following modules are shown:
[0053] 1. Pipeline module: The pipeline module is responsible for automated construction and deployment in DevOps, and can achieve continuous integration and continuous delivery. The pipeline module includes functions such as credential management, code library management, code pull plug-in, code check plug-in, compile and build plug-in, and product push plug-in, which help R&D personnel automate the R&D process and improve development efficiency.
[0054] 2. Code inspection module: The code inspection module is responsible for automated code inspection in DevOps, and can automatically perform code style inspection, code defect inspection, and code vulnerability inspection. By combining with the pipeline to achieve left shift of testing, it helps R&D to discover and fix problems as early as possible, thereby reducing repair costs and improving product quality.
[0055] Code style checking module: Use code to fine-tune the LLM model so that the LLM model can learn the coding style of the R&D team; use coding standards, business specifications and other documents to fine-tune the LLM model so that the LLM model can learn the coding standards of the R&D team; during code checking, the LLM model checks whether the coding standards, naming standards, and readability of the code meet the requirements of the R&D team based on the training corpus;
[0056] Code defect inspection module: Use the reasoning ability of the LLM model to check whether the code has logic loopholes, performance problems, security loopholes and other code defects during code inspection;
[0057] Code vulnerability check module: Use security vulnerability libraries such as CVE and NVD to fine-tune the LLM model, allowing the LLM model to continuously learn security vulnerabilities. During code inspection, the LLM model checks whether the dependencies introduced by the code project have security vulnerabilities, whether the dependency version is too low or has stopped maintenance, etc. based on the learned security vulnerability library;
[0058] Model output parsing module: parses the text content output by the LLM model and converts it into structured data, then converts the structured data into scan results, and finally saves the scan results to the database.
[0059] 3. Prompt module: Train the Prompt instruction library for different language types. Each language type contains three types of Prompt prompt words: code style check, code defect scan, and code vulnerability check. R&D personnel train Prompt to provide more accurate context for the LLM model, guide the LLM model to generate content that better meets the needs, and help the LLM model generate more accurate inspection results that better meet R&D needs.
[0060] 4. Knowledge base module: The knowledge base maintains coding standards, security standards, and business standards documents for different language types to help R&D personnel quickly accumulate and access R&D knowledge. The knowledge base can help the LLM model learn the coding standards and coding style of the R&D team as a fine-tuning corpus. The knowledge base RAG can help the LLM model dynamically learn new knowledge.
[0061] Knowledge storage module: responsible for storing knowledge business data in the OLTP database, storing knowledge content in the vector database and full-text retrieval database, and providing vector retrieval and full-text retrieval;
[0062] Knowledge retrieval module: The knowledge retrieval module provides a knowledge retrieval API, which supports vector retrieval and full-text retrieval. After receiving a retrieval request, the knowledge retrieval module will retrieve relevant knowledge from the vector database and full-text retrieval database according to the request content, and return the retrieval results after the retrieval is completed.
[0063] 5. Model operation module: Integrate a variety of different LLM models to provide external reasoning services, including but not limited to DeepSeek, Qwen, Llama, Yi; use the model reasoning framework to run the LLM model; use the model proxy module to provide a unified model API externally; such as Figure 3 As shown, the model running module includes:
[0064] Model reasoning framework: The model reasoning framework supports a variety of different reasoning frameworks and supports dynamic switching of different model reasoning frameworks, including but not limited to Ollama, TGI, and vLLM. The reasoning framework can run different LLM models to help R&D personnel quickly verify the inspection effects of different LLM models.
[0065] Model proxy module: The model proxy module provides a unified model API. The proxy module adapts to the APIs of different reasoning frameworks and handles the differences between the model APIs of different reasoning frameworks within the model proxy module.
[0066] 6. Model fine-tuning module: Pull the user code library code to fine-tune the code style of the LLM model, so that the content generated by the LLM model is closer to the user's code style; regularly pull vulnerability information from the CVE and NVD security vulnerability libraries, and use the vulnerability information to fine-tune the LLM model to make the LLM model remember security vulnerabilities in different languages; Figure 4 As shown, the model fine-tuning module includes:
[0067] Security vulnerability collection module: Use crawlers to periodically pull vulnerability information from CVE and NVD security vulnerability libraries and save the vulnerability information to object storage; at the same time, the vulnerability information is also stored in the knowledge base module. Before the model is fine-tuned, knowledge can be dynamically added to the prompt through knowledge base retrieval;
[0068] Code collection module: Use crawlers to periodically pull code from the code library, parse the repository information, language type, and code content of the code file, and save the structured data to object storage;
[0069] Text formatting module: obtains training corpus text from object storage and knowledge base modules, and then converts the corpus text into the format required by the fine-tuning module according to the corpus type;
[0070] Model fine-tuning module: Use the formatted training data to fine-tune the LLM model. The fine-tuning models include but are not limited to DeepSeek, Qwen, Llama, and Yi.
[0071] The above-mentioned embodiments only express several implementation methods of the present invention, and the description is relatively specific and detailed, but it cannot be understood as limiting the scope of the invention patent. It should be pointed out that for ordinary technicians in this field, several modifications and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention.
Claims
1. An intelligent code checking method based on DevOps, characterized in that: include: Step 1: The pipeline pulls the code from the code base to the local machine; Step 2: The code inspection module obtains the code inspection type configured by the user from the pipeline, and the code inspection type includes code style inspection, code defect inspection and code vulnerability inspection; the code vulnerability inspection refers to analyzing the security vulnerabilities existing in the code dependency according to the vulnerability information of the CVE and NVD vulnerability libraries; Step 3: Use regular expressions to extract the code language type from the file extension; Step 4: Use the code language type and the code check type to construct a query request, and call the Prompt module interface to obtain the Prompt prompt word; calling the Prompt module interface to obtain the Prompt prompt word includes the following steps: Train prompt command libraries for different language types. Each language type contains three types of prompt words: code style check, code defect scan, and code vulnerability check. The code checking module obtains the prompt word from the prompt instruction library according to the code language type and the code checking type; Step 5: Use the code language type, code check type and checked code content to construct a query request, and call the knowledge base interface to obtain relevant coding standard knowledge, security standard knowledge, and business standard knowledge; calling the knowledge base interface to obtain relevant coding standard knowledge, security standard knowledge, and business standard knowledge includes the following steps: The knowledge base maintains coding specification documents, security specification documents, and business specification documents for different language types; The code checking module obtains the coding standards and code style documents of the specified language type from the knowledge base according to the code language type; Step 6: Format the code content, prompt words and knowledge base data and combine them to obtain model input data; Step 7: Input the model data, input the LLM model fine-tuned for code checking, and obtain the generated content of the LLM model; the LLM model fine-tuned for code checking includes the following contents: Fine-tune the code style by pulling the user code base code to fine-tune the LLM model, so that the content generated by the LLM model is closer to the user's code style; Security vulnerability fine-tuning: regularly pull vulnerability information from CVE and NVD security vulnerability libraries, and use the vulnerability information to fine-tune the LLM model so that the LLM model can remember security vulnerabilities in different languages; Step 8: Convert the LLM model content into formatted inspection results according to the output format configured in the prompt; Step 9: Write the code inspection results to the database.
2. The method according to claim 1, characterized in that: The code style check includes the following contents: checking whether the coding standard, naming standard, and readability of the code meet the requirements.
3. The method according to claim 2, characterized in that: The code defect check includes the following contents: checking whether the code has logical loopholes, performance problems, and security loopholes.
4. The method according to claim 3, characterized in that: The code vulnerability check includes the following contents: checking whether the dependencies introduced by the code project have security vulnerabilities, whether the dependency versions are too low or have stopped maintenance.
5. The method according to claim 1, characterized in that: The LLM models include DeepSeek, Qwen, Llama, and Yi.
6. The method according to claim 5, characterized in that: Writing code checking results to the database based on the LLM model content includes the following steps: The format specification of the LLM model generation content is set in the Prompt prompt; Use regular expressions to convert LLM generated content into inspection results according to format specifications; Save the inspection results to the database.
7. A DevOps-based intelligent code checking system, used to implement the DevOps-based intelligent code checking method according to any one of claims 1 to 6, characterized in that: include: Code checking module: obtains the pipeline local code, prompt words and coding specifications of the knowledge base, then generates LLM model input data and sends it to the large model, and finally formats the content generated by the large model and stores it in the database; Prompt module: trains prompt instruction libraries for different language types. Each language type contains three types of prompt words: code style check, code defect scan, and code vulnerability check. Knowledge base module: The knowledge base maintains coding standards, security standards, and business standard documents for different language types, and supports text retrieval using vector retrieval and full-text retrieval; Model operation module: Integrates a variety of different LLM models, including DeepSeek, Qwen, Llama, and Yi, and provides a unified model API to the outside world; Model fine-tuning module: Pull the code from the user code library to fine-tune the code style of the LLM model, so that the content generated by the LLM model is closer to the user's code style; Vulnerability information is regularly pulled from the CVE and NVD security vulnerability libraries, and the vulnerability information is used to fine-tune the LLM model for security vulnerabilities, so that the LLM model can remember security vulnerabilities in different languages.
Citation Information
Patent Citations
Rich text code review method and system based on large language model and medium
CN118152287A