diff --git a/src/main/java/jenkins/plugins/office365connector/ActionableBuilder.java b/src/main/java/jenkins/plugins/office365connector/ActionableBuilder.java index 57191a7..4934086 100644 --- a/src/main/java/jenkins/plugins/office365connector/ActionableBuilder.java +++ b/src/main/java/jenkins/plugins/office365connector/ActionableBuilder.java @@ -19,7 +19,7 @@ import hudson.model.Job; import hudson.model.Result; import hudson.model.Run; -import jenkins.plugins.office365connector.model.Action; +import jenkins.plugins.office365connector.model.CardAction; import jenkins.plugins.office365connector.model.adaptivecard.AdaptiveCardAction; import jenkins.plugins.office365connector.model.messagecard.PotentialAction; import jenkins.scm.api.SCMHead; @@ -36,7 +36,7 @@ public class ActionableBuilder { private final Run run; private final FactsBuilder factsBuilder; - private final List potentialActions = new ArrayList<>(); + private final List potentialActions = new ArrayList<>(); private final boolean isAdaptiveCards; public ActionableBuilder(Run run, FactsBuilder factsBuilder, boolean isAdaptiveCards) { @@ -45,7 +45,7 @@ public ActionableBuilder(Run run, FactsBuilder factsBuilder, boolean isAdaptiveC this.isAdaptiveCards = isAdaptiveCards; } - public List buildActionable() { + public List buildActionable() { pullRequestActionable(); buildViewBuild(); @@ -80,7 +80,7 @@ private void pullRequestActionable() { ObjectMetadataAction oma = job.getAction(ObjectMetadataAction.class); if (oma != null) { String urlString = oma.getObjectUrl(); - Action viewPRPotentialAction = isAdaptiveCards ? null : new PotentialAction(viewHeader, urlString); + CardAction viewPRPotentialAction = isAdaptiveCards ? new AdaptiveCardAction(viewHeader, urlString) : new PotentialAction(viewHeader, urlString); potentialActions.add(viewPRPotentialAction); factsBuilder.addFact(titleHeader, oma.getObjectDisplayName()); } diff --git a/src/main/java/jenkins/plugins/office365connector/model/Card.java b/src/main/java/jenkins/plugins/office365connector/model/Card.java index d49456c..81fd199 100644 --- a/src/main/java/jenkins/plugins/office365connector/model/Card.java +++ b/src/main/java/jenkins/plugins/office365connector/model/Card.java @@ -6,7 +6,7 @@ public interface Card { public Object toPaylod(); - void setAction(List actions); + void setAction(List actions); void setThemeColor(String cardThemeColor); diff --git a/src/main/java/jenkins/plugins/office365connector/model/Action.java b/src/main/java/jenkins/plugins/office365connector/model/CardAction.java similarity index 64% rename from src/main/java/jenkins/plugins/office365connector/model/Action.java rename to src/main/java/jenkins/plugins/office365connector/model/CardAction.java index 823f3bf..5b90971 100644 --- a/src/main/java/jenkins/plugins/office365connector/model/Action.java +++ b/src/main/java/jenkins/plugins/office365connector/model/CardAction.java @@ -2,11 +2,11 @@ import java.util.List; -public interface Action { +public interface CardAction { void setName(String name); - void setTarget(List target); + void setTargets(List targets); String getName(); } diff --git a/src/main/java/jenkins/plugins/office365connector/model/adaptivecard/AdaptiveCard.java b/src/main/java/jenkins/plugins/office365connector/model/adaptivecard/AdaptiveCard.java index 7796735..afa9994 100644 --- a/src/main/java/jenkins/plugins/office365connector/model/adaptivecard/AdaptiveCard.java +++ b/src/main/java/jenkins/plugins/office365connector/model/adaptivecard/AdaptiveCard.java @@ -6,8 +6,8 @@ import com.google.gson.annotations.SerializedName; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.model.Result; -import jenkins.plugins.office365connector.model.Action; import jenkins.plugins.office365connector.model.Card; +import jenkins.plugins.office365connector.model.CardAction; import jenkins.plugins.office365connector.model.Section; public class AdaptiveCard implements Card { @@ -22,7 +22,7 @@ public class AdaptiveCard implements Card { @SerializedName("msTeams") private final MsTeams msteams = new MsTeams(); private final List body; - private List actions; + private List actions; public AdaptiveCard(final String summary, final Section section, Result result) { this.body = new ArrayList<>(); @@ -69,7 +69,7 @@ public List getBody() { return body; } - public List getActions() { + public List getActions() { return actions; } @@ -79,13 +79,13 @@ public Object toPaylod() { } @Override - public void setAction(final List actions) { + public void setAction(final List actions) { this.actions = actions; } @Override public void setThemeColor(final String cardThemeColor) { - + // intentionally empty, unused with AdaptiveCard format } @Override diff --git a/src/main/java/jenkins/plugins/office365connector/model/adaptivecard/AdaptiveCardAction.java b/src/main/java/jenkins/plugins/office365connector/model/adaptivecard/AdaptiveCardAction.java index 32fd4a1..01651ce 100644 --- a/src/main/java/jenkins/plugins/office365connector/model/adaptivecard/AdaptiveCardAction.java +++ b/src/main/java/jenkins/plugins/office365connector/model/adaptivecard/AdaptiveCardAction.java @@ -2,7 +2,9 @@ import java.util.List; -public class AdaptiveCardAction implements jenkins.plugins.office365connector.model.Action { +import jenkins.plugins.office365connector.model.CardAction; + +public class AdaptiveCardAction implements CardAction { private String type = "Action.OpenUrl"; @@ -45,8 +47,8 @@ public void setName(final String name) { } @Override - public void setTarget(final List target) { - target.stream().findFirst().ifPresent(this::setUrl); + public void setTargets(final List targets) { + targets.stream().findFirst().ifPresent(this::setUrl); } @Override diff --git a/src/main/java/jenkins/plugins/office365connector/model/messagecard/MessageCard.java b/src/main/java/jenkins/plugins/office365connector/model/messagecard/MessageCard.java index baa7d2d..50ae112 100644 --- a/src/main/java/jenkins/plugins/office365connector/model/messagecard/MessageCard.java +++ b/src/main/java/jenkins/plugins/office365connector/model/messagecard/MessageCard.java @@ -17,7 +17,7 @@ import java.util.Arrays; import java.util.List; -import jenkins.plugins.office365connector.model.Action; +import jenkins.plugins.office365connector.model.CardAction; import jenkins.plugins.office365connector.model.Card; import jenkins.plugins.office365connector.model.Section; @@ -32,7 +32,7 @@ public class MessageCard implements Card { // even plugin needs only single 'section' connector API expects arrays private List sections; - private List potentialAction; + private List potentialAction; public MessageCard(String summary, Section section) { this.summary = summary; @@ -55,11 +55,11 @@ public String getThemeColor() { return themeColor; } - public void setAction(List potentialActions) { + public void setAction(List potentialActions) { this.potentialAction = potentialActions; } - public List getAction() { + public List getAction() { return this.potentialAction; } diff --git a/src/main/java/jenkins/plugins/office365connector/model/messagecard/PotentialAction.java b/src/main/java/jenkins/plugins/office365connector/model/messagecard/PotentialAction.java index 4f6ee59..8b4b084 100644 --- a/src/main/java/jenkins/plugins/office365connector/model/messagecard/PotentialAction.java +++ b/src/main/java/jenkins/plugins/office365connector/model/messagecard/PotentialAction.java @@ -17,12 +17,12 @@ import com.google.gson.annotations.SerializedName; import hudson.Util; -import jenkins.plugins.office365connector.model.Action; +import jenkins.plugins.office365connector.model.CardAction; /** * @author srhebbar */ -public class PotentialAction implements Action { +public class PotentialAction implements CardAction { @SerializedName("@context") private String context = "http://schema.org"; @@ -58,8 +58,8 @@ public List getTarget() { } @Override - public void setTarget(List target) { - this.target = target; + public void setTargets(List targets) { + this.target = targets; } public String getContext() { diff --git a/src/test/java/jenkins/plugins/office365connector/ActionablePotentialActionBuilderTest.java b/src/test/java/jenkins/plugins/office365connector/ActionablePotentialActionBuilderTest.java index eb8cd93..5ae851e 100644 --- a/src/test/java/jenkins/plugins/office365connector/ActionablePotentialActionBuilderTest.java +++ b/src/test/java/jenkins/plugins/office365connector/ActionablePotentialActionBuilderTest.java @@ -11,7 +11,7 @@ import hudson.model.AbstractProject; import hudson.model.TaskListener; import jenkins.plugins.office365connector.helpers.SCMHeadBuilder; -import jenkins.plugins.office365connector.model.Action; +import jenkins.plugins.office365connector.model.CardAction; import jenkins.scm.api.SCMHead; import jenkins.scm.api.metadata.ContributorMetadataAction; import jenkins.scm.api.metadata.ObjectMetadataAction; @@ -64,11 +64,11 @@ public void buildActionable_OnEmptyAction_ReturnsEmptyList() { // from @Before // when - List potentialActions = actionableBuilder.buildActionable(); + List potentialActions = actionableBuilder.buildActionable(); // then assertThat(potentialActions).hasSize(1); - Action potentialAction = potentialActions.get(0); + CardAction potentialAction = potentialActions.get(0); assertThat(potentialAction.getName()).isEqualTo("View Build"); } @@ -133,7 +133,7 @@ public void pullRequestActionable_OnContributorMetadataAction_AddsFact() throws // then assertThat(factsBuilder.collect()).hasSize(1); - List potentialActions = FieldReflection.getFieldValue(actionableBuilder.getClass().getDeclaredField("potentialActions"), actionableBuilder); + List potentialActions = FieldReflection.getFieldValue(actionableBuilder.getClass().getDeclaredField("potentialActions"), actionableBuilder); assertThat(potentialActions).hasSize(1); } @@ -164,7 +164,7 @@ public void pullRequestActionable_OnObjectMetadataAction_DoesNotAddFact() throws // then assertThat(factsBuilder.collect()).hasSize(1); - List potentialActions = FieldReflection.getFieldValue(actionableBuilder.getClass().getDeclaredField("potentialActions"), actionableBuilder); + List potentialActions = FieldReflection.getFieldValue(actionableBuilder.getClass().getDeclaredField("potentialActions"), actionableBuilder); assertThat(potentialActions).isEmpty(); } diff --git a/src/test/java/jenkins/plugins/office365connector/model/messagecard/PotentialActionTest.java b/src/test/java/jenkins/plugins/office365connector/model/messagecard/PotentialActionTest.java index f13cb66..c656807 100644 --- a/src/test/java/jenkins/plugins/office365connector/model/messagecard/PotentialActionTest.java +++ b/src/test/java/jenkins/plugins/office365connector/model/messagecard/PotentialActionTest.java @@ -48,7 +48,7 @@ public void getTarget_ReturnsTarget() { PotentialAction potentialAction = new PotentialAction("name", "url"); // then - potentialAction.setTarget(target); + potentialAction.setTargets(target); // then assertThat(potentialAction.getTarget()).isEqualTo(target);