-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retrieve GitlabHook data in upstream builds if available
- Loading branch information
Showing
5 changed files
with
51 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/com/dabsquared/gitlabjenkins/util/CauseUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.dabsquared.gitlabjenkins.util; | ||
|
||
import hudson.model.Cause; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author Sami Makki | ||
*/ | ||
public class CauseUtil { | ||
|
||
public static <T extends Cause> T findCauseFromUpstreamCauses(List<Cause> causes, Class<T> type) { | ||
for (Cause cause : causes) { | ||
if (type.isInstance(cause)) { | ||
return type.cast(cause); | ||
} | ||
if (cause instanceof Cause.UpstreamCause) { | ||
List<Cause> upCauses = ((Cause.UpstreamCause) cause).getUpstreamCauses(); // Non null, returns empty list when none are set | ||
for (Cause upCause : upCauses) { | ||
if (type.isInstance(upCause)) { | ||
return type.cast(upCause); | ||
} | ||
} | ||
T gitlabCause = findCauseFromUpstreamCauses(upCauses, type); | ||
if (gitlabCause != null) { | ||
return gitlabCause; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters