Skip to content

Commit d04d8b5

Browse files
author
Baptiste Gaillard
committed
Update plugin for git-plugin 4.0.0-rc
1 parent 4e05b9a commit d04d8b5

File tree

2 files changed

+54
-17
lines changed

2 files changed

+54
-17
lines changed

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>com.coravy.hudson.plugins.github</groupId>
1313
<artifactId>github</artifactId>
14-
<version>1.29.5-SNAPSHOT</version>
14+
<version>1.30.0-SNAPSHOT</version>
1515
<packaging>hpi</packaging>
1616

1717
<name>GitHub plugin</name>
@@ -62,7 +62,7 @@
6262
<url>https://repo.jenkins-ci.org/public/</url>
6363
</repository>
6464
</repositories>
65-
65+
6666
<pluginRepositories>
6767
<pluginRepository>
6868
<id>repo.jenkins-ci.org</id>
@@ -99,13 +99,13 @@
9999
<dependency>
100100
<groupId>org.jenkins-ci.plugins</groupId>
101101
<artifactId>git</artifactId>
102-
<version>3.4.0</version>
102+
<version>4.0.0-rc</version>
103103
</dependency>
104104

105105
<dependency>
106106
<groupId>org.jenkins-ci.plugins</groupId>
107107
<artifactId>scm-api</artifactId>
108-
<version>2.2.0</version>
108+
<version>2.3.0</version>
109109
</dependency>
110110

111111
<dependency>
@@ -157,7 +157,7 @@
157157
<dependency>
158158
<groupId>org.jenkins-ci.plugins</groupId>
159159
<artifactId>apache-httpcomponents-client-4-api</artifactId>
160-
<version>4.5.3-2.1</version>
160+
<version>4.5.5-3.0</version>
161161
<scope>test</scope>
162162
</dependency>
163163

src/main/java/org/jenkinsci/plugins/github/util/BuildDataHelper.java

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
package org.jenkinsci.plugins.github.util;
22

3+
import hudson.model.Action;
34
import hudson.model.Job;
45
import hudson.model.Run;
56
import hudson.plugins.git.Revision;
67
import hudson.plugins.git.util.Build;
78
import hudson.plugins.git.util.BuildData;
9+
import hudson.plugins.git.util.BuildDetails;
810
import org.eclipse.jgit.lib.ObjectId;
911

1012
import javax.annotation.Nonnull;
1113
import java.io.IOException;
14+
import java.util.ArrayList;
1215
import java.util.List;
1316
import 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
*/
2127
public 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

Comments
 (0)