Commit messages are valuable resources for describing why code changes are committed to repositories in version control systems (e.g., Git). They effectively help developers understand code changes and better perform software maintenance tasks. Unfortunately, developers often neglect to write high-quality commit messages in practice. Therefore, a growing body of work is proposed to generate commit messages automatically. These works all demonstrated that how to organize and represent code changes is vital in generating good commit messages, including the use of fine-grained graphs or embeddings to better represent code changes. In this study, we choose an alternative way to condense code changes before generation, i.e., proposing brief yet concise text templates consisting of the following three parts: (1) summarized code changes, (2) elicited comments, and (3) emphasized code identifiers. Specifically, we first condense code changes by using our proposed templates with the help of a heuristic-based tool named ChangeScribe, and then fine-tune CodeLlama-7B on the pairs of our proposed templates and corresponding commit messages. Our proposed templates better utilize pre-trained language models, while being naturally brief and readable to complement generated commit messages for developers. Our evaluation based on a widely used dataset showed that our approach can outperform six baselines in terms of BLEU-Norm, METEOR, and ROUGE-L, with average improvements of 51.7%, 78.7%, and 62.5%, respectively. The ablation study and human evaluation also provide further insights into the effectiveness of our approach.
翻译:提交信息是描述代码变更为何提交至版本控制系统(如Git)仓库的宝贵资源。它们能有效帮助开发者理解代码变更,更好地执行软件维护任务。遗憾的是,实践中开发者常忽视编写高质量的提交信息。因此,越来越多的研究工作被提出以自动生成提交信息。这些研究均表明,如何组织和表示代码变更对于生成良好的提交信息至关重要,包括使用细粒度图或嵌入来更好地表示代码变更。在本研究中,我们选择在生成前压缩代码变更的替代方案,即提出由以下三部分组成的简洁文本模板:(1)概括的代码变更,(2)提取的注释,以及(3)强调的代码标识符。具体而言,我们首先借助基于启发式的工具ChangeScribe,使用我们提出的模板来压缩代码变更,然后在提出的模板与对应提交信息的配对数据上微调CodeLlama-7B模型。我们提出的模板能更好地利用预训练语言模型,同时其天然的简洁性和可读性可为开发者补充生成的提交信息。基于广泛使用的数据集进行的评估表明,我们的方法在BLEU-Norm、METEOR和ROUGE-L指标上均优于六个基线模型,平均提升分别达到51.7%、78.7%和62.5%。消融研究和人工评估也进一步证实了我们方法的有效性。