Skip to content

Commit

Permalink
some review comments fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
markush81 committed Aug 5, 2024
1 parent 0723040 commit f366899
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 23 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);

Check warning on line 83 in src/main/java/jenkins/plugins/office365connector/ActionableBuilder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 83 is only partially covered, one branch is missing
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,7 +2,7 @@

import java.util.List;

public interface Action {
public interface CardAction {

void setName(String name);

Expand Down
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
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
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

0 comments on commit f366899

Please sign in to comment.