Code review recommendation method and device, equipment and storage medium
By constructing a hypergraph of the collaborative relationships between developers and pull requests, the problem of insufficient consideration of the multiple roles of developers in existing technologies is solved, resulting in higher accuracy and speed of code review recommendations, and meeting the fast and accurate recommendation needs of large open source software projects.
Patent Information
- Application Number
- CN202310111603.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-07
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2043-02-07
AI Technical Summary
Existing code review methods fail to adequately consider the collaborative behavior of developers in multiple roles, resulting in poor code reviewer recommendation performance and impacting project development speed.
By constructing a hypergraph of collaboration relationships between developers and pull requests, the original dataset is obtained and graph nodes are initialized. The association value vector is calculated, recommendation ranking is performed, and code review recommendation results are output, taking into account the collaborative impact of developers in multiple roles.
It improved the accuracy and speed of code review and recommendation, enhanced the efficiency of code review, and met the needs of large-scale open-source software projects for rapid and accurate recommendations.
Smart Images

Figure CN116108232B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of open source software ecological service recommendation, and in particular to a code review recommendation method and device, equipment and a storage medium. BACKGROUND
[0002] With the development of distributed software development, the pull-based development model has now become the preferred standard for developers to collaborate on development, and numerous platforms such as github, gitlab, gitee, etc. have emerged. These development platforms have lowered the threshold for developers to participate in project development, allowing development teams to accept external contributions and providing problem management systems for external developers. These development platforms provide many developers with the opportunity to contribute code and gain experience, promoting collaboration among developers and the iterative development of open source software projects. Generally speaking, external developers usually only have read access to open source software projects, but can obtain a local copy of the code in the remote public repository by forking and cloning. Developers can modify the code locally to fix bugs or develop new features, and then request to merge the changed code into the central repository by submitting a pull request (PR) to make their own contributions. The core team of an open source software project needs to act as a guardian of code quality, and conducts code review on submitted PRs to ensure that the new code is complete and of good quality before merging it into the central repository.
[0003] For some large open source software projects, comprehensive code review of new PRs is crucial to ensure code quality and long-term iterative development. Adequate code review can avoid potential bugs, save maintenance time, and promote experience and knowledge growth among developers during the review process. Therefore, for new PRs, appropriate code reviewers can provide effective feedback, reduce code review delays, and improve project development speed. For large open source software projects, the large number of incoming PR requests poses a serious challenge to the review work of the project core team. For example, the highly popular open source software project react has received over 12,000 PR requests since its inception, but the number of developers who have conducted reviews is less than 1,000. Typically, a PR requires multiple developers for comprehensive review, so PR management has become one of the most important activities for the core team on github.
[0004] In order to solve the above technical problems, the concept of modern code review (MCR) is proposed to quickly and accurately find suitable developers in the core team to review PR, reduce the workload while ensuring the review effect. MCR is an informal, asynchronous and tool-based lightweight code review practice, which has been widely applied in software development process. In the past research, many MCR methods have been proposed and applied to actual development, such as RevFinder algorithm based on PR modified file path set similarity. Through the summary of the past research, the existing code review methods are mostly based on machine learning (ML) and information retrieval (IR) technology, which analyzes the information such as review history, developer experience and knowledge, and then recommends code reviewers. There are also algorithms considering the social relationship of developers such as EARec and algorithms considering the mutual influence of developers such as HGRec, which further enhance the interpretability of the recommendation results.
[0005] Although the existing algorithm can better recommend code reviewers, there is still room for improvement. Although the existing code review method has involved the social relationship of developers, it does not consider the influence of the collaboration behavior of developers in multiple roles on the recommendation of code reviewers. For example, developer User1 plays the role of code submitter in PR1, and developers User1 and User2 play the role of code reviewer in PR2. When recommending reviewers for a new PR3 similar to PR1 and PR2, it is necessary to consider that User1 is more likely to be more familiar with the modified code of PR3 than User2. SUMMARY
[0006] The main purpose of the present application is to provide a code review recommendation method, device, equipment and storage medium, which aims to solve the technical problems of poor code reviewer recommendation performance, slow code review speed and influence on project development speed in the prior art.
[0007] In a first aspect, the present application provides a code review recommendation method, which comprises the following steps:
[0008] Obtaining an original data set and initializing graph nodes of developers and pull requests;
[0009] According to the original data set and the graph nodes, a collaboration relationship hypergraph of the developers and the pull requests is constructed;
[0010] According to the collaboration relationship hypergraph, a correlation value vector of each pull request is determined, a recommendation sorting is performed according to the correlation value vector, and a code review recommendation result is output.
[0011] Optionally, the original data set is acquired, and graph nodes of developers and pull requests are initialized, including:
[0012] Pull request basic information, pull request submission information, pull request comment information, pull request review information, pull request event information, and developer information interacting with the pull request are acquired, and an original data set is constructed according to the pull request basic information, the pull request submission information, the pull request comment information, the pull request review information, the pull request event information, and the developer information.
[0013] A pull request creator, a code submitter, an issue-type commenter, a review-type commenter, and a code reviewer are taken as a developer node, and the graph nodes of the developers and the pull requests are initialized.
[0014] Optionally, the collaboration relationship hypergraph of the developers and the pull requests is constructed according to the original data set and the graph nodes, including:
[0015] The similarity of a modification file path set of the pull request is acquired.
[0016] According to the similarity of the modification file path set, a pull request pair with a similarity greater than a preset similarity threshold is acquired from the original data set.
[0017] According to the pull request pair, a pull request relationship hyperedge is constructed, and an interaction behavior between each developer in each role and each pull request and a preset hyperedge weight algorithm of each type of pull request are acquired.
[0018] According to the interaction behavior, the preset hyperedge weight algorithm, and the pull request relationship hyperedge, the collaboration relationship hypergraph of the developers and the pull requests is constructed.
[0019] Optionally, the similarity of the modification file path set of the pull request is acquired, including:
[0020] The similarity of the modification file path set of the pull request is acquired by the following formula:
[0021]
[0022]
[0023] wherein, W (p i ,p j ) represents the similarity between a pull request PR i and a PR j , SimFilePath (f m ,f n ) represents the similarity between a file f m and a file fn path distance between the two nodes, LCP represents a longest common prefix function, F i and F j is distributed as PR i and PR j is a modified file path set of PR s and t e are respectively a data set start time and an end time, t i and t j is a creation time of PR i and PR j .
[0024] Optionally, the determining the association value vector of each pull request according to the collaboration relationship hypergraph, the recommendation sorting according to the association value vector, and the outputting the code review recommendation result, comprise:
[0025] calculating a hypergraph Laplacian matrix according to the collaboration relationship hypergraph;
[0026] finding the association value vector with the lowest loss function in the hypergraph Laplacian matrix according to an initial vector of a target pull request;
[0027] calculating a candidate recommendation score according to the association value vector, sorting according to the candidate recommendation score, and determining a preset number of developers as the reviewer recommendation result of each pull request according to the sorting result.
[0028] Optionally, the finding the association value vector with the lowest loss function in the hypergraph Laplacian matrix according to the initial vector of the target pull request, comprises:
[0029] calculating the loss function corresponding to each association value vector according to the initial vector of the target pull request by the following formula, and finding the association value vector with the lowest loss function in the hypergraph Laplacian matrix:
[0030]
[0031] wherein, f is the association value vector, R emp (f) is a supervised empirical error, is a hypergraph partitioning standardized loss function;
[0032] R emp (f) = λ‖f-y‖ 2
[0033] wherein, y is the initial vector of the target pull request, and λ is a positive parameter for balancing the standardized loss and the empirical loss;
[0034]
[0035] where d(v) = ∑ e∈E ω(h)h(v, e) is the degree of a vertex of the hypergraph, D v is the vertex degree matrix, δ(e) = ∑ v∈V h(v, e) is the degree of a hyperedge of the hypergraph, D e is the hyperedge degree matrix, is the formula for calculating the incidence matrix H of the hypergraph, W is a diagonal matrix recording the weights of each hyperedge, is the adjacency matrix of the hypergraph, L = I - A is the normalized Laplacian matrix of the hypergraph.
[0036] Optionally, the candidate recommendation score is calculated according to the incidence value vector, the candidate recommendation score is sorted, and a preset number of developers are determined as the reviewer recommendation results of each pull request according to the sorting result, which includes:
[0037] The candidate recommendation score is calculated according to the incidence value vector by the following formula:
[0038]
[0039] where f is the incidence value vector, is the recommendation score of the candidate u i , f[r i ] is the score of u i as a code reviewer, f[ct i ] is the score of u i as a code submitter, f[rc i ] is the score of u i as a review type commentator, f[ic i ] is the score of u i as an issue type commentator.
[0040] The second aspect, in order to achieve the above object, the present application also proposes a kind of code audit recommendation device, the code audit recommendation device includes:
[0041] Data acquisition module, for obtaining original data set, and initializing the graph node of developer and pull request;
[0042] Hypergraph construction module, for constructing the cooperative relationship hypergraph of the developer and the pull request according to the original data set and the graph node;
[0043] Sorting recommendation module, for determining the incidence value vector of each pull request according to the cooperative relationship hypergraph, recommending sorting according to the incidence value vector, and outputting code audit recommendation result.
[0044] In a third aspect, the present application provides a code review recommendation device, which comprises a memory, a processor, and a code review recommendation program stored in the memory and executable on the processor, and the code review recommendation program is configured to implement the steps of the code review recommendation method described above.
[0045] In a fourth aspect, the present application provides a storage medium, which stores a code review recommendation program, and the code review recommendation program is configured to implement the steps of the code review recommendation method described above when executed by a processor.
[0046] The code review recommendation method provided by the present application can fully consider the influence of the multiple roles of the developer in the collaboration process with the pull request on the reviewer recommendation, can more fully and comprehensively use the historical behavior information of the developer, has higher recommendation accuracy, and improves the speed and efficiency of code review recommendation. BRIEF DESCRIPTION OF DRAWINGS
[0047] Figure 1 The device structure schematic diagram of the hardware running environment involved in the embodiment scheme of the present application;
[0048] Figure 2 The flowchart of the code review recommendation method of the first embodiment of the present application;
[0049] Figure 3 The flowchart of the code review recommendation method of the second embodiment of the present application;
[0050] Figure 4 The flowchart of the code review recommendation method of the third embodiment of the present application;
[0051] Figure 5 The flowchart of the code review recommendation method of the fourth embodiment of the present application;
[0052] Figure 6 The function module diagram of the code review recommendation device of the first embodiment of the present application.
[0053] The implementation, functional features and advantages of the present application will be further described with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION
[0054] It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
[0055] The solution of the embodiment of the present application is mainly: obtaining an original data set, and initializing graph nodes of a developer and a pull request; constructing a collaboration relationship hypergraph of the developer and the pull request according to the original data set and the graph nodes; determining an association value vector of each pull request according to the collaboration relationship hypergraph, performing recommendation sorting according to the association value vector, and outputting a code review recommendation result, which can fully consider the influence of the multiple roles of the developer in the collaboration process with the pull request on the reviewer recommendation, can more fully and comprehensively use the historical behavior information of the developer, has higher recommendation accuracy, improves the speed and efficiency of the code review recommendation, and solves the technical problems of poor code reviewer recommendation performance, slow code review speed and influence on the project development speed in the prior art.
[0056] Reference Figure 1 , Figure 1 The device structure diagram of the hardware running environment involved in the embodiment of the present application is shown.
[0057] As shown in Figure 1 , the device can include a processor 1001, such as a CPU, a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 can include a display screen (Display) and an input unit such as a keyboard (Keyboard). The optional user interface 1003 can also include a standard wired interface, a wireless interface. The network interface 1004 can optionally include a standard wired interface, a wireless interface (such as a Wi-Fi interface). The memory 1005 can be a high-speed RAM memory, or a stable memory (Non-Volatile Memory), such as a magnetic disk memory. The memory 1005 can also be an independent storage device from the aforementioned processor 1001.
[0058] Those skilled in the art can understand that Figure 1 The device structure shown in the foregoing embodiments does not constitute a limitation on the device, and can include more or fewer components than the diagram, or combine certain components, or different component arrangements.
[0059] As shown in Figure 1 , the memory 1005 as a storage medium can include an operating device, a network communication module, a user interface module, and a code review recommendation program.
[0060] The device of the present application calls the code review recommendation program stored in the memory 1005 through the processor 1001, and performs the following operations:
[0061] Obtain the original dataset and initialize the graph nodes for developers and fetch requests;
[0062] Construct a hypergraph of the collaboration relationship between the developer and the pull request based on the original dataset and the graph nodes;
[0063] The association value vector of each pull request is determined based on the collaboration relationship hypergraph, and the recommendation is sorted according to the association value vector. The code review recommendation result is then output.
[0064] The device of the present invention, through processor 1001 calling the code review and recommendation program stored in memory 1005, also performs the following operations:
[0065] Obtain basic information about the pull request, pull request submission information, pull request comment information, pull request review information, pull request event information, and developer information that interacted with the pull request; construct the original dataset based on the basic information about the pull request, the pull request submission information, the pull request comment information, the pull request review information, the pull request event information, and the developer information.
[0066] Initialize the developer nodes and the graph nodes for the pull request by designating the pull request creator, code submitter, issue commenter, review commenter, and code reviewer as developer nodes.
[0067] The device of the present invention, through processor 1001 calling the code review and recommendation program stored in memory 1005, also performs the following operations:
[0068] Obtain the similarity of the modified file path set in the pull request;
[0069] Based on the modified file path set similarity, retrieve pull request pairs from the original dataset with a similarity greater than a preset similarity threshold;
[0070] Construct pull request relationship hyperedges based on the pull requests, and obtain the interaction behaviors between each developer and each pull request under various roles and the preset hyperedge weight algorithm for each type of pull request;
[0071] Based on the interaction behavior, the preset hyperedge weight algorithm and the pull request relationship hyperedge construct a collaboration relationship hypergraph between the developer and the pull request.
[0072] The device of the present invention, through processor 1001 calling the code review and recommendation program stored in memory 1005, also performs the following operations:
[0073] The similarity of the modified file path set in the pull request is calculated using the following formula:
[0074]
[0075]
[0076] Wherein, W (p i ,p j ) represents the similarity between the pull request PR i And PR j , SimFilePath (f m ,f n ) represents the path distance between file f m And file f n , LCP represents the longest common prefix function, F i And F j The distribution of PR i And PR j The modified file path set, t s And t e Respectively, the start and end time of the data set, t i And t j The creation time of PR i And PR j .
[0077] The device of the application calls the code review recommendation program stored in the memory 1005 through the processor 1001, and further performs the following operations:
[0078] According to the cooperation relation hypergraph, a hypergraph Laplace matrix is calculated;
[0079] According to the initial vector of the target pull request, find the correlation value vector with the lowest loss function in the hypergraph Laplace matrix;
[0080] According to the correlation value vector, calculate the candidate recommendation score, sort according to the candidate recommendation score, and determine the pre-set number of developers as the reviewer recommendation result of each pull request according to the sorting result.
[0081] The device of the application calls the code review recommendation program stored in the memory 1005 through the processor 1001, and further performs the following operations:
[0082] According to the initial vector of the target pull request, calculate the loss function corresponding to each correlation value vector by the following formula, and find the correlation value vector with the lowest loss function in the hypergraph Laplace matrix:
[0083]
[0084] Wherein, f is the correlation value vector, R emp (f) is the supervised empirical error, A loss function for supergraph partition standardization
[0085] R emp (f) = lambda ||f-y||2 2
[0086] Wherein y is the initial vector of the target pull request, lambda is a positive parameter for balancing the standardized loss and the empirical loss;
[0087]
[0088] Wherein d(v) = summation e∈E Omega (h) h(v, e) is the degree of the vertex of the supergraph, D ν is the vertex degree matrix, delta (e) = summation v∈V h(v, e) is the degree of the hyperedge of the supergraph, D e is the hyperedge degree matrix, is the calculation formula of the incidence matrix H of the supergraph, W is the diagonal matrix recording the weight of each hyperedge, is the adjacency matrix of the supergraph, L = I - A is the normalized Laplacian matrix of the supergraph.
[0089] The equipment of the present application calls the code review recommendation program stored in the memory 1005 through the processor 1001, and also performs the following operations:
[0090] The candidate recommendation score is calculated according to the correlation value vector by the following formula:
[0091]
[0092] Wherein f is the correlation value vector, is the recommendation score of the candidate u i , f[r i ] is the score of u i as a code reviewer, f[ct i ] is the score of u i as a code submitter, f[rc i ] is the score of u i as a review type reviewer, f[ic i ] is the score of u i as an issue type reviewer.
[0093] The embodiment can fully consider the influence of the multiple roles of the developer in the collaboration process with the pull request on the reviewer recommendation, can more fully and comprehensively use the historical behavior information of the developer, has higher recommendation accuracy, and improves the speed and efficiency of the code review recommendation.
[0094] Based on the above hardware structure, the code review recommendation method embodiment of the present application is proposed.
[0095] Reference Figure 2 , Figure 2 The flowchart of the first embodiment of the code review recommendation method of the present application is shown in FIG. 1.
[0096] In the first embodiment, the code review recommendation method comprises the following steps:
[0097] Step S10, obtaining an original data set and initializing the graph nodes of the developers and the pull requests.
[0098] It should be noted that after obtaining the original data set of the open source software project, the graph nodes of the developers and the pull requests (Pull Request, PR) can be initialized.
[0099] Step S20, constructing the collaboration relationship hypergraph of the developers and the pull requests according to the original data set and the graph nodes.
[0100] It can be understood that the collaboration relationship hypergraph corresponding to the collaboration relationship between the developers and the pull requests can be constructed by the original data set and the graph nodes.
[0101] Step S30, determining the correlation value vector of each pull request according to the collaboration relationship hypergraph, performing recommendation sorting according to the correlation value vector, and outputting the code review recommendation result.
[0102] It should be understood that the correlation value vector of each pull request can be determined by the collaboration relationship hypergraph, and then the recommendation score sorting can be performed according to the correlation value vector, so that the code review recommendation result for the open source software project can be output according to the score sorting result.
[0103] The embodiment can fully consider the influence of the multiple roles of the developer in the collaboration process with the pull request on the reviewer recommendation, can more fully and comprehensively use the historical behavior information of the developer, has higher recommendation accuracy, and improves the speed and efficiency of the code review recommendation.
[0104] Further, Figure 3 The flowchart of the second embodiment of the code review recommendation method of the present application is shown in Figure 3 The second embodiment of the code review recommendation method of the present application is proposed based on the first embodiment, and in the embodiment, the step S10 specifically includes the following steps:
[0105] Step S11, obtaining pull request basic information, pull request submission information, pull request comment information, pull request review information, pull request event information and developer information interacting with the pull request, and constructing an original data set according to the pull request basic information, the pull request submission information, the pull request comment information, the pull request review information, the pull request event information and the developer information.
[0106] It should be noted that the original data set includes pull request PR basic information, PR submission information, PR comment information, PR review information, PR event information and developer information interacting with the PR.
[0107] Step S12, taking the pull request creator, the code submitter, the issue type commenter, the review type commenter and the code reviewer as the developer node, and initializing the developer node and the graph node of the pull request.
[0108] It can be understood that the developers participating in the project and the PR can be set as graph nodes, and the developer node can be subdivided into a pull request PR creator, a code submitter, an issue type commenter, a review type commenter and a code reviewer according to the behavior, and then the developer node and the graph node of the pull request can be initialized.
[0109] It should be understood that the pull request creator, i.e. the PR creator, is the developer who actually creates the PR; the code committer is the developer who actually writes the code, and in actual development, the code modification in a PR may be completed by multiple developers; the issue type commenter is the developer who comments on the PR rather than the diff part in the specific commit, wherein the diff refers to the code modification in a specific file; the review type commenter is the developer who participates in the code review process and discusses the diff part in the specific commit; wherein the diff refers to the code modification in a specific file; and the code reviewer is the developer who makes review suggestions for the PR.
[0110] The embodiment obtains the pull request basic information, the pull request submission information, the pull request comment information, the pull request review information, the pull request event information, and the developer information interacting with the pull request, constructs an original data set according to the pull request basic information, the pull request submission information, the pull request comment information, the pull request review information, the pull request event information, and the developer information, initializes the developer nodes and the graph nodes of the pull request by taking the pull request creator, the code committer, the issue type commenter, the review type commenter, and the code reviewer as the developer nodes, can fully consider the influence of the multiple roles of the developer in the cooperation process with the pull request on the reviewer recommendation, accurately obtains the original data set and initializes the graph nodes, and improves the accuracy, speed, and efficiency of subsequent code review recommendation.
[0111] Further, Figure 4 The flowchart of the third embodiment of the code review recommendation method of the present application is shown in Figure 4 The third embodiment of the code review recommendation method of the present application is proposed based on the first embodiment, and in the embodiment, the step S20 specifically includes the following steps:
[0112] Step S21, obtaining the similarity of the modified file path set of the pull request.
[0113] It should be noted that the pull request corresponds to the similarity of the modified file path set, i.e. the modified file path set similarity.
[0114] Further, the step S21 includes the following steps:
[0115] The modified file path set similarity of the pull request is obtained by calculation according to the following formula:
[0116]
[0117]
[0118] Among them, W(p) i ,p j ) indicates a pull request (PR). i With PR j The degree of similarity between them, SimFilePath(f m ,f n ) indicates file f m With file f n The path distance between them, LCP represents the longest common prefix function, F i With F j Distribution is PR i With PR j The set of modified file paths, t s With t e These represent the start and end times of the dataset, t. i With t j For PR i With PR j Creation time.
[0119] It is understandable that the similarity between PRs can be determined by the formula above, which depends on the similarity of the modified file path sets between PRs.
[0120] Furthermore, the formula for calculating the closeness of the interaction between the PR and its creator is as follows:
[0121]
[0122] In the formula, W(p) i ,u j ) represents User j When playing the role of a PR creator, with PR i The degree of closeness of the interaction between them, t s With t e These represent the start and end times of the dataset, t. i For PR i Creation time.
[0123] Furthermore, the formula for calculating the closeness of the interaction between PRs and their code submitters is as follows:
[0124]
[0125] In the formula, W(p) i ,u) represents PR i The sum of the closeness of the interaction relationships with all its code committers, Indicates PR i Number of code committers Indicates PR i User, the code submitter m In PRi The number of submissions, t s With t e These represent the start and end times of the dataset, t. mn For PR i User, the code submitter m The creation time of the nth commit, l code For PR i User, the code submitter m The total number of lines of code modified in the nth commit, λ∈[0,1].
[0126] Furthermore, the formula for calculating the interaction relationship between PRs and developers acting as issue commenters is as follows:
[0127]
[0128] In the formula, W(p) i ,u) represents PR i The sum of the closeness of the interactions between it and all its issue-type commenters, Indicates PR i The number of issue-related comments Indicates PR i User who comments on issues m In PR i Number of comments, t s With t e These represent the start and end times of the dataset, t. mn For PR i User who comments on issues m The creation time of the nth comment, β∈[0,1].
[0129] Furthermore, the formula for calculating the closeness of the interaction between PR and reviewers is as follows:
[0130]
[0131] In the formula, W(p) i ,u) represents PR i The sum of the closeness of the interaction relationships with all its reviewers. Indicates PR i The number of reviewers. Indicates PR i User review m In PR i Number of comments, t s With t e These represent the start and end times of the dataset, t.mn For PR i User who comments on issues m The creation time of the nth comment, γ∈[0,1].
[0132] Furthermore, the formula for calculating the closeness of the interaction between PR and reviewers is as follows:
[0133]
[0134] In the formula, W(p) i ,u) represents PR i The sum of the closeness of the interactions with all its code reviewers, Indicates PR i Number of code reviewers Indicates PR i Code reviewer User m In PR i Number of reviews, t s With t e These represent the start and end times of the dataset, t. mn For PR i Code reviewer User m The creation time of the nth review, ξ∈[0,1].
[0135] Using developers and PRs as nodes and based on six types of edges, a collaborative interaction network between developers and PRs can be built.
[0136] Step S22: Obtain pull request pairs with a similarity greater than a preset similarity threshold from the original dataset based on the modified file path set similarity.
[0137] It is understood that by modifying the file path set similarity, pull request pairs with a similarity greater than a preset similarity threshold can be obtained from the original dataset. That is, based on the PR, the file path set similarity is modified, and the top K PR pairs with the highest similarity are selected.
[0138] Step S23: Construct pull request relationship hyperedges based on the pull request pairs, and obtain the interaction behaviors between each developer and each pull request under various roles and the preset hyperedge weight algorithm for each type of pull request.
[0139] It should be understood that the pull request pairs can be used to construct pull request PR relationship hyperedges, and the interaction behaviors between developers and each pull request under various roles and the preset hyperedge weight algorithms for each type of pull request can be obtained.
[0140] Step S24, according to the interaction behavior, the preset hyperedge weight algorithm and the pull request relationship hyperedge, the collaboration relationship hypergraph of the developer and the pull request is constructed.
[0141] It should be noted that the hyperedge refers to an edge composed of two or more nodes, which not only reflects the collaboration between developers, but also considers the mutual influence between developers, and the collaboration relationship hypergraph between PR and developers is constructed through multiple types of hyperedges.
[0142] It can be understood that, according to the interaction behavior, the preset hyperedge weight algorithm and the pull request relationship hyperedge, the collaboration relationship hypergraph of the developer and the pull request is constructed.
[0143] In a specific implementation, based on the interaction behavior of each developer in various roles with PR and the preset type hyperedge weight calculation method, the collaboration relationship hypergraph is constructed, wherein K is a positive integer.
[0144] The above scheme is used to obtain the modification file path set similarity of the pull request; according to the modification file path set similarity, the pull request pair with a similarity greater than a preset similarity threshold is obtained from the original data set; according to the pull request pair, the pull request relationship hyperedge is constructed, and the interaction behavior of each developer in various roles with each pull request and the preset hyperedge weight algorithm of each type of pull request are obtained; according to the interaction behavior, the preset hyperedge weight algorithm and the pull request relationship hyperedge, the collaboration relationship hypergraph of the developer and the pull request is constructed, which can quickly construct the collaboration relationship hypergraph of the developer and the pull request, fully consider the influence of multiple roles of the developer in the collaboration process with the pull request on the reviewer recommendation, improve the recommendation accuracy, and improve the speed and efficiency of code review recommendation.
[0145] Further, Figure 5 The flowchart of the fourth embodiment of the code review recommendation method of the present application is shown in Figure 5 The fourth embodiment of the code review recommendation method of the present application is proposed based on the first embodiment, and in this embodiment, the step S30 specifically includes the following steps:
[0146] Step S31, calculating the hypergraph Laplacian matrix according to the collaboration relationship hypergraph.
[0147] It should be noted that by giving a target PR, based on the collaboration relationship hypergraph, the correlation value vector f can be calculated: based on the collaboration relationship hypergraph, the hypergraph Laplacian matrix L can be calculated.
[0148] Step S32, finding the correlation value vector with the lowest loss function in the hypergraph Laplacian matrix according to the initial vector of the target pull request.
[0149] It should be understood that the initial vector of the target pull request can find the correlation value vector with the lowest loss function in the hypergraph Laplacian matrix, and the correlation value vector f that makes the loss function ψ(f) lowest is found for the initial vector y of the target PR, and the value in the vector f is the correlation value between the developer and the target PR.
[0150] Further, the step S32 specifically comprises the following steps:
[0151] The loss function corresponding to each correlation value vector is calculated according to the initial vector of the target pull request by the following formula, and the correlation value vector with the lowest loss function is found in the hypergraph Laplacian matrix:
[0152]
[0153] Wherein, f is the correlation value vector, R emp (f) is the supervised empirical error, is the loss function of the hypergraph partition standardization;
[0154] R emp (f) = λ‖f-y‖ 2
[0155] Wherein, y is the initial vector of the target pull request, and λ is a positive parameter for balancing the standardized loss and the empirical loss;
[0156]
[0157] Wherein, d(v) = ∑ e∈E ω(h)h(v,e) is the degree of the vertex of the hypergraph, D v is the vertex degree matrix, δ(e) = ∑ v∈V h(v,e) is the degree of the hyperedge of the hypergraph, D e is the hyperedge degree matrix, is the calculation formula of the correlation matrix H of the hypergraph, W is the diagonal matrix recording the weight of each hyperedge, is the adjacency matrix of the hypergraph, and L = I-A is the standardized Laplacian matrix of the hypergraph.
[0158] It should be noted that the correlation value vector f can be regarded as a prediction function, the more the connection between two vertices on the hypergraph, the higher the probability that they share similar correlation value vectors, and the value in the correlation value vector f is the correlation value between the developer and the target PR.
[0159] Further, the step calculates a candidate recommendation score according to the correlation value vector, ranks according to the candidate recommendation score, and determines a preset number of developers as the reviewer recommendation result of each pull request according to the ranking result, including:
[0160] The candidate recommendation score is calculated according to the correlation value vector by the following formula:
[0161]
[0162] Wherein, f is the correlation value vector, is the recommendation score of the candidate u i , f[r i ] is the score of u i as a code reviewer, f[ct i ] is the score of u i as a code committer, f[rc i ] is the score of u i as a review type commentator, f[ic i ] is the score of u i as an issue type commentator.
[0163] Further, the calculation formula of the loss function ψ(f) is:
[0164] ψ(f) = f T Lf + λ‖f - y‖ 2
[0165] The calculation formula of the correlation value vector f that minimizes the loss function ψ(f) is:
[0166]
[0167] In an embodiment, the recommendation score calculation formula in the step S4 is:
[0168]
[0169] Wherein, f is the developer ranking vector, is the recommendation score of the candidate u i , f[r i ] is the score of u i as a code reviewer, f[ct i ] is the score of u i as a code committer (if the candidate has never played a code committer, f[ct i ] is 0), f[rc i ] is the score of u i as a review type commentator (if the candidate has never played a review type commentator, f[rci ] is 0, f[ic i ] is u i Score of the candidate as an issue reviewer (if the candidate has never played the role of an issue reviewer, f[ic i ] is 0).
[0170] For a new target PR, all reviewers of the PR before the target PR creation time are taken as candidates, and the sum of the correlation values between each candidate playing various roles and the initial vector of the PR is calculated, that is, the recommendation score, and the recommendation score result is sorted from high to low, and the N developers with the highest recommendation score value are selected as the reviewer recommendation result of the PR.
[0171] The present embodiment fully considers various collaborative interaction relationships between developers and developers, and between developers and PRs, that is, including common submission relationships, common review relationships and two types of common comment relationships between developers, various interaction relationships between developers and PRs, and similarity relationships between PRs, constructs a collaborative relationship hypergraph between developers and PRs, performs multiple rounds of learning on the relationship between developers and PRs for the target PR initial vector, finds a suitable correlation value vector, uses the recommendation score result for reviewer recommendation, so that the recommendation result is more comprehensive and accurate.
[0172] Step S33, calculating candidate recommendation scores according to the correlation value vector, sorting according to the candidate recommendation scores, and determining a preset number of developers as reviewer recommendation results of each pull request according to the sorting result.
[0173] It can be understood that, based on the correlation value vector f, the candidate recommendation score Score is calculated: based on the correlation value vector f, for all reviewer candidates, the sum of the correlation values under different roles is taken as the final recommendation score; the reviewer recommendation result is output according to the recommendation score Score: for all reviewer candidates, the recommendation scores Score are sorted according to size, and the top N developers are determined as the reviewer recommendation result of each PR, where N is a positive integer.
[0174] According to the scheme, the hypergraph Laplacian matrix is calculated through the cooperation relationship hypergraph, the associated value vector with the lowest loss function is found in the hypergraph Laplacian matrix according to the initial vector of the target pull request, the candidate recommendation score is calculated according to the associated value vector, the candidate recommendation score is sorted, and the pre-set number of developers are determined as the reviewer recommendation results of each pull request according to the sorting result. The influence of the multiple roles of the developer in the cooperation process with the pull request on the reviewer recommendation can be fully considered, the historical behavior information of the developer can be more fully and comprehensively used, the recommendation accuracy is higher, and the speed and efficiency of the code review recommendation are improved.
[0175] Correspondingly, the application further provides a code review recommendation device.
[0176] Reference Figure 6 , Figure 6 The function module diagram of the code review recommendation device according to the first embodiment of the application is shown in the figure.
[0177] In the code review recommendation device according to the first embodiment of the application, the code review recommendation device comprises:
[0178] The data acquisition module 10 is configured to acquire an original data set and initialize the graph nodes of the developers and the pull requests.
[0179] The hypergraph construction module 20 is configured to construct the cooperation relationship hypergraph of the developers and the pull requests according to the original data set and the graph nodes.
[0180] The sorting recommendation module 30 is configured to determine the associated value vector of each pull request according to the cooperation relationship hypergraph, perform recommendation sorting according to the associated value vector, and output the code review recommendation result.
[0181] The data acquisition module 10 is further configured to acquire the pull request basic information, the pull request submission information, the pull request comment information, the pull request review information, the pull request event information and the developer information interacting with the pull request, construct the original data set according to the pull request basic information, the pull request submission information, the pull request comment information, the pull request review information, the pull request event information and the developer information, and initialize the graph nodes of the developers and the pull requests.
[0182] The supergraph construction module 20 is further configured to obtain a modification file path set similarity of the pull request, obtain a pull request pair with a similarity greater than a preset similarity threshold from the original data set according to the modification file path set similarity, construct a pull request relationship superedge according to the pull request pair, and obtain an interaction behavior between each developer under various roles and each pull request and a preset superedge weight algorithm of each type of pull request. The supergraph construction module 20 is further configured to construct a collaboration relationship supergraph of the developer and the pull request according to the interaction behavior, the preset superedge weight algorithm, and the pull request relationship superedge.
[0183] The supergraph construction module 20 is further configured to obtain the modification file path set similarity of the pull request by the following formula:
[0184]
[0185]
[0186] wherein W (p i ,p j ) represents a similarity between the pull request PR i and PR j , SimFilePath (f m ,f n ) represents a path distance between the file f m and the file f n , LCP represents a longest common prefix function, F i and F j are distributed as modification file path sets of PR i and PR j , t s and t e are start and end times of the data set, respectively, t i and t j are creation times of PR i and PR j .
[0187] The sorting and recommendation module 30 is further configured to calculate a supergraph Laplacian matrix according to the collaboration relationship supergraph, find a correlation value vector with a lowest loss function in the supergraph Laplacian matrix according to an initial vector of a target pull request, calculate a candidate person recommendation score according to the correlation value vector, sort according to the candidate person recommendation score, and determine a preset number of developers as an examiner recommendation result of each pull request according to a sorting result.
[0188] The sorting and recommendation module 30 is further configured to calculate a loss function corresponding to each correlation value vector according to an initial vector of a target pull request by the following formula, and find a correlation value vector with a lowest loss function in the supergraph Laplacian matrix:
[0189]
[0190] wherein f is the correlation value vector, R emp (f) is the supervised empirical error, is the loss function of the hypergraph partitioning standardization;
[0191] R emp (f) = λ‖f-y‖ 2
[0192] wherein y is the initial vector of the target pull request, λ is a positive parameter for balancing the standardization loss and the empirical loss;
[0193]
[0194] wherein d(v) = ∑ e∈E ω(h)h(v,e) is the degree of the vertex of the hypergraph, D v is the vertex degree matrix, δ(e) = ∑ v∈V h(v,e) is the degree of the hyperedge of the hypergraph, D e is the hyperedge degree matrix, is the calculation formula of the correlation matrix H of the hypergraph, W is a diagonal matrix recording the weight of each hyperedge, is the adjacency matrix of the hypergraph, L = I-A is the standardization Laplace matrix of the hypergraph.
[0195] The ranking recommendation module 30 is further configured to calculate a candidate recommendation score according to the correlation value vector by the following formula:
[0196]
[0197] wherein f is the correlation value vector, is the recommendation score of the candidate u i , f[r i ] is the score of u i as a code reviewer, f[ct i ] is the score of u i as a code submitter, f[rc i ] is the score of u i as a review type commentator, f[ic i ] is the score of u i as an issue type commentator.
[0198] Wherein the steps implemented by each functional module of the code review recommendation device can refer to each embodiment of the code review recommendation method of the present application, which will not be repeated here.
[0199] Furthermore, this embodiment of the invention also proposes a storage medium storing a code review recommendation program, which, when executed by a processor, performs the following operations:
[0200] Obtain the original dataset and initialize the graph nodes for developers and fetch requests;
[0201] Construct a hypergraph of the collaboration relationship between the developer and the pull request based on the original dataset and the graph nodes;
[0202] The association value vector of each pull request is determined based on the collaboration relationship hypergraph, and the recommendation is sorted according to the association value vector. The code review recommendation result is then output.
[0203] Furthermore, when the code review and recommendation program is executed by the processor, it also performs the following operations:
[0204] Obtain basic information about the pull request, pull request submission information, pull request comment information, pull request review information, pull request event information, and developer information that interacted with the pull request; construct the original dataset based on the basic information about the pull request, the pull request submission information, the pull request comment information, the pull request review information, the pull request event information, and the developer information.
[0205] Initialize the developer nodes and the graph nodes for the pull request by designating the pull request creator, code submitter, issue commenter, review commenter, and code reviewer as developer nodes.
[0206] Furthermore, when the code review and recommendation program is executed by the processor, it also performs the following operations:
[0207] Obtain the similarity of the modified file path set in the pull request;
[0208] Based on the modified file path set similarity, retrieve pull request pairs from the original dataset with a similarity greater than a preset similarity threshold;
[0209] Construct pull request relationship hyperedges based on the pull requests, and obtain the interaction behaviors between each developer and each pull request under various roles and the preset hyperedge weight algorithm for each type of pull request;
[0210] Based on the interaction behavior, the preset hyperedge weight algorithm and the pull request relationship hyperedge construct a collaboration relationship hypergraph between the developer and the pull request.
[0211] Furthermore, when the code review and recommendation program is executed by the processor, it also performs the following operations:
[0212] The similarity of the modified file path set in the pull request is calculated using the following formula:
[0213]
[0214]
[0215] Among them, W(p) i ,p j ) indicates a pull request (PR). i With PR j The degree of similarity between them, SimFilePath(f m ,f n ) indicates file f m With file f n The path distance between them, LCP represents the longest common prefix function, F i With F j Distribution is PR i With PR j The set of modified file paths, t s With t e These represent the start and end times of the dataset, t. i With t j For PR i With PR j Creation time.
[0216] Furthermore, when the code review and recommendation program is executed by the processor, it also performs the following operations:
[0217] Calculate the hypergraph Laplacian matrix based on the aforementioned cooperative hypergraph;
[0218] Based on the initial vector of the target pull request, find the correlation value vector with the lowest loss function in the Laplacian matrix of the hypergraph;
[0219] The candidate recommendation score is calculated based on the associated value vector, and the candidates are sorted according to the recommendation score. Based on the sorting result, a preset number of developers are determined as the reviewer recommendation results for each pull request.
[0220] Furthermore, when the code review and recommendation program is executed by the processor, it also performs the following operations:
[0221] Based on the initial vector of the target pull request, the loss function corresponding to each associated value vector is calculated using the following formula, and the associated value vector with the lowest loss function is found in the hypergraph Laplacian matrix:
[0222]
[0223] Where f is the associated value vector, R emp(f) represents the supervised empirical error. The loss function for hypergraph segmentation standardization;
[0224] R emp (f)=λ‖fy‖ 2
[0225] Where y is the initial vector of the target pull request, and λ is a positive parameter used to balance the standardized loss and the empirical loss;
[0226]
[0227]
[0228] Where d(v)=∑ e∈E ω(h)h(v,e) is the degree of a vertex in the hypergraph, D v Let δ(e) be the vertex degree matrix. v∈V h(v,e) is the degree of the hyperedge in the hypergraph, and D e It is the hypermarginality matrix. Here is the formula for calculating the incidence matrix H of the hypergraph, and W is a diagonal matrix recording the weights of each hyperedge. Let L be the adjacency matrix of the hypergraph, and let L = IA be the normalized Laplacian matrix of the hypergraph.
[0229] Furthermore, when the code review and recommendation program is executed by the processor, it also performs the following operations:
[0230] The candidate recommendation score is calculated based on the associated value vector using the following formula:
[0231]
[0232] Where f is the associated value vector. For candidate u i Recommended score, f[r i ] for u i As a score for code reviewers, f[ct] i ] for u i As a score for code submitters, f[rc i ] for u i As a score for reviewers, f[ic i ] for u i As a score for issue-type commenters.
[0233] This embodiment, through the above-described scheme, obtains the original dataset and initializes the graph nodes for developers and pull requests; constructs a collaboration hypergraph of the developers and pull requests based on the original dataset and the graph nodes; determines the association value vector of each pull request based on the collaboration hypergraph; performs recommendation sorting based on the association value vector; and outputs code review recommendation results. This approach fully considers the impact of the developer's multiple roles in the collaboration process with the pull request on the reviewer's recommendations, and makes more comprehensive use of the developer's historical behavior information, resulting in higher recommendation accuracy and improved speed and efficiency of code review recommendations.
[0234] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0235] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0236] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.
Claims
1. A code review and recommendation method, characterized in that, The code review and recommendation methods include: Obtain the original dataset and initialize the graph nodes for developers and fetch requests; Construct a hypergraph of the collaboration relationship between the developer and the pull request based on the original dataset and the graph nodes; The association value vector of each pull request is determined based on the collaboration relationship hypergraph, the recommendation is sorted based on the association value vector, and the code review recommendation result is output. The step of constructing a collaboration hypergraph between the developer and the pull request based on the original dataset and the graph nodes includes: Obtain the similarity of the modified file path set in the pull request; Based on the modified file path set similarity, retrieve pull request pairs from the original dataset with a similarity greater than a preset similarity threshold; Construct pull request relationship hyperedges based on the pull requests, and obtain the interaction behaviors between each developer and each pull request under various roles and the preset hyperedge weight algorithm for each type of pull request; Based on the interaction behavior, the preset hyperedge weight algorithm and the pull request relationship hyperedge construct a collaboration relationship hypergraph between the developer and the pull request; The step of determining the association value vector of each pull request based on the collaboration relationship hypergraph, performing recommendation sorting based on the association value vector, and outputting code review recommendation results includes: Calculate the hypergraph Laplacian matrix based on the aforementioned cooperative hypergraph; Based on the initial vector of the target pull request, find the correlation value vector with the lowest loss function in the Laplacian matrix of the hypergraph; The candidate recommendation score is calculated based on the associated value vector, and the candidates are sorted according to the recommendation score. Based on the sorting result, a preset number of developers are determined as the reviewer recommendation results for each pull request.
2. The code review and recommendation method as described in claim 1, characterized in that, The process of obtaining the original dataset and initializing the graph nodes for developers and pull requests includes: Obtain basic information about the pull request, pull request submission information, pull request comment information, pull request review information, pull request event information, and developer information that interacted with the pull request; construct the original dataset based on the basic information about the pull request, the pull request submission information, the pull request comment information, the pull request review information, the pull request event information, and the developer information. Initialize the developer nodes and the graph nodes for the pull request by designating the pull request creator, code submitter, issue commenter, review commenter, and code reviewer as developer nodes.
3. The code review and recommendation method as described in claim 1, characterized in that, The step of obtaining the similarity of the modified file path set in the pull request includes: The similarity of the modified file path set in the pull request is calculated using the following formula: in, Indicates a pull request and The degree of similarity between them Represents a file With the document Path distance between Represents the longest common prefix function. and Distribution and Modify the set of file paths. and These represent the start and end times of the dataset, respectively. and for and Creation time.
4. The code review and recommendation method as described in claim 1, characterized in that, The step of finding the association value vector with the lowest loss function in the hypergraph Laplacian matrix based on the initial vector of the target fetch request includes: Based on the initial vector of the target pull request, the loss function corresponding to each associated value vector is calculated using the following formula, and the associated value vector with the lowest loss function is found in the hypergraph Laplacian matrix: in, For associated value vectors, For supervised empirical error, The loss function for hypergraph segmentation standardization; in, Retrieve the initial vector requested for the target. It is a positive parameter used to weigh standardization loss against experience loss; in, Let be the degree of the vertices of the hypergraph. Let be the vertex degree matrix. Let the degree of the hyperedge of the hypergraph be . It is the hypermarginality matrix. The incidence matrix of the hypergraph The calculation formula, To record the diagonal matrix of the weights of each hyperedge, Let be the adjacency matrix of the hypergraph. Let be the normalized Laplacian matrix of the hypergraph.
5. The code review and recommendation method as described in claim 1, characterized in that, The process of calculating candidate recommendation scores based on the associated value vector, sorting candidates according to their recommendation scores, and determining a preset number of developers as reviewers for each pull request based on the sorting results includes: The candidate recommendation score is calculated based on the associated value vector using the following formula: in, That is, the associated value vector. as a candidate Recommended score, for As a score for code reviewers, for The score as a code submitter for As a score for reviewers. for As a score for issue-type commenters.
6. A code review and recommendation device, characterized in that, The code review and recommendation device includes: The data acquisition module is used to acquire the raw dataset and initialize the graph nodes for developers and fetch requests; A hypergraph construction module is used to construct a collaboration hypergraph between the developer and the pull request based on the original dataset and the graph nodes. The ranking and recommendation module is used to determine the association value vector of each pull request based on the collaboration relationship hypergraph, perform recommendation ranking based on the association value vector, and output the code review recommendation results; The hypergraph construction module is further configured to: obtain the similarity of the modified file path set of the pull request; obtain pull request pairs with a similarity greater than a preset similarity threshold from the original dataset based on the modified file path set similarity; construct pull request relationship hyperedges based on the pull request pairs; and obtain the interaction behaviors between each developer and each pull request under various roles and the preset hyperedge weighting algorithms for each type of pull request; and construct the collaboration relationship hypergraph between the developer and the pull request based on the interaction behaviors, the preset hyperedge weighting algorithms, and the pull request relationship hyperedges. The ranking and recommendation module is further configured to: calculate the hypergraph Laplacian matrix based on the collaboration relationship hypergraph; find the association value vector with the lowest loss function in the hypergraph Laplacian matrix based on the initial vector of the target pull request; calculate the candidate recommendation score based on the association value vector; rank the candidates based on the candidate recommendation scores; and determine a preset number of developers as the reviewer recommendation results for each pull request based on the ranking results.
7. A code review and recommendation device, characterized in that, The code review and recommendation device includes: a memory, a processor, and a code review and recommendation program stored on the memory and executable on the processor, wherein the code review and recommendation program is configured to implement the steps of the code review and recommendation method as described in any one of claims 1 to 5.
8. A storage medium, characterized in that, The storage medium stores a code review and recommendation program, which, when executed by a processor, implements the steps of the code review and recommendation method as described in any one of claims 1 to 5.