Skip to content

Commit

Permalink
some review comments fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
markush81 authored and damianszczepanik committed Oct 9, 2024
1 parent 91a1db8 commit 8b09210
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,7 +36,7 @@ public class ActionableBuilder {

private final Run run;
private final FactsBuilder factsBuilder;
private final List<Action> potentialActions = new ArrayList<>();
private final List<CardAction> potentialActions = new ArrayList<>();
private final boolean isAdaptiveCards;

public ActionableBuilder(Run run, FactsBuilder factsBuilder, boolean isAdaptiveCards) {
Expand All @@ -45,7 +45,7 @@ public ActionableBuilder(Run run, FactsBuilder factsBuilder, boolean isAdaptiveC
this.isAdaptiveCards = isAdaptiveCards;
}

public List<Action> buildActionable() {
public List<CardAction> buildActionable() {

pullRequestActionable();
buildViewBuild();
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public interface Card {

public Object toPaylod();

void setAction(List<Action> actions);
void setAction(List<CardAction> actions);

void setThemeColor(String cardThemeColor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import java.util.List;

public interface Action {
public interface CardAction {

void setName(String name);

void setTarget(List<String> target);
void setTargets(List<String> targets);

String getName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -22,7 +22,7 @@ public class AdaptiveCard implements Card {
@SerializedName("msTeams")
private final MsTeams msteams = new MsTeams();
private final List<AdaptiveCardElement> body;
private List<Action> actions;
private List<CardAction> actions;

public AdaptiveCard(final String summary, final Section section, Result result) {
this.body = new ArrayList<>();
Expand Down Expand Up @@ -69,7 +69,7 @@ public List<AdaptiveCardElement> getBody() {
return body;
}

public List<Action> getActions() {
public List<CardAction> getActions() {
return actions;
}

Expand All @@ -79,13 +79,13 @@ public Object toPaylod() {
}

@Override
public void setAction(final List<Action> actions) {
public void setAction(final List<CardAction> actions) {
this.actions = actions;
}

@Override
public void setThemeColor(final String cardThemeColor) {

// intentionally empty, unused with AdaptiveCard format
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -45,8 +47,8 @@ public void setName(final String name) {
}

@Override
public void setTarget(final List<String> target) {
target.stream().findFirst().ifPresent(this::setUrl);
public void setTargets(final List<String> targets) {
targets.stream().findFirst().ifPresent(this::setUrl);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -32,7 +32,7 @@ public class MessageCard implements Card {
// even plugin needs only single 'section' connector API expects arrays
private List<jenkins.plugins.office365connector.model.Section> sections;

private List<Action> potentialAction;
private List<CardAction> potentialAction;

public MessageCard(String summary, Section section) {
this.summary = summary;
Expand All @@ -55,11 +55,11 @@ public String getThemeColor() {
return themeColor;
}

public void setAction(List<Action> potentialActions) {
public void setAction(List<CardAction> potentialActions) {
this.potentialAction = potentialActions;
}

public List<Action> getAction() {
public List<CardAction> getAction() {
return this.potentialAction;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -58,8 +58,8 @@ public List<String> getTarget() {
}

@Override
public void setTarget(List<String> target) {
this.target = target;
public void setTargets(List<String> targets) {
this.target = targets;
}

public String getContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,11 +64,11 @@ public void buildActionable_OnEmptyAction_ReturnsEmptyList() {
// from @Before

// when
List<Action> potentialActions = actionableBuilder.buildActionable();
List<CardAction> potentialActions = actionableBuilder.buildActionable();

// then
assertThat(potentialActions).hasSize(1);
Action potentialAction = potentialActions.get(0);
CardAction potentialAction = potentialActions.get(0);
assertThat(potentialAction.getName()).isEqualTo("View Build");
}

Expand Down Expand Up @@ -133,7 +133,7 @@ public void pullRequestActionable_OnContributorMetadataAction_AddsFact() throws
// then
assertThat(factsBuilder.collect()).hasSize(1);

List<Action> potentialActions = FieldReflection.getFieldValue(actionableBuilder.getClass().getDeclaredField("potentialActions"), actionableBuilder);
List<CardAction> potentialActions = FieldReflection.getFieldValue(actionableBuilder.getClass().getDeclaredField("potentialActions"), actionableBuilder);
assertThat(potentialActions).hasSize(1);
}

Expand Down Expand Up @@ -164,7 +164,7 @@ public void pullRequestActionable_OnObjectMetadataAction_DoesNotAddFact() throws
// then
assertThat(factsBuilder.collect()).hasSize(1);

List<Action> potentialActions = FieldReflection.getFieldValue(actionableBuilder.getClass().getDeclaredField("potentialActions"), actionableBuilder);
List<CardAction> potentialActions = FieldReflection.getFieldValue(actionableBuilder.getClass().getDeclaredField("potentialActions"), actionableBuilder);
assertThat(potentialActions).isEmpty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8b09210

Please sign in to comment.