Skip to content

Commit 8747cbe

Browse files
proskijakub-bochenski
authored andcommitted
Remove StashBuilds#getCause(), call build.getCause() directly
The "build" argument in onStarted() and onCompleted() is not of a raw type anymore, which enables type-safe behavior without casts. build.getCause() returns a value of the type provided in its argument. If cause is null or there is no cause of the given type, build.getCause() returns null. That is the desired behavior. No extra wrapper is required.
1 parent cf25c4f commit 8747cbe

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

src/main/java/stashpullrequestbuilder/stashpullrequestbuilder/StashBuilds.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import hudson.Util;
44
import hudson.model.AbstractBuild;
5-
import hudson.model.Cause;
65
import hudson.model.Result;
76
import hudson.model.TaskListener;
87
import java.io.IOException;
@@ -23,16 +22,8 @@ public StashBuilds(StashBuildTrigger trigger, StashRepository repository) {
2322
this.repository = repository;
2423
}
2524

26-
public StashCause getCause(AbstractBuild build) {
27-
Cause cause = build.getCause(StashCause.class);
28-
if (cause == null || !(cause instanceof StashCause)) {
29-
return null;
30-
}
31-
return (StashCause) cause;
32-
}
33-
3425
public void onStarted(AbstractBuild<?, ?> build) {
35-
StashCause cause = this.getCause(build);
26+
StashCause cause = build.getCause(StashCause.class);
3627
if (cause == null) {
3728
return;
3829
}
@@ -44,7 +35,7 @@ public void onStarted(AbstractBuild<?, ?> build) {
4435
}
4536

4637
public void onCompleted(AbstractBuild<?, ?> build, TaskListener listener) {
47-
StashCause cause = this.getCause(build);
38+
StashCause cause = build.getCause(StashCause.class);
4839
if (cause == null) {
4940
return;
5041
}

0 commit comments

Comments
 (0)