Skip to content

Commit

Permalink
"View build" button is not displayed for successful builds (#272)
Browse files Browse the repository at this point in the history
Issue #258
  • Loading branch information
damianszczepanik authored May 14, 2022
1 parent baaf6ac commit 17658ee
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.List;

import hudson.model.Job;
import hudson.model.Result;
import hudson.model.Run;
import jenkins.plugins.office365connector.model.PotentialAction;
import jenkins.scm.api.SCMHead;
Expand Down Expand Up @@ -51,9 +52,12 @@ public List<PotentialAction> buildActionable() {
private void buildViewBuild() {
String urlToJob = DisplayURLProvider.get().getRunURL(run);
String build = Messages.Office365ConnectorWebhookNotifier_BuildPronoun();
String viewHeader = Messages.Office365ConnectorWebhookNotifier_ViewHeader(build);

potentialActions.add(new PotentialAction(viewHeader, urlToJob));
// hide action button when the build succeed
if (run.getResult() != Result.SUCCESS) {
String viewHeader = Messages.Office365ConnectorWebhookNotifier_ViewHeader(build);
potentialActions.add(new PotentialAction(viewHeader, urlToJob));
}
}

// support for pull requests such as https://github.com/jenkinsci/github-branch-source-plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public Card createCompletedCard(List<FactDefinition> factDefinitions) {

Card card = new Card(summary, section);
card.setThemeColor(getCardThemeColor(lastResult));
card.setPotentialAction(potentialActionBuilder.buildActionable());
if (run.getResult() != Result.SUCCESS) {
card.setPotentialAction(potentialActionBuilder.buildActionable());
}

return card;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,21 @@ private void mockPullRequest() {
}

@Test
public void validateBackToNormalRequest_WithPullRequest() {
public void validateRepeatedFailure_WithPullRequest() {

// given
mockResult(Result.FAILURE);
Office365ConnectorWebhookNotifier notifier = new Office365ConnectorWebhookNotifier(run, mockListener());

// when
notifier.sendBuildCompletedNotification();

// then
assertHasSameContent(workerAnswer.getData(), FileUtils.getContentFile("repeated_failure-pull_request.json"));
}

@Test
public void validateBackToNormal_WithoutActions() {

// given
mockResult(Result.SUCCESS);
Expand All @@ -130,6 +144,6 @@ public void validateBackToNormalRequest_WithPullRequest() {
notifier.sendBuildCompletedNotification();

// then
assertHasSameContent(workerAnswer.getData(), FileUtils.getContentFile("back_to_normal-pull_request.json"));
assertHasSameContent(workerAnswer.getData(), FileUtils.getContentFile("back_to_normal-without_actions.json"));
}
}
29 changes: 29 additions & 0 deletions src/test/resources/requests/back_to_normal-without_actions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"summary": "Damian Szczepanik » hook » PR-1: Build #3 Back to Normal",
"themeColor": "#00FF00",
"sections": [
{
"markdown": true,
"facts": [
{
"name": "Status",
"value": "Back to Normal"
},
{
"name": "Remarks",
"value": "Branch indexing."
},
{
"name": "Committers",
"value": "damian"
},
{
"name": "Developers",
"value": "damian"
}
],
"activityTitle": "Notification from Damian Szczepanik » hook » PR\\-1",
"activitySubtitle": "Latest status of build #3"
}
]
}
10 changes: 0 additions & 10 deletions src/test/resources/requests/completed-success.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,5 @@
"activityTitle": "Notification from Parent project » myFirst\\_Job\\_",
"activitySubtitle": "Latest status of build #167"
}
],
"potentialAction": [
{
"@context": "http://schema.org",
"@type": "ViewAction",
"name": "View Build",
"target": [
"http://localhost/job/myFirst_Job_/167/display/redirect"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"summary": "Damian Szczepanik » hook » PR-1: Build #3 Back to Normal",
"themeColor": "#00FF00",
"summary": "Damian Szczepanik » hook » PR-1: Build #3 Repeated Failure",
"themeColor": "#EF2929",
"sections": [
{
"markdown": true,
"facts": [
{
"name": "Status",
"value": "Back to Normal"
"value": "Repeated Failure"
},
{
"name": "Failing since",
"value": "build #10"
},
{
"name": "Remarks",
Expand Down

0 comments on commit 17658ee

Please sign in to comment.