Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 68dda3a

Browse filesBrowse files
committed
Merge pull request hub4j#175
2 parents 1a071b0 + 2cd44f8 commit 68dda3a
Copy full SHA for 68dda3a

File tree

Expand file treeCollapse file tree

1 file changed

+34
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+34
-0
lines changed

‎src/main/java/org/kohsuke/github/GHRepository.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.