Skip to content

Commit

Permalink
Reduce round trips and cleanup test data
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed May 21, 2020
1 parent 66f22de commit 1eb8bf9
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 1,100 deletions.
17 changes: 11 additions & 6 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,12 @@ GHRepository wrap(GitHub root) {
if (root.isOffline() && owner != null) {
owner.wrapUp(root);
}
if (source != null) {
source.wrap(root);
}
if (parent != null) {
parent.wrap(root);
}
return this;
}

Expand Down Expand Up @@ -2482,10 +2488,10 @@ public GHRepository getSource() throws IOException {
if (fork && source == null) {
populate();
}
if (source == null)
if (source == null) {
return null;
if (source.root == null)
source = root.getRepository(source.getFullName());
}

return source;
}

Expand All @@ -2504,10 +2510,9 @@ public GHRepository getParent() throws IOException {
populate();
}

if (parent == null)
if (parent == null) {
return null;
if (parent.root == null)
parent = root.getRepository(parent.getFullName());
}
return parent;
}

Expand Down
5 changes: 5 additions & 0 deletions src/test/java/org/kohsuke/github/GHEventPayloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,18 @@ public void pushToFork() throws Exception {
is(mockGitHub.apiServer().baseUrl() + "/repos/hub4j-test-org/github-api"));
assertThat(event.getRepository().getHttpTransportUrl(), is("https://github.com/hub4j-test-org/github-api.git"));

// ensure that root has been bound after populate
event.getRepository().getSource().getRef("heads/master");
event.getRepository().getParent().getRef("heads/master");

// Source
event = gitHub.parseEventPayload(payload.asReader(mockGitHub::mapToMockGitHub), GHEventPayload.Push.class);
assertThat(event.getRepository().getSource().getFullName(), is("hub4j/github-api"));

// Parent
event = gitHub.parseEventPayload(payload.asReader(mockGitHub::mapToMockGitHub), GHEventPayload.Push.class);
assertThat(event.getRepository().getParent().getFullName(), is("hub4j/github-api"));

}

// TODO implement support classes and write test
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ref": "refs/heads/master",
"node_id": "MDM6UmVmNjE3MjEwOnJlZnMvaGVhZHMvbWFzdGVy",
"url": "https://api.github.com/repos/hub4j/github-api/git/refs/heads/master",
"object": {
"sha": "ba12efea9d8604cad5c174620628aceb1fe224fb",
"type": "commit",
"url": "https://api.github.com/repos/hub4j/github-api/git/commits/ba12efea9d8604cad5c174620628aceb1fe224fb"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,5 @@
},
"uuid": "90aa0017-3f50-4829-bda4-6531fbcfba60",
"persistent": true,
"scenarioName": "scenario-1-repos-hub4j-test-org-github-api",
"requiredScenarioState": "Started",
"newScenarioState": "scenario-1-repos-hub4j-test-org-github-api-2",
"insertionIndex": 2
}
Loading

0 comments on commit 1eb8bf9

Please sign in to comment.