Skip to content

Commit b51d655

Browse files
committed
#947 address review comments
1 parent 74496d3 commit b51d655

File tree

2 files changed

+30
-73
lines changed

2 files changed

+30
-73
lines changed

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

Lines changed: 24 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ public class GHEventPayload {
2424
// Webhook payload object common properties: action, sender, repository, organization, installation
2525
private String action;
2626
private GHUser sender;
27-
GHRepository repository;
27+
private GHRepository repository;
2828
private GHOrganization organization;
29-
GHAppInstallation installation;
29+
private GHAppInstallation installation;
3030

3131
GHEventPayload() {
3232
}
3333

3434
/**
35-
* Most webhook payloads contain an action property that contains the specific activity that triggered the event.
35+
* Gets the action for the triggered event. Most but not all webhook payloads contain an action property that
36+
* contains the specific activity that triggered the event.
3637
*
3738
* @return event action
3839
*/
@@ -112,11 +113,14 @@ void wrapUp(GitHub root) {
112113
sender.wrapUp(root);
113114
}
114115
if (repository != null) {
115-
repository.root = root;
116+
repository.wrap(root);
116117
}
117118
if (organization != null) {
118119
organization.wrapUp(root);
119120
}
121+
if (installation != null) {
122+
installation.wrapUp(root);
123+
}
120124
}
121125

122126
// List of events that still need to be added:
@@ -192,8 +196,8 @@ void wrapUp(GitHub root) {
192196
if (checkRun == null)
193197
throw new IllegalStateException(
194198
"Expected check_run payload, but got something else. Maybe we've got another type of event?");
199+
GHRepository repository = getRepository();
195200
if (repository != null) {
196-
repository.wrap(root);
197201
checkRun.wrap(repository);
198202
} else {
199203
checkRun.wrap(root);
@@ -226,8 +230,8 @@ void wrapUp(GitHub root) {
226230
if (checkSuite == null)
227231
throw new IllegalStateException(
228232
"Expected check_suite payload, but got something else. Maybe we've got another type of event?");
233+
GHRepository repository = getRepository();
229234
if (repository != null) {
230-
repository.wrap(root);
231235
checkSuite.wrap(repository);
232236
} else {
233237
checkSuite.wrap(root);
@@ -258,11 +262,10 @@ public List<GHRepository> getRepositories() {
258262
@Override
259263
void wrapUp(GitHub root) {
260264
super.wrapUp(root);
261-
if (installation == null)
265+
if (getInstallation() == null) {
262266
throw new IllegalStateException(
263267
"Expected check_suite payload, but got something else. Maybe we've got another type of event?");
264-
else
265-
installation.wrapUp(root);
268+
}
266269

267270
if (repositories != null && !repositories.isEmpty()) {
268271
try {
@@ -320,11 +323,10 @@ public List<GHRepository> getRepositoriesRemoved() {
320323
@Override
321324
void wrapUp(GitHub root) {
322325
super.wrapUp(root);
323-
if (installation == null)
326+
if (getInstallation() == null) {
324327
throw new IllegalStateException(
325328
"Expected check_suite payload, but got something else. Maybe we've got another type of event?");
326-
else
327-
installation.wrapUp(root);
329+
}
328330

329331
List<GHRepository> repositories;
330332
if ("added".equals(getAction()))
@@ -393,8 +395,8 @@ void wrapUp(GitHub root) {
393395
if (pullRequest == null)
394396
throw new IllegalStateException(
395397
"Expected pull_request payload, but got something else. Maybe we've got another type of event?");
398+
GHRepository repository = getRepository();
396399
if (repository != null) {
397-
repository.wrap(root);
398400
pullRequest.wrapUp(repository);
399401
} else {
400402
pullRequest.wrapUp(root);
@@ -441,8 +443,8 @@ void wrapUp(GitHub root) {
441443

442444
review.wrapUp(pullRequest);
443445

446+
GHRepository repository = getRepository();
444447
if (repository != null) {
445-
repository.wrap(root);
446448
pullRequest.wrapUp(repository);
447449
} else {
448450
pullRequest.wrapUp(root);
@@ -489,8 +491,8 @@ void wrapUp(GitHub root) {
489491

490492
comment.wrapUp(pullRequest);
491493

494+
GHRepository repository = getRepository();
492495
if (repository != null) {
493-
repository.wrap(root);
494496
pullRequest.wrapUp(repository);
495497
} else {
496498
pullRequest.wrapUp(root);
@@ -531,8 +533,8 @@ public void setIssue(GHIssue issue) {
531533
@Override
532534
void wrapUp(GitHub root) {
533535
super.wrapUp(root);
536+
GHRepository repository = getRepository();
534537
if (repository != null) {
535-
repository.wrap(root);
536538
issue.wrap(repository);
537539
} else {
538540
issue.wrap(root);
@@ -593,8 +595,8 @@ public void setIssue(GHIssue issue) {
593595
@Override
594596
void wrapUp(GitHub root) {
595597
super.wrapUp(root);
598+
GHRepository repository = getRepository();
596599
if (repository != null) {
597-
repository.wrap(root);
598600
issue.wrap(repository);
599601
} else {
600602
issue.wrap(root);
@@ -636,8 +638,8 @@ public void setComment(GHCommitComment comment) {
636638
@Override
637639
void wrapUp(GitHub root) {
638640
super.wrapUp(root);
641+
GHRepository repository = getRepository();
639642
if (repository != null) {
640-
repository.wrap(root);
641643
comment.wrap(repository);
642644
}
643645
}
@@ -695,14 +697,6 @@ public String getMasterBranch() {
695697
public String getDescription() {
696698
return description;
697699
}
698-
699-
@Override
700-
void wrapUp(GitHub root) {
701-
super.wrapUp(root);
702-
if (repository != null) {
703-
repository.wrap(root);
704-
}
705-
}
706700
}
707701

708702
/**
@@ -735,14 +729,6 @@ public String getRef() {
735729
public String getRefType() {
736730
return refType;
737731
}
738-
739-
@Override
740-
void wrapUp(GitHub root) {
741-
super.wrapUp(root);
742-
if (repository != null) {
743-
repository.wrap(root);
744-
}
745-
}
746732
}
747733

748734
/**
@@ -777,8 +763,8 @@ public void setDeployment(GHDeployment deployment) {
777763
@Override
778764
void wrapUp(GitHub root) {
779765
super.wrapUp(root);
766+
GHRepository repository = getRepository();
780767
if (repository != null) {
781-
repository.wrap(root);
782768
deployment.wrap(repository);
783769
}
784770
}
@@ -837,8 +823,8 @@ public void setDeployment(GHDeployment deployment) {
837823
@Override
838824
void wrapUp(GitHub root) {
839825
super.wrapUp(root);
826+
GHRepository repository = getRepository();
840827
if (repository != null) {
841-
repository.wrap(root);
842828
deployment.wrap(repository);
843829
deploymentStatus.wrap(repository);
844830
}
@@ -878,9 +864,6 @@ public void setForkee(GHRepository forkee) {
878864
void wrapUp(GitHub root) {
879865
super.wrapUp(root);
880866
forkee.wrap(root);
881-
if (repository != null) {
882-
repository.wrap(root);
883-
}
884867
}
885868
}
886869

@@ -891,12 +874,6 @@ void wrapUp(GitHub root) {
891874
* event</a>
892875
*/
893876
public static class Ping extends GHEventPayload {
894-
@Override
895-
void wrapUp(GitHub root) {
896-
super.wrapUp(root);
897-
if (repository != null)
898-
repository.wrap(root);
899-
}
900877

901878
}
902879

@@ -908,13 +885,6 @@ void wrapUp(GitHub root) {
908885
*/
909886
public static class Public extends GHEventPayload {
910887

911-
@Override
912-
void wrapUp(GitHub root) {
913-
super.wrapUp(root);
914-
if (repository != null)
915-
repository.wrap(root);
916-
}
917-
918888
}
919889

920890
/**
@@ -1038,13 +1008,6 @@ public String getCompare() {
10381008
return compare;
10391009
}
10401010

1041-
@Override
1042-
void wrapUp(GitHub root) {
1043-
super.wrapUp(root);
1044-
if (repository != null)
1045-
repository.wrap(root);
1046-
}
1047-
10481011
/**
10491012
* The type Pusher.
10501013
*/
@@ -1218,14 +1181,6 @@ public GHRelease getRelease() {
12181181
public void setRelease(GHRelease release) {
12191182
this.release = release;
12201183
}
1221-
1222-
@Override
1223-
void wrapUp(GitHub root) {
1224-
super.wrapUp(root);
1225-
if (repository != null) {
1226-
repository.wrap(root);
1227-
}
1228-
}
12291184
}
12301185

12311186
/**
@@ -1236,11 +1191,7 @@ void wrapUp(GitHub root) {
12361191
* @see <a href="https://docs.github.com/en/rest/reference/repos">Repositories</a>
12371192
*/
12381193
public static class Repository extends GHEventPayload {
1239-
@Override
1240-
void wrapUp(GitHub root) {
1241-
super.wrapUp(root);
1242-
repository.wrap(root);
1243-
}
1194+
12441195
}
12451196

12461197
/**
@@ -1319,8 +1270,8 @@ void wrapUp(GitHub root) {
13191270
throw new IllegalStateException(
13201271
"Expected status payload, but got something else. Maybe we've got another type of event?");
13211272
}
1273+
GHRepository repository = getRepository();
13221274
if (repository != null) {
1323-
repository.wrap(root);
13241275
commit.wrapUp(repository);
13251276
}
13261277
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,13 @@ public void release_published() throws Exception {
413413
.parseEventPayload(payload.asReader(), GHEventPayload.Release.class);
414414

415415
assertThat(event.getAction(), is("published"));
416+
assertThat(event.getSender().getLogin(), is("seregamorph"));
416417
assertThat(event.getRepository().getName(), is("company-rest-api-framework"));
418+
assertThat(event.getOrganization().getLogin(), is("company-group"));
419+
assertThat(event.getInstallation(), nullValue());
420+
assertThat(event.getRelease().getName(), is("4.2"));
421+
assertThat(event.getRelease().getTagName(), is("rest-api-framework-4.2"));
422+
assertThat(event.getRelease().getBody(), is("REST-269 - unique test executions (#86) Sergey Chernov"));
417423
}
418424

419425
@Test

0 commit comments

Comments
 (0)