Automating Code Review Activities by Large-Scale Pre-training

Zhiyu Li,Shuai Lu,Daya Guo,Nan Duan,Shailesh Jannu,Grant Jenks,Deep Majumder,Jared Green,Alexey Svyatkovskiy,Shengyu Fu,Neel Sundaresan
DOI: https://doi.org/10.48550/arXiv.2203.09095
2022-10-11
Abstract:Code review is an essential part to software development lifecycle since it aims at guaranteeing the quality of codes. Modern code review activities necessitate developers viewing, understanding and even running the programs to assess logic, functionality, latency, style and other factors. It turns out that developers have to spend far too much time reviewing the code of their peers. Accordingly, it is in significant demand to automate the code review process. In this research, we focus on utilizing pre-training techniques for the tasks in the code review scenario. We collect a large-scale dataset of real-world code changes and code reviews from open-source projects in nine of the most popular programming languages. To better understand code diffs and reviews, we propose CodeReviewer, a pre-trained model that utilizes four pre-training tasks tailored specifically for the code review scenario. To evaluate our model, we focus on three key tasks related to code review activities, including code change quality estimation, review comment generation and code refinement. Furthermore, we establish a high-quality benchmark dataset based on our collected data for these three tasks and conduct comprehensive experiments on it. The experimental results demonstrate that our model outperforms the previous state-of-the-art pre-training approaches in all tasks. Further analysis show that our proposed pre-training tasks and the multilingual pre-training dataset benefit the model on the understanding of code changes and reviews.
Software Engineering,Artificial Intelligence
What problem does this paper attempt to address?
The problem that this paper attempts to solve is specific tasks in the automated code review process, in order to reduce the time and effort required by developers during the code review process. Specifically, the paper focuses on three key tasks: 1. **Code Change Quality Estimation**: Predict whether code changes require review comments, that is, determine whether the quality of code changes is high enough to be directly accepted or requires further review. This helps reviewers focus on parts of code changes that may have quality problems first, thereby improving the efficiency of code review. 2. **Review Comment Generation**: Automatically generate review comments based on code changes. This task aims to reduce the time cost for reviewers to write comments, and provide preliminary review opinions by automated means, making the review process more efficient. 3. **Code Refinement**: Generate an improved version of the code based on the original code and reviewers' comments. This task is for code submitters, helping them automatically make necessary modifications and improvements to the code after receiving review feedback. To achieve these goals, the paper proposes a large - scale pre - trained model named CodeReviewer. This model is based on the Transformer model with an encoder - decoder structure, and four pre - training tasks specifically designed for code review scenarios are designed, including Diff Tag Prediction, Denoising Code Diff, Denoising Review Comment, and Review Comment Generation. Through these pre - training tasks, CodeReviewer can better understand the relationship between code changes and review comments, and thus perform well on the above three key tasks.