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 4ff0870

Browse filesBrowse files
committed
Refresh repositories while warp up installation event
1 parent 7fc68f2 commit 4ff0870
Copy full SHA for 4ff0870

File tree

Expand file treeCollapse file tree

3 files changed

+69
-9
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+69
-9
lines changed

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHEventPayload.java
+55-6Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import com.fasterxml.jackson.annotation.JsonSetter;
55
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
66

7+
import java.io.IOException;
78
import java.io.Reader;
9+
import java.util.Collections;
810
import java.util.List;
911

1012
/**
@@ -275,7 +277,7 @@ public boolean isPrivate() {
275277
public static class Installation extends GHEventPayload {
276278
private String action;
277279
private GHAppInstallation installation;
278-
private List<InstallationRepository> repositories;
280+
private List<GHRepository> repositories;
279281

280282
/**
281283
* Gets action
@@ -300,9 +302,30 @@ public GHAppInstallation getInstallation() {
300302
*
301303
* @return the repositories
302304
*/
303-
public List<InstallationRepository> getRepositories() {
305+
public List<GHRepository> getRepositories() {
304306
return repositories;
305307
};
308+
309+
@Override
310+
void wrapUp(GitHub root) {
311+
super.wrapUp(root);
312+
if (installation == null)
313+
throw new IllegalStateException(
314+
"Expected check_suite payload, but got something else. Maybe we've got another type of event?");
315+
else
316+
installation.wrapUp(root);
317+
318+
if (repositories != null && !repositories.isEmpty()) {
319+
try {
320+
for (GHRepository singleRepo : repositories) { // warp each of the repository
321+
singleRepo.wrap(root);
322+
singleRepo.refresh();
323+
}
324+
} catch (IOException e) {
325+
throw new GHException("Failed to refresh repositories", e);
326+
}
327+
}
328+
}
306329
}
307330

308331
/**
@@ -316,8 +339,8 @@ public static class InstallationRepositories extends GHEventPayload {
316339
private String action;
317340
private GHAppInstallation installation;
318341
private String repositorySelection;
319-
private List<InstallationRepository> repositoriesAdded;
320-
private List<InstallationRepository> repositoriesRemoved;
342+
private List<GHRepository> repositoriesAdded;
343+
private List<GHRepository> repositoriesRemoved;
321344

322345
/**
323346
* Gets action
@@ -351,7 +374,7 @@ public String getRepositorySelection() {
351374
*
352375
* @return the repositories
353376
*/
354-
public List<InstallationRepository> getRepositoriesAdded() {
377+
public List<GHRepository> getRepositoriesAdded() {
355378
return repositoriesAdded;
356379
}
357380

@@ -360,10 +383,36 @@ public List<InstallationRepository> getRepositoriesAdded() {
360383
*
361384
* @return the repositories
362385
*/
363-
public List<InstallationRepository> getRepositoriesRemoved() {
386+
public List<GHRepository> getRepositoriesRemoved() {
364387
return repositoriesRemoved;
365388
}
366389

390+
@Override
391+
void wrapUp(GitHub root) {
392+
super.wrapUp(root);
393+
if (installation == null)
394+
throw new IllegalStateException(
395+
"Expected check_suite payload, but got something else. Maybe we've got another type of event?");
396+
else
397+
installation.wrapUp(root);
398+
399+
List<GHRepository> repositories = Collections.emptyList();
400+
if (action == "added")
401+
repositories = repositoriesAdded;
402+
else
403+
repositories = repositoriesRemoved;
404+
405+
if (repositories != null && !repositories.isEmpty()) {
406+
try {
407+
for (GHRepository singleRepo : repositories) { // warp each of the repository
408+
singleRepo.wrap(root);
409+
singleRepo.refresh();
410+
}
411+
} catch (IOException e) {
412+
throw new GHException("Failed to refresh repositories", e);
413+
}
414+
}
415+
}
367416
}
368417

369418
/**

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,7 @@ public boolean remove(Object url) {
21302130

21312131
GHRepository wrap(GitHub root) {
21322132
this.root = root;
2133-
if (root.isOffline()) {
2133+
if (root.isOffline() && owner != null) {
21342134
owner.wrapUp(root);
21352135
}
21362136
return this;
@@ -2792,4 +2792,17 @@ public GHTagObject createTag(String tag, String message, String object, String t
27922792
.fetch(GHTagObject.class)
27932793
.wrap(this);
27942794
}
2795+
2796+
/**
2797+
* Repopulates this object.
2798+
*
2799+
* @throws java.io.IOException
2800+
* The IO exception
2801+
*/
2802+
public void refresh() throws IOException {
2803+
if (root.isOffline())
2804+
return; // can't populate if the root is offline
2805+
2806+
root.createRequest().withApiUrl(root.getApiUrl() + full_name).fetchInto(this).wrap(root);
2807+
}
27952808
}

‎src/test/java/org/kohsuke/github/GHEventPayloadTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHEventPayloadTest.java
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ public void InstallationRepositoriesEvent() throws Exception {
405405
assertThat(event.getRepositorySelection(), is("selected"));
406406

407407
assertThat(event.getRepositoriesAdded().get(0).getId(), is(186853007L));
408-
assertThat(event.getRepositoriesAdded().get(0).getNodeId(), is("MDEwOlJlcG9zaXRvcnkxODY4NTMwMDc="));
409408
assertThat(event.getRepositoriesAdded().get(0).getName(), is("Space"));
410409
assertThat(event.getRepositoriesAdded().get(0).getFullName(), is("Codertocat/Space"));
411410
assertThat(event.getRepositoriesAdded().get(0).isPrivate(), is(false));
@@ -425,7 +424,6 @@ public void InstallationEvent() throws Exception {
425424
assertThat(event.getInstallation().getAccount().getLogin(), is("octocat"));
426425

427426
assertThat(event.getRepositories().get(0).getId(), is(1296269L));
428-
assertThat(event.getRepositories().get(0).getNodeId(), is("MDEwOlJlcG9zaXRvcnkxODY4NTMwMDc="));
429427
assertThat(event.getRepositories().get(0).getName(), is("Hello-World"));
430428
assertThat(event.getRepositories().get(0).getFullName(), is("octocat/Hello-World"));
431429
assertThat(event.getRepositories().get(0).isPrivate(), is(false));

0 commit comments

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