Code submission automatic review method, system and equipment based on gerrit and medium

By configuring plug-ins and parsing code submissions on the gerrit server, the existing code review methods are solved for the cumbersome configuration and privacy leakage manually, and efficient and accurate code review is achieved, reducing the workload of code reviewers.

CN119149088APending Publication Date: 2024-12-17SHANGHAI YOULE DIGITAL TECH SOFTWARE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411151190.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-21
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

Existing code review methods require manual initialization and configuration, which have problems such as code privacy and data sources that cannot be controlled, and it is impossible to effectively check the submitted code content on the gerrit side.

Method used

By obtaining the source code and dependency code of gerrit, using SHA value to pass the code submission content into the registered plug-in, configure the gerrit server, and parse whether the code submission content complies with the set submission information rules. If it does not comply, return it to the development side to resubmit again. , if it meets, conduct a custom review to reduce the workload of code reviewers.

Benefits of technology

Automatic code review on the gerrit server is realized, which improves the efficiency and accuracy of code review, avoids privacy leakage and data source control issues, and reduces the workload of reviewers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149088A_ABST
    Figure CN119149088A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of software development, in particular to a gerrit-based code submission automatic review method, system and equipment and a medium. According to the method, a tool is written by utilizing the characteristic that gerrit supports a user-defined hook and a plug-in, and code submission can be automatically checked when a gerrit server receives the submission; the checking content comprises but is not limited to title checking of submitted information, description checking of the submitted information and compiling specification checking of submitted codes. The submission conforming to the specification passes the review and then is manually reviewed by a special code reviewer, and the submission not conforming to the specification fails and then is returned to the submitter for modification, so that the code review can be more efficiently and accurately performed, and the huge review work of the code reviewer can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software development, and in particular to a method, system, device and medium for automatic code submission review based on Gerrit. Background Art

[0002] In a software development process, developers submit code every day to develop new required functions. Different developers have different development habits, such as naming habits and formatting habits, which lead to a series of problems such as inconsistent code styles submitted to the code base or inability to distinguish the functions submitted in the submission information. Therefore, most software companies have code reviews, but as the project becomes more mature and the number of developers increases, the number of code submissions increases every day, and the workload of code reviewers becomes very large.

[0003] The existing method of using git hook to check submission information and format the code of modified files can only make partial checks locally by the submitter, and the submitter can close or skip it. It requires developers in some positions to manually initialize the configuration, which is cumbersome; the Chinese invention patent with the publication number "CN118093394A" and the name "Code review method, device, equipment and storage medium" has the problems of code leakage, large model training workload and instability when using a large language model; the Chinese invention patent with the publication number "CN118093015A" and the name "A code review method, device, electronic device and storage medium" also has the problems of code privacy and uncontrollable data source when using github for code review; the Chinese invention patent with the publication number "CN116048493" and the name "Method, system, terminal and storage medium for implementing gerrit submission information rule submission based on vscode" limits the editor to vscode, and cannot check the submitted code content on the gerrit side. Summary of the invention

[0004] In view of the existing code review method which needs manual initialization configuration, has a cumbersome process, and has the problems of uncontrollable code privacy and data source, the present invention proposes a gerrit-based automatic code submission review method, system, device and medium; firstly, the gerrit source code is obtained and the dependent code corresponding to the source code is installed; then, the code submission content is transferred to a registered plug-in according to the SHA value to complete the gerrit server configuration; finally, according to the code submission content parsed from the plug-in, it is judged whether the submission content conforms to the set submission information rules; if it does not conform to the set submission information rules, the review fails and is returned to the development end for resubmission; if it conforms, the code is submitted to manual review through code custom review, which can not only conduct code review more efficiently and accurately but also reduce the huge review workload of code reviewers.

[0005] The specific implementation contents of the present invention are as follows: A method for automatically reviewing code submission based on gerrit, firstly, obtains the source code of gerrit and installs the dependent code corresponding to the source code; then, according to the SHA value of the code submission, the code submission content is transferred to a registered plug-in, and the gerrit server is configured; finally, according to the code submission content parsed from the plug-in, whether the submission content conforms to the set submission information rules is judged, if it does not conform to the set submission information rules, the review fails and is returned to the development end for resubmission; if it conforms to the set submission information rules, the parsing is continued to judge whether the code segmentation conforms to the set submission information rules; if it does not conform, the review fails and is returned to the development end for resubmission; if it conforms, the code is submitted to manual review through code custom review.

[0006] In order to better implement the present invention, further, the gerrit-based automatic code submission review method specifically includes the following steps: Step S1: Obtain the source code of gerrit and install the dependent code corresponding to the source code; Step S2: Obtain the submitted content according to the SHA value of the code submission and pass it into the registered plug-in, write and register the server plug-in according to the plug-in interface and the set submission information rules, install the plug-in to the gerrit server, and complete the gerrit server configuration; Step S3: The submitted content of the code obtained from the developer is passed to the server plug-in, and the submitted content is parsed and determined whether it complies with the set submission information rules. If it does not comply with the set submission information rules, the review fails and is returned to the developer for resubmission. If the review passes, the parsing continues to determine whether the segmented code complies with the set submission information rules. If it does not comply, the review fails and is returned to the developer for resubmission. If it complies, it is determined to have passed the custom review.

[0007] In order to better implement the present invention, further, the step S2 specifically includes the following steps: Step S21: Obtain the SHA value of the code submission, obtain the code submission content according to the SHA value and pass it to the receiveEvent event; Step S22: Obtain the code submission content from the receiveEvent event and split it; Step S23: passing the separated code submission content into the registered plug-in; Step S24: compile and register a server plug-in that complies with the set submission information rules according to the registered plug-in interface; Step S25: Build the server plug-in into an executable file and install it to the gerrit server to complete the gerrit server configuration.

[0008] In order to better implement the present invention, further, the step S21 specifically includes the following steps: Step S211: Call the git log command from the root directory of the gerrit server according to the SHA value to obtain code submission information; Step S212: Call the git diff-tree command from the root directory of the gerrit server according to the SHA value to obtain a list of code submission files; Step S213: Obtain the content of the code submission file according to the SHA value and the code submission file list; Step S214: the code submission information is used as a title and the code submission file name and the code submission content are passed one-to-one to the received receiveEvent class.

[0009] In order to better implement the present invention, further, the specific operation of step S22 is: dividing the code submission content into content, submission information, and submission description from the object of the receiveEvent class, and encapsulating them into a json object.

[0010] In order to better implement the present invention, further, the step S3 specifically includes the following steps: Step S31: Obtain the code submission information written by the developer from the development end and push it to the gerrit server; Step S32: Pushing the code submission content from the gerrit server to the server plug-in according to the code submission information; Step S33: determine whether the parsed code submission content obtained from the server plug-in complies with the set submission information rules. If it does not comply with the set submission information rules, the review will fail and the code will be returned to the development end for resubmission. If it complies with the set submission information rules, continue parsing to determine whether the segmented code complies with the set submission information rules. If it does not comply, the review will fail and the code will be returned to the development end for resubmission. If it complies, the code will pass the custom review and be submitted to manual review.

[0011] Based on the above-mentioned Gerrit-based automatic code submission review method, in order to better realize the present invention, further, a Gerrit-based automatic code submission review system is proposed, which is used to execute the above-mentioned Gerrit-based automatic code submission review method; including an acquisition unit, a configuration unit, and a custom review unit; The acquisition unit is used to acquire the source code of Gerrit and install the dependent code corresponding to the source code; The configuration unit is used to transfer the code submission content to the registered plug-in according to the SHA value of the code submission, and configure the gerrit server; The custom review unit is used to determine whether the submitted content complies with the set submission information rules based on the code submission content obtained by parsing the plug-in. If it does not comply with the set submission information rules, the review fails and is returned to the development end for resubmission. If it complies with the set submission information rules, the parsing is continued to determine whether the code segmentation complies with the set submission information rules. If it does not comply, the review fails and is returned to the development end for resubmission. If it complies, it is submitted to manual review through the code custom review.

[0012] Based on the above-mentioned Gerrit-based automatic code submission review method, in order to better realize the present invention, further, an electronic device is proposed, including a memory and a processor; a computer program is stored on the memory; when the computer program is executed on the processor, the above-mentioned Gerrit-based automatic code submission review method is realized.

[0013] Based on the above-mentioned Gerrit-based automatic code submission review method, in order to better realize the present invention, further, a computer-readable storage medium is proposed, on which computer instructions are stored; when the computer instructions are executed on the above-mentioned electronic device, the above-mentioned Gerrit-based automatic code submission review method is implemented.

[0014] The present invention has the following beneficial effects: (1) The present invention automatically reviews submissions when the gerrit server receives the submissions, which not only enables more efficient and accurate code review but also reduces the huge review work of code reviewers.

[0015] (2) The present invention sets automatic review on the server side, which cannot be skipped or closed by the submitter. It only needs to be configured once and takes effect permanently. It also avoids the problem of privacy leakage by writing plug-ins and storing them on the server side. There are no restrictions on users and developers, and all contents such as submitted information and submitted code can be checked, which effectively reduces the workload of reviewers and greatly improves the review efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 A schematic diagram of the Gerrit server configuration process provided by an embodiment of the present invention.

[0017] Figure 2 The present invention provides an overall flow chart of the embodiment of the present invention. DETAILED DESCRIPTION

[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. It should be understood that the described embodiments are only part of the embodiments of the present invention, not all of the embodiments, and therefore should not be regarded as limiting the scope of protection. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technical personnel in this field without making creative work are within the scope of protection of the present invention.

[0019] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "disposed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be an indirect connection through an intermediate medium, or it can be the internal communication of two elements. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0020] The professional terms and explanations involved in the embodiments of the present invention are as follows: Gerrit: A code review software that uses the version control system Git as its underlying foundation.

[0021] Custom hooks and plug-ins: enhance the gerrit server and add features that it does not have.

[0022] Code review: review whether the source code submitted by developers complies with the writing specifications.

[0023] Embodiment 1: This embodiment proposes a method for automatic code submission review based on gerrit. First, the source code of gerrit is obtained and the dependent code corresponding to the source code is installed; then, the code submission content is transferred to the registered plug-in according to the SHA value of the code submission, and the gerrit server is configured; finally, according to the code submission content parsed from the plug-in, whether the submission content conforms to the set submission information rules is judged. If it does not conform to the set submission information rules, the review fails and is returned to the development end for resubmission. If it conforms to the set submission information rules, the parsing is continued to judge whether the code segmentation conforms to the set submission information rules. If it does not conform, the review fails and is returned to the development end for resubmission. If it conforms, it is submitted to manual review through code custom review. Specifically, the following steps are included: Step S1: Get the source code of gerrit and install the dependent code corresponding to the source code.

[0024] Step S2: Obtain the submitted content according to the SHA value of the code submission and pass it into the registered plug-in, write and register the server plug-in according to the plug-in interface and the set submission information rules, install the plug-in to the gerrit server, and complete the gerrit server configuration.

[0025] The step S2 specifically includes the following steps: Step S21: Obtain the SHA value of the code submission, obtain the code submission content according to the SHA value and pass it to the receiveEvent event; The step S21 specifically includes the following steps: Step S211: Call the git log command from the root directory of the gerrit server according to the SHA value to obtain code submission information; Step S212: Call the git diff-tree command from the root directory of the gerrit server according to the SHA value to obtain a list of code submission files; Step S213: Obtain the content of the code submission file according to the SHA value and the code submission file list; Step S214: the code submission information is used as a title and the code submission file name and the code submission content are passed one-to-one to the received receiveEvent class.

[0026] Step S22: Obtain the code submission content from the receiveEvent event and split it.

[0027] Furthermore, the specific operation of step S22 is: dividing the code submission content into content, submission information, and submission description from the object of the receiveEvent class, and encapsulating them into a json object.

[0028] Step S23: passing the separated code submission content into the registered plug-in; Step S24: compile and register a server plug-in that complies with the set submission information rules according to the registered plug-in interface; Step S25: Build the server plug-in into an executable file and install it to the gerrit server to complete the gerrit server configuration.

[0029] Step S3: The submitted content of the code obtained from the developer is passed to the server plug-in, and the submitted content is parsed and determined whether it complies with the set submission information rules. If it does not comply with the set submission information rules, the review fails and is returned to the developer for resubmission. If the review passes, the parsing continues to determine whether the segmented code complies with the set submission information rules. If it does not comply, the review fails and is returned to the developer for resubmission. If it complies, it is determined to have passed the custom review.

[0030] Furthermore, the step S3 specifically includes the following steps: Step S31: Obtain the code submission information written by the developer from the development end and push it to the gerrit server; Step S32: Pushing the code submission content from the gerrit server to the server plug-in according to the code submission information; Step S33: determine whether the parsed code submission content obtained from the server plug-in complies with the set submission information rules. If it does not comply with the set submission information rules, the review will fail and the code will be returned to the development end for resubmission. If it complies with the set submission information rules, continue parsing to determine whether the segmented code complies with the set submission information rules. If it does not comply, the review will fail and the code will be returned to the development end for resubmission. If it complies, the code will pass the custom review and be submitted to manual review.

[0031] Working principle: This embodiment first obtains the source code of gerrit and installs the dependent code corresponding to the source code; then the code submission content is passed to the registered plug-in according to the SHA value to complete the gerrit server configuration; finally, based on the code submission content parsed from the plug-in, it is judged whether the submission content complies with the set submission information rules. If it does not comply with the set submission information rules, the review fails and is returned to the development end for resubmission. If it complies, it is submitted to manual review through code custom review, which can not only conduct code review more efficiently and accurately but also reduce the huge review workload of code reviewers.

[0032] Embodiment 2: This embodiment is based on the above embodiment 1. Figure 1 , Figure 2 As shown, a specific embodiment is described in detail.

[0033] like Figure 1 As shown, first of all, the official Gerrit does not pass submission information to the custom plug-in, so its source code needs to be modified to support this function.

[0034] The configuration process of the gerrit server is as follows: 1. Download the gerrit source code normally and install the required dependency code for it; at this time, the receiving module cannot get the submission information and submission content, so the core code needs to be modified. The modification steps are as follows: (1) Each code submission has a unique ID, namely the SHA value; (2) Use the SHA value to go to the server project root directory and obtain the commit information through git log; (3) Use the SHA value to go to the server project root directory and use git diff-tree to get the list of submitted files; (4) Using the SHA value and file list, you can get the file content; (5) Use the submitted information as the title and pass the file name and content one by one to the receiving receiveEvent class; (6) Separate the submission content from the receiveEvent object into content, submission information, submission description, etc. and encapsulate them into a json object; (7) Pass the json object into the registered plug-in.

[0035] 2. Write and register plug-ins that meet our custom specifications through its plug-in interface.

[0036] 3. After writing, rebuild it into an executable file and install it on the server.

[0037] 4. Complete the configuration of the gerrit server.

[0038] like Figure 2 As shown, the workflow after completing the configuration of the gerrit server is as follows: 1. The developer writes the submission information and pushes the code to the gerrit server; 2. After receiving the code, the gerrit server will notify the registered plug-in with the submission content; 3. The plugin starts parsing the submitted content; 4. First, parse whether the submission information complies with our customized submission information rules; 5. We will then analyze the code format of the submitted content to see if it complies with our custom code rules; 6. If any of the conditions in step 4 and step 5 fail, the check will fail; 7. If both steps 4 and 5 are met, it will pass the custom review and enter the manual review stage.

[0039] Working principle: This embodiment uses the feature of gerrit supporting custom hooks and plug-ins to write a tool that can automatically check the code submission when the gerrit server receives the submission. The content of the inspection includes but is not limited to the title inspection of the submission information, the description inspection of the submission information, the writing specification inspection of the submitted code, etc. The submission that meets the specifications will pass the review and then be manually reviewed by a dedicated code reviewer. The submission that does not meet the specifications will fail and be returned to the submitter for modification. This can not only conduct code review more efficiently and accurately, but also reduce the huge review work of code reviewers.

[0040] The other parts of this embodiment are the same as those of the above-mentioned embodiment 1, and thus will not be described in detail.

[0041] Embodiment 3: This embodiment, based on any one of the above-mentioned embodiments 1-2, proposes a gerrit-based automatic code submission review system, which is used to execute the above-mentioned gerrit-based automatic code submission review method; it includes an acquisition unit, a configuration unit, and a custom review unit; The acquisition unit is used to acquire the source code of Gerrit and install the dependent code corresponding to the source code; The configuration unit is used to transfer the code submission content to the registered plug-in according to the SHA value of the code submission, and configure the gerrit server; The custom review unit is used to determine whether the submitted content complies with the set submission information rules based on the code submission content obtained by parsing the plug-in. If it does not comply with the set submission information rules, the review fails and is returned to the development end for resubmission. If it complies with the set submission information rules, the parsing is continued to determine whether the code segmentation complies with the set submission information rules. If it does not comply, the review fails and is returned to the development end for resubmission. If it complies, it is submitted to manual review through the code custom review.

[0042] This embodiment also proposes an electronic device, including a memory and a processor; a computer program is stored on the memory; when the computer program is executed on the processor, the above-mentioned Gerrit-based automatic code submission review method is implemented.

[0043] This embodiment also proposes a computer-readable storage medium, on which computer instructions are stored; when the computer instructions are executed on the above-mentioned electronic device, the above-mentioned Gerrit-based automatic code submission review method is implemented.

[0044] The above description is only a preferred embodiment of the present invention and does not limit the present invention in any form. Any simple modification or equivalent change made to the above embodiment based on the technical essence of the present invention shall fall within the protection scope of the present invention.

Claims

1. A method for automatic code submission review based on Gerrit, characterized in that: First, obtain the source code of gerrit and install the dependent code corresponding to the source code; then, according to the SHA value of the code submission, pass the code submission content to the registered plug-in and configure the gerrit server; finally, according to the code submission content parsed from the plug-in, determine whether the submission content complies with the set submission information rules. If it does not comply with the set submission information rules, the review will fail and be returned to the development end for resubmission. If it complies with the set submission information rules, continue to parse and determine whether the parsed and segmented code complies with the set submission information rules. If it does not comply, the review will fail and be returned to the development end for resubmission. If it complies, it will pass the code custom review and be submitted to manual review.

2. According to the gerrit-based code submission automatic review method according to claim 1, it is characterized in that: The gerrit-based automatic code submission review method specifically includes the following steps: Step S1: Obtain the source code of gerrit and install the dependent code corresponding to the source code; Step S2: Obtain the submitted content according to the SHA value of the code submission and pass it into the registered plug-in, write and register the server plug-in according to the plug-in interface and the set submission information rules, install the plug-in to the gerrit server, and complete the gerrit server configuration; Step S3: The submitted content of the code obtained from the developer is passed to the server plug-in, and the submitted content is parsed and determined whether it complies with the set submission information rules. If it does not comply with the set submission information rules, the review fails and is returned to the developer for resubmission. If the review passes, the parsing continues to determine whether the segmented code complies with the set submission information rules. If it does not comply, the review fails and is returned to the developer for resubmission. If it complies, it is determined to have passed the custom review.

3. According to the gerrit-based code submission automatic review method of claim 2, it is characterized in that: The step S2 specifically includes the following steps: Step S21: Obtain the SHA value of the code submission, obtain the code submission content according to the SHA value and pass it to the receiveEvent event; Step S22: Obtain the code submission content from the receiveEvent event and split it; Step S23: passing the separated code submission content into the registered plug-in; Step S24: compile and register a server plug-in that complies with the set submission information rules according to the registered plug-in interface; Step S25: Build the server plug-in into an executable file and install it to the gerrit server to complete the gerrit server configuration.

4. According to the gerrit-based code submission automatic review method of claim 3, it is characterized in that: The step S21 specifically includes the following steps: Step S211: Call the git log command from the root directory of the gerrit server according to the SHA value to obtain code submission information; Step S212: Call the git diff-tree command from the root directory of the gerrit server according to the SHA value to obtain a list of code submission files; Step S213: Obtain the content of the code submission file according to the SHA value and the code submission file list; Step S214: the code submission information is used as a title and the code submission file name and the code submission content are passed one-to-one to the received receiveEvent class.

5. According to the gerrit-based code submission automatic review method of claim 4, it is characterized in that: The specific operation of step S22 is: dividing the code submission content into content, submission information, and submission description from the object of the receiveEvent class, and encapsulating them into a json object.

6. According to the gerrit-based code submission automatic review method of claim 2, it is characterized in that: The step S3 specifically comprises the following steps: Step S31: Obtain the code submission information written by the developer from the development end and push it to the gerrit server; Step S32: Pushing the code submission content from the gerrit server to the server plug-in according to the code submission information; Step S33: determine whether the parsed code submission content obtained from the server plug-in complies with the set submission information rules. If it does not comply with the set submission information rules, the review will fail and the code will be returned to the development end for resubmission. If it complies with the set submission information rules, continue parsing to determine whether the segmented code complies with the set submission information rules. If it does not comply, the review will fail and the code will be returned to the development end for resubmission. If it complies, the code will pass the custom review and be submitted to manual review.

7. A gerrit-based automatic code submission review system, used to execute the gerrit-based automatic code submission review method according to claim 1; characterized in that: Includes acquisition unit, configuration unit, and custom review unit; The acquisition unit is used to acquire the source code of Gerrit and install the dependent code corresponding to the source code; The configuration unit is used to transfer the code submission content to the registered plug-in according to the SHA value of the code submission, and configure the gerrit server; The custom review unit is used to determine whether the submitted content complies with the set submission information rules based on the code submission content obtained by parsing the plug-in. If it does not comply with the set submission information rules, the review fails and is returned to the development end for resubmission. If it complies with the set submission information rules, the parsing is continued to determine whether the code segmentation complies with the set submission information rules. If it does not comply, the review fails and is returned to the development end for resubmission. If it complies, it is submitted to manual review through the code custom review.

8. An electronic device, characterized in that: It comprises a memory and a processor; a computer program is stored on the memory; when the computer program is executed on the processor, the Gerrit-based automatic code submission review method as described in any one of claims 1 to 6 is implemented.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions; when the computer instructions are executed on the electronic device as described in claim 8, the Gerrit-based code submission automatic review method as described in any one of claims 1-6 is implemented.