forked from jenkinsci/github-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update plugin for git-plugin 4.0.0-rc
- Loading branch information
Baptiste Gaillard
committed
Jun 11, 2019
1 parent
4e05b9a
commit d04d8b5
Showing
2 changed files
with
54 additions
and
17 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
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 |
---|---|---|
@@ -1,24 +1,32 @@ | ||
package org.jenkinsci.plugins.github.util; | ||
|
||
import hudson.model.Action; | ||
import hudson.model.Job; | ||
import hudson.model.Run; | ||
import hudson.plugins.git.Revision; | ||
import hudson.plugins.git.util.Build; | ||
import hudson.plugins.git.util.BuildData; | ||
import hudson.plugins.git.util.BuildDetails; | ||
import org.eclipse.jgit.lib.ObjectId; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Stores common methods for {@link BuildData} handling. | ||
* | ||
* @author Oleg Nenashev <[email protected]> | ||
* @since 1.10 | ||
*/ | ||
public final class BuildDataHelper { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(BuildDataHelper.class); | ||
|
||
private BuildDataHelper() { | ||
} | ||
|
||
|
@@ -34,30 +42,40 @@ private BuildDataHelper() { | |
* @param buildDataList the list of build datas from a build run | ||
* @return the build data related to the project, null if not found | ||
*/ | ||
public static BuildData calculateBuildData( | ||
String parentName, String parentFullName, List<BuildData> buildDataList | ||
public static Action calculateBuildDataOrDetails( | ||
String parentName, String parentFullName, List<Action> buildDataOrDetailsList | ||
) { | ||
LOGGER.debug("Name of parent build: {}", parentName); | ||
LOGGER.debug("Name of parent full build: {}", parentFullName); | ||
|
||
if (buildDataList == null) { | ||
if (buildDataOrDetailsList == null) { | ||
return null; | ||
} | ||
|
||
if (buildDataList.size() == 1) { | ||
return buildDataList.get(0); | ||
if (buildDataOrDetailsList.size() == 1) { | ||
return buildDataOrDetailsList.get(0); | ||
} | ||
|
||
String projectName = parentFullName.replace(parentName, ""); | ||
|
||
LOGGER.debug("Project name: {}", projectName); | ||
|
||
if (projectName.endsWith("/")) { | ||
projectName = projectName.substring(0, projectName.lastIndexOf('/')); | ||
} | ||
|
||
for (BuildData buildData : buildDataList) { | ||
Set<String> remoteUrls = buildData.getRemoteUrls(); | ||
LOGGER.debug("Project name: {}", projectName); | ||
|
||
for (Action buildDataOrDetails : buildDataOrDetailsList) { | ||
Set<String> remoteUrls = buildDataOrDetails instanceof BuildData | ||
? ((BuildData) buildDataOrDetails).getRemoteUrls() | ||
: ((BuildDetails) buildDataOrDetails).getRemoteUrls(); | ||
|
||
for (String remoteUrl : remoteUrls) { | ||
|
||
LOGGER.debug("Remote URL: {}", remoteUrl); | ||
if (remoteUrl.contains(projectName)) { | ||
return buildData; | ||
return buildDataOrDetails; | ||
} | ||
} | ||
} | ||
|
@@ -76,19 +94,38 @@ public static BuildData calculateBuildData( | |
@Nonnull | ||
public static ObjectId getCommitSHA1(@Nonnull Run<?, ?> build) throws IOException { | ||
List<BuildData> buildDataList = build.getActions(BuildData.class); | ||
List<BuildDetails> buildDetailsList = build.getActions(BuildDetails.class); | ||
|
||
// | ||
List<Action> buildDataOrDetailsList = new ArrayList<Action>(); | ||
buildDataOrDetailsList.addAll(buildDataList); | ||
buildDataOrDetailsList.addAll(buildDetailsList); | ||
|
||
/* | ||
List<Action> actions = build.getActions(); | ||
for (Action action : actions) { | ||
LOGGER.debug( | ||
"Action, class: {}, displayName: {}, urlName: {}", | ||
action.getClass().getName(), | ||
action.getDisplayName(), | ||
action.getUrlName() | ||
); | ||
} | ||
*/ | ||
|
||
Job<?, ?> parent = build.getParent(); | ||
|
||
BuildData buildData = calculateBuildData( | ||
parent.getName(), parent.getFullName(), buildDataList | ||
Action buildDataOrDetails = calculateBuildDataOrDetails( | ||
parent.getName(), parent.getFullName(), buildDataOrDetailsList | ||
); | ||
|
||
if (buildData == null) { | ||
if (buildDataOrDetails == null) { | ||
throw new IOException(Messages.BuildDataHelper_NoBuildDataError()); | ||
} | ||
|
||
// buildData?.lastBuild?.marked and fall back to .revision with null check everywhere to be defensive | ||
Build b = buildData.lastBuild; | ||
Build b = buildDataOrDetails instanceof BuildData | ||
? ((BuildData) buildDataOrDetails).lastBuild : ((BuildDetails) buildDataOrDetails).getBuild(); | ||
if (b != null) { | ||
Revision r = b.marked; | ||
if (r == null) { | ||
|
d04d8b5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bgaillard be great to get this into the main ASAP
d04d8b5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Narimm thanks, the PR is now published here jenkinsci#216. Do not hesitate to add a thumb up to promote it :-)