Skip to content

Commit

Permalink
Merge pull request #175
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Apr 13, 2015
2 parents 1a071b0 + 2cd44f8 commit 68dda3a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Expand Up @@ -63,6 +63,8 @@ public class GHRepository extends GHObject {

private GHRepoPermission permissions;

private GHRepository source, parent;

public GHDeploymentBuilder createDeployment(String ref) {
return new GHDeploymentBuilder(this,ref);
}
Expand Down Expand Up @@ -1107,6 +1109,38 @@ public List<GHDeployKey> getDeployKeys() throws IOException{
return list;
}

/**
* Forked repositories have a 'source' attribute that specifies the ultimate source of the forking chain.
*
* @return
* {@link GHRepository} that points to the root repository where this repository is forked
* (indirectly or directly) from. Otherwise null.
* @see #getParent()
*/
public GHRepository getSource() throws IOException {
if (source == null) return null;
if (source.root == null)
source = root.getRepository(source.getFullName());
return source;
}

/**
* Forked repositories have a 'parent' attribute that specifies the repository this repository
* is directly forked from. If we keep traversing {@link #getParent()} until it returns null, that
* is {@link #getSource()}.
*
* @return
* {@link GHRepository} that points to the repository where this repository is forked
* directly from. Otherwise null.
* @see #getSource()
*/
public GHRepository getParent() throws IOException {
if (parent == null) return null;
if (parent.root == null)
parent = root.getRepository(parent.getFullName());
return parent;
}

/**
* Subscribes to this repository to get notifications.
*/
Expand Down

0 comments on commit 68dda3a

Please sign in to comment.