Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong usage of CauseAction, rename some method. #54

Merged
merged 2 commits into from
Mar 20, 2019
Merged

Fix wrong usage of CauseAction, rename some method. #54

merged 2 commits into from
Mar 20, 2019

Conversation

tianzhipeng-git
Copy link
Contributor

@tianzhipeng-git tianzhipeng-git commented Aug 23, 2018

SInce hudson.model.Run

 public @Nonnull List getCauses() {
        CauseAction a = getAction(CauseAction.class);
        if (a==null)    return Collections.emptyList();
        return Collections.unmodifiableList(a.getCauses());
   }

use just one CauseAction object to get several causes, So adding several CauseAction doesn't work.

@@ -226,12 +226,11 @@ public void parameterizedRebuild(Run currentBuild, StaplerResponse response) thr
if (project == null) {
return;
}
System.out.println("rbx: " + (currentBuild == build));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid System.out. Use logging if text output necessary (but it is?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's my debugging output. Been removed.

@franknarf8
Copy link

This should fix the unit tests :

diff --git a/src/test/java/com/sonyericsson/rebuild/RebuildValidatorTest.java b/src/test/java/com/sonyericsson/rebuild/RebuildValidatorTest.java
index 58d51db..730691a 100644
--- a/src/test/java/com/sonyericsson/rebuild/RebuildValidatorTest.java
+++ b/src/test/java/com/sonyericsson/rebuild/RebuildValidatorTest.java
@@ -47,7 +47,6 @@ import org.jvnet.hudson.test.TestExtension;
 import org.kohsuke.stapler.DataBoundConstructor;
 
 import java.io.IOException;
-import java.util.List;
 import java.util.concurrent.ExecutionException;
 
 /**
@@ -253,25 +252,23 @@ public class RebuildValidatorTest extends HudsonTestCase {
 		while (project.isBuilding()) {
 			Thread.sleep(DELAY);
 		}
-		List<Action> actions = project.getLastCompletedBuild().getActions();
 		boolean hasRebuildCause = false;
 		boolean hasRemoteCause = false;
 		boolean hasUserIdCause = false;
-		for (Action action : actions) {
+		for (Action action : project.getLastCompletedBuild().getAllActions()) {
 			if (action instanceof CauseAction) {
-				CauseAction causeAction = (CauseAction) action;
-				if (causeAction.getCauses().get(0).getClass()
-						.equals(RebuildCause.class)) {
-					hasRebuildCause = true;
-				}
-				if (causeAction.getCauses().get(0).getClass()
-						.equals(Cause.RemoteCause.class)) {
-					hasRemoteCause = true;
-				}
-				if (causeAction.getCauses().get(0).getClass()
-						.equals(Cause.UserIdCause.class)) {
-					hasUserIdCause = true;
+				for(Cause cause : ((CauseAction)action).getCauses()) {
+					if (cause.getClass().equals(RebuildCause.class)) {
+						hasRebuildCause = true;
+					}
+					if (cause.getClass().equals(Cause.RemoteCause.class)) {
+						hasRemoteCause = true;
+					}
+					if (cause.getClass().equals(Cause.UserIdCause.class)) {
+						hasUserIdCause = true;
+					}
 				}
+
 			}
 		}
 		assertTrue("Build should have user, remote and rebuild causes",

@franknarf8
Copy link

@tianzhipeng-git @GLundh ,

Should I fork @tianzhipeng-git 's fork and open another pull request?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants