11package org .jenkinsci .plugins .github .util ;
22
3+ import hudson .model .Action ;
34import hudson .model .Job ;
45import hudson .model .Run ;
56import hudson .plugins .git .Revision ;
67import hudson .plugins .git .util .Build ;
78import hudson .plugins .git .util .BuildData ;
9+ import hudson .plugins .git .util .BuildDetails ;
810import org .eclipse .jgit .lib .ObjectId ;
911
1012import javax .annotation .Nonnull ;
1113import java .io .IOException ;
14+ import java .util .ArrayList ;
1215import java .util .List ;
1316import java .util .Set ;
1417
18+ import org .slf4j .Logger ;
19+ import org .slf4j .LoggerFactory ;
20+
1521/**
1622 * Stores common methods for {@link BuildData} handling.
1723 *
1824 * @author Oleg Nenashev <o.v.nenashev@gmail.com>
1925 * @since 1.10
2026 */
2127public final class BuildDataHelper {
28+ private static final Logger LOGGER = LoggerFactory .getLogger (BuildDataHelper .class );
29+
2230 private BuildDataHelper () {
2331 }
2432
@@ -34,30 +42,40 @@ private BuildDataHelper() {
3442 * @param buildDataList the list of build datas from a build run
3543 * @return the build data related to the project, null if not found
3644 */
37- public static BuildData calculateBuildData (
38- String parentName , String parentFullName , List <BuildData > buildDataList
45+ public static Action calculateBuildDataOrDetails (
46+ String parentName , String parentFullName , List <Action > buildDataOrDetailsList
3947 ) {
48+ LOGGER .debug ("Name of parent build: {}" , parentName );
49+ LOGGER .debug ("Name of parent full build: {}" , parentFullName );
4050
41- if (buildDataList == null ) {
51+ if (buildDataOrDetailsList == null ) {
4252 return null ;
4353 }
4454
45- if (buildDataList .size () == 1 ) {
46- return buildDataList .get (0 );
55+ if (buildDataOrDetailsList .size () == 1 ) {
56+ return buildDataOrDetailsList .get (0 );
4757 }
4858
4959 String projectName = parentFullName .replace (parentName , "" );
5060
61+ LOGGER .debug ("Project name: {}" , projectName );
62+
5163 if (projectName .endsWith ("/" )) {
5264 projectName = projectName .substring (0 , projectName .lastIndexOf ('/' ));
5365 }
5466
55- for (BuildData buildData : buildDataList ) {
56- Set <String > remoteUrls = buildData .getRemoteUrls ();
67+ LOGGER .debug ("Project name: {}" , projectName );
68+
69+ for (Action buildDataOrDetails : buildDataOrDetailsList ) {
70+ Set <String > remoteUrls = buildDataOrDetails instanceof BuildData
71+ ? ((BuildData ) buildDataOrDetails ).getRemoteUrls ()
72+ : ((BuildDetails ) buildDataOrDetails ).getRemoteUrls ();
5773
5874 for (String remoteUrl : remoteUrls ) {
75+
76+ LOGGER .debug ("Remote URL: {}" , remoteUrl );
5977 if (remoteUrl .contains (projectName )) {
60- return buildData ;
78+ return buildDataOrDetails ;
6179 }
6280 }
6381 }
@@ -76,19 +94,38 @@ public static BuildData calculateBuildData(
7694 @ Nonnull
7795 public static ObjectId getCommitSHA1 (@ Nonnull Run <?, ?> build ) throws IOException {
7896 List <BuildData > buildDataList = build .getActions (BuildData .class );
97+ List <BuildDetails > buildDetailsList = build .getActions (BuildDetails .class );
98+
99+ //
100+ List <Action > buildDataOrDetailsList = new ArrayList <Action >();
101+ buildDataOrDetailsList .addAll (buildDataList );
102+ buildDataOrDetailsList .addAll (buildDetailsList );
103+
104+ /*
105+ List<Action> actions = build.getActions();
106+ for (Action action : actions) {
107+ LOGGER.debug(
108+ "Action, class: {}, displayName: {}, urlName: {}",
109+ action.getClass().getName(),
110+ action.getDisplayName(),
111+ action.getUrlName()
112+ );
113+ }
114+ */
79115
80116 Job <?, ?> parent = build .getParent ();
81117
82- BuildData buildData = calculateBuildData (
83- parent .getName (), parent .getFullName (), buildDataList
118+ Action buildDataOrDetails = calculateBuildDataOrDetails (
119+ parent .getName (), parent .getFullName (), buildDataOrDetailsList
84120 );
85121
86- if (buildData == null ) {
122+ if (buildDataOrDetails == null ) {
87123 throw new IOException (Messages .BuildDataHelper_NoBuildDataError ());
88124 }
89125
90126 // buildData?.lastBuild?.marked and fall back to .revision with null check everywhere to be defensive
91- Build b = buildData .lastBuild ;
127+ Build b = buildDataOrDetails instanceof BuildData
128+ ? ((BuildData ) buildDataOrDetails ).lastBuild : ((BuildDetails ) buildDataOrDetails ).getBuild ();
92129 if (b != null ) {
93130 Revision r = b .marked ;
94131 if (r == null ) {
0 commit comments