@@ -63,7 +63,7 @@ public class GHRepository extends GHObject {
6363
6464 private GHRepoPermission permissions ;
6565
66- private GHRepository source ;
66+ private GHRepository source , parent ;
6767
6868 public GHDeploymentBuilder createDeployment (String ref ) {
6969 return new GHDeploymentBuilder (this ,ref );
@@ -1115,6 +1115,7 @@ public List<GHDeployKey> getDeployKeys() throws IOException{
11151115 * @return
11161116 * {@link GHRepository} that points to the root repository where this repository is forked
11171117 * (indirectly or directly) from. Otherwise null.
1118+ * @see #getParent()
11181119 */
11191120 public GHRepository getSource () throws IOException {
11201121 if (source == null ) return null ;
@@ -1123,6 +1124,23 @@ public GHRepository getSource() throws IOException {
11231124 return source ;
11241125 }
11251126
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+
11261144 /**
11271145 * Subscribes to this repository to get notifications.
11281146 */
0 commit comments