An Initial Step Towards Organ Transplantation Based on GitHub Repository

Shangwen Wang, Xiaoguang Mao, Yue Yu

Abstract

Organ transplantation, which is the utilization of codes directly related to some specific functionalities to complete one's own program, provides more convenience for developers than traditional component reuse. However, recent techniques are challenged with the lack of organs for transplantation. Hence, we conduct an empirical study on extracting organs from GitHub repository to explore transplantation based on large-scale dataset. We analyze statistics from 12 representative GitHub projects and conclude that: 1) there are abundant practical organs existing in commits with "add" as a key word in the comments; 2) organs in this repository mainly possess four kinds of contents; 3) approximately 70% of the organs are easy-to-transplant. Implementing our transplantation strategy for different kinds of organs, we manually extract 30 organs in three different programming languages (Java, Python, and C) and perform unit tests. Finally, we transplant three Java organs into a specific platform for a performance check. All results indicate the feasibility of organ transplantation based on open-source repositories, bringing new ideas for code reuse.

Introduction

In modern software engineering, code reuse is a cornerstone of efficiency. Traditionally, this has occurred at the "component" level, where developers import entire libraries or sets of classes to access specific features. However, this "all-or-nothing" approach often leads to significant code bloat and introduces unnecessary dependencies. "Software organ transplantation" offers a surgical alternative: extracting only the precise logic required for a specific functionality (the "organ") and grafting it into a new "host" application. Despite its potential, the field has been limited by an "organ shortage"—a lack of diverse, ready-to-use code snippets. This research addresses this gap by investigating GitHub as a primary source for organ harvesting.

Methodology: From Repository to Host

The proposed transplantation framework involves a multi-stage pipeline: mining, classification, extraction, and integration.

Mining and Classification

The researchers focused on GitHub commit history, specifically targeting commits containing the keyword "add." The hypothesis is that developers explicitly use this term when introducing new, modular features. Commits are classified into "practical" organs (functional code) and "unpractical" organs (documentation, comments, or configuration changes).

Figure 2: A case of adding an explanation into a project, illustrating the classification of unpractical organs during the mining phase.

Extraction and the "Vein" Concept

A major challenge in transplantation is "organ rejection," often caused by missing dependencies or variables. To solve this, the authors developed a strategy to extract the "vein"—the set of local and global variables necessary for the organ to function. By using call graphs, the system traces the state of these variables immediately before the organ's execution, ensuring the snippet remains functional in its new environment.

Placement via Lexical Fitness

To determine where an organ should be "grafted" within a host application, the study employs a lexical fitness function. This heuristic assumes that classes with similar names share similar functional contexts. By matching the vocabulary of the donor class with potential host classes, the system identifies the most compatible insertion point.

Experimental Evaluation

The study was validated through two primary experiments: an empirical analysis of 12 GitHub projects and a series of transplantation tests.

Empirical Findings

Analysis of projects like SoundJS, awesome-nlp, and requery revealed that nearly 60% of "add" commits contained practical organs. Crucially, 70% of these were "easy-to-transplant," meaning they were highly modular and required minimal modification to function independently. The mined organs ranged from simple multi-line statements (26%) and new functions (35%) to entirely new classes (17%).

Unit Testing and Host Integration

The researchers extracted 30 mathematical organs across Java, Python, and C from repositories like Apache Commons Math and SymPy. These were subjected to automated unit testing using tools such as EvoSuite, JUnit Test Generator, PyUnit, and LDRA Testbed.

  • Java Organs: 97.6% average pass rate.
  • Python Organs: 81.9% average pass rate.
  • C Organs: 80.5% average pass rate.

Furthermore, three Java organs—a background music player, a welcome screen, and a gesture password system—were successfully transplanted into MiCode Notes, an open-source Android application. The gesture password transplant, the most complex, required only 13 atomic operations (10 additions, 1 deletion, 2 modifications) to achieve full integration.

Conclusion

This study demonstrates that open-source repositories like GitHub are a viable and abundant source for software organ transplantation. By leveraging commit metadata and lexical similarity, developers can move beyond bloated component reuse toward a more precise, surgical approach to code sharing. Future work will focus on the full automation of this pipeline and handling more complex, multi-file organs.

Summary updated

Abstract

Organ transplantation, which is the utilization of codes directly related to some specific functionalities to complete ones own program, provides more convenience for developers than traditional component reuse. However, recent techniques are challenged with the lack of organs for transplantation. Hence, we conduct an empirical study on extracting organs from GitHub repository to explore transplantation based on large-scale dataset. We analyze statistics from 12 representative GitHub projects and get the conclusion that 1) there are abundant practical organs existing in commits with add as a key word in the comments; 2) organs in this repository mainly possess four kinds of contents; 3) approximately 70% of the organs are easy-to-transplant. Implementing our transplantation strategy for different kinds of organs, we manually extract 30 organs in three different programming languages, namely Java, Python, and C, and make unit tests for them utilizing four testing tools (two for Java, one for Python, and one for C). At last, we transplant three Java organs into a specific platform for a performance check to verify whether they can work well in the new system. All the 30 organs extracted by our strategy possess good performances in unit test with the highest passing rate reaching 97% and the lowest one still passing 80% and the three Java organs work well in the new system, providing three new functionalities for the host. All the results indicate the feasibility of organ transplantation based on open-source repository, bringing new idea for code reuse.
BibTeX
@inproceedings{wang2018initial,
  author = {Shangwen Wang and Xiaoguang Mao and Yue Yu},
  title = {{An Initial Step Towards Organ Transplantation Based on GitHub Repository}},
  booktitle = {IEEE Access},
  year = {2018},
  url = {https://openreview.net/forum?id=MRjkVQZ26K},
}
Figure