@@ -63,6 +63,8 @@ public class GHRepository extends GHObject {
6363
6464 private GHRepoPermission permissions ;
6565
66+ private GHRepository source , parent ;
67+
6668 public GHDeploymentBuilder createDeployment (String ref ) {
6769 return new GHDeploymentBuilder (this ,ref );
6870 }
@@ -1107,6 +1109,38 @@ public List<GHDeployKey> getDeployKeys() throws IOException{
11071109 return list ;
11081110 }
11091111
1112+ /**
1113+ * Forked repositories have a 'source' attribute that specifies the ultimate source of the forking chain.
1114+ *
1115+ * @return
1116+ * {@link GHRepository} that points to the root repository where this repository is forked
1117+ * (indirectly or directly) from. Otherwise null.
1118+ * @see #getParent()
1119+ */
1120+ public GHRepository getSource () throws IOException {
1121+ if (source == null ) return null ;
1122+ if (source .root == null )
1123+ source = root .getRepository (source .getFullName ());
1124+ return source ;
1125+ }
1126+
1127+ /**
1128+ * Forked repositories have a 'parent' attribute that specifies the repository this repository
1129+ * is directly forked from. If we keep traversing {@link #getParent()} until it returns null, that
1130+ * is {@link #getSource()}.
1131+ *
1132+ * @return
1133+ * {@link GHRepository} that points to the repository where this repository is forked
1134+ * directly from. Otherwise null.
1135+ * @see #getSource()
1136+ */
1137+ public GHRepository getParent () throws IOException {
1138+ if (parent == null ) return null ;
1139+ if (parent .root == null )
1140+ parent = root .getRepository (parent .getFullName ());
1141+ return parent ;
1142+ }
1143+
11101144 /**
11111145 * Subscribes to this repository to get notifications.
11121146 */
0 commit comments