Skip to content

Commit 155c721

Browse files
author
Sergey Brenko
authored
Merge pull request #53 from zebrunner/notification-enhancements
Added possibility to disable notifications
2 parents d3dc9eb + d21a767 commit 155c721

9 files changed

+30
-10
lines changed

src/main/java/com/zebrunner/agent/core/config/ConfigurationHolder.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ private static String toSerializedRunContext(String ciRunId) {
122122
// return new Gson().toJson(runContext);
123123
// }
124124

125+
public static boolean notificationsEnabled() {
126+
Boolean enabled = configuration.getNotification().getEnabled();
127+
return enabled == null || enabled;
128+
}
129+
125130
public static boolean shouldNotifyOnEachFailure() {
126131
Boolean notifyOnEachFailure = configuration.getNotification().getNotifyOnEachFailure();
127132
return notifyOnEachFailure != null && notifyOnEachFailure;
@@ -149,7 +154,7 @@ public static String getMilestoneName() {
149154

150155
public static boolean isTcmSyncEnabled() {
151156
Boolean pushResults = configuration.getTcm().getZebrunner().getPushResults();
152-
return pushResults != null && pushResults;
157+
return pushResults == null || pushResults;
153158
}
154159

155160
public static boolean isTcmRealTimeSyncEnabled() {
@@ -163,7 +168,7 @@ public static String getTcmTestRunId() {
163168

164169
public static boolean isTestRailSyncEnabled() {
165170
Boolean pushResults = configuration.getTcm().getTestRail().getPushResults();
166-
return pushResults != null && pushResults;
171+
return pushResults == null || pushResults;
167172
}
168173

169174
public static boolean isTestRailRealTimeSyncEnabled() {
@@ -198,7 +203,7 @@ public static String getTestRailAssignee() {
198203

199204
public static boolean isXraySyncEnabled() {
200205
Boolean pushResults = configuration.getTcm().getXray().getPushResults();
201-
return pushResults != null && pushResults;
206+
return pushResults == null || pushResults;
202207
}
203208

204209
public static boolean isXrayRealTimeSyncEnabled() {
@@ -212,7 +217,7 @@ public static String getXrayExecutionKey() {
212217

213218
public static boolean isZephyrSyncEnabled() {
214219
Boolean pushResults = configuration.getTcm().getZephyr().getPushResults();
215-
return pushResults != null && pushResults;
220+
return pushResults == null || pushResults;
216221
}
217222

218223
public static boolean isZephyrSyncRealTimeEnabled() {

src/main/java/com/zebrunner/agent/core/config/ConfigurationProvidersChain.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private static void normalizeMilestoneConfiguration(ReportingConfiguration confi
142142

143143
private static void normalizeNotificationConfiguration(ReportingConfiguration config) {
144144
if (config.getNotification() == null) {
145-
config.setNotification(new ReportingConfiguration.NotificationConfiguration(null, null, null, null));
145+
config.setNotification(new ReportingConfiguration.NotificationConfiguration(null, null, null, null, null));
146146
} else {
147147
ReportingConfiguration.NotificationConfiguration notificationConfig = config.getNotification();
148148

@@ -321,6 +321,9 @@ private static void merge(ReportingConfiguration config, ReportingConfiguration
321321
}
322322

323323
ReportingConfiguration.NotificationConfiguration notification = config.getNotification();
324+
if (notification.getEnabled() == null) {
325+
notification.setEnabled(providedConfig.getNotification().getEnabled());
326+
}
324327
if (notification.getNotifyOnEachFailure() == null) {
325328
notification.setNotifyOnEachFailure(providedConfig.getNotification().getNotifyOnEachFailure());
326329
}
@@ -449,6 +452,7 @@ private static boolean areAllArgsSet(ReportingConfiguration config) {
449452
String testCaseStatusOnFail = config.getTcm().getTestCaseStatus().getOnFail();
450453
String testCaseStatusOnSkip = config.getTcm().getTestCaseStatus().getOnSkip();
451454

455+
Boolean notificationsEnabled = config.getNotification().getEnabled();
452456
Boolean notifyOnEachFailure = config.getNotification().getNotifyOnEachFailure();
453457
String slackChannels = config.getNotification().getSlackChannels();
454458
String msTeamsChannels = config.getNotification().getMsTeamsChannels();
@@ -482,7 +486,7 @@ private static boolean areAllArgsSet(ReportingConfiguration config) {
482486
&& displayName != null && build != null && environment != null && context != null
483487
&& retryKnownIssues != null && substituteRemoteWebDrivers != null && treatSkipsAsFailures != null
484488
&& testCaseStatusOnPass != null && testCaseStatusOnFail != null && testCaseStatusOnSkip != null
485-
&& notifyOnEachFailure != null && slackChannels != null && msTeamsChannels != null && emails != null
489+
&& notificationsEnabled != null && notifyOnEachFailure != null && slackChannels != null && msTeamsChannels != null && emails != null
486490
&& tcmPushResults != null && tcmPushInRealTime != null && tcmRunId != null
487491
&& testRailPushResults != null && testRailPushInRealTime != null && testRailSuiteId != null
488492
&& testRailRunId != null && testRailIncludeAllTestCasesInNewRun != null && testRailRunName != null

src/main/java/com/zebrunner/agent/core/config/ReportingConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public static class RunConfiguration {
6666
@AllArgsConstructor
6767
public static class NotificationConfiguration {
6868

69+
private Boolean enabled;
6970
private Boolean notifyOnEachFailure;
7071
private String slackChannels;
7172
private String msTeamsChannels;

src/main/java/com/zebrunner/agent/core/config/provider/EnvironmentConfigurationProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class EnvironmentConfigurationProvider implements ConfigurationProvider {
4949
private static final String TCM_ZEPHYR_JIRA_PROJECT_KEY_VARIABLE = "REPORTING_TCM_ZEPHYR_JIRA_PROJECT_KEY";
5050
private static final String TCM_ZEPHYR_TEST_CYCLE_KEY_VARIABLE = "REPORTING_TCM_ZEPHYR_TEST_CYCLE_KEY";
5151

52+
private static final String NOTIFICATION_ENABLED = "REPORTING_NOTIFICATION_ENABLED";
5253
private static final String NOTIFICATION_NOTIFY_ON_EACH_FAILURE_VARIABLE = "REPORTING_NOTIFICATION_NOTIFY_ON_EACH_FAILURE";
5354
private static final String NOTIFICATION_SLACK_CHANNELS_VARIABLE = "REPORTING_NOTIFICATION_SLACK_CHANNELS";
5455
private static final String NOTIFICATION_MS_TEAMS_CHANNELS_VARIABLE = "REPORTING_NOTIFICATION_MS_TEAMS_CHANNELS";
@@ -98,6 +99,7 @@ public ReportingConfiguration getConfiguration() {
9899
String zephyrJiraProjectKey = System.getenv(TCM_ZEPHYR_JIRA_PROJECT_KEY_VARIABLE);
99100
String zephyrTestCycleKey = System.getenv(TCM_ZEPHYR_TEST_CYCLE_KEY_VARIABLE);
100101

102+
Boolean notificationsEnabled = parseBoolean(System.getenv(NOTIFICATION_ENABLED));
101103
Boolean notifyOnEachFailure = parseBoolean(System.getenv(NOTIFICATION_NOTIFY_ON_EACH_FAILURE_VARIABLE));
102104
String slackChannels = System.getenv(NOTIFICATION_SLACK_CHANNELS_VARIABLE);
103105
String msTeamsChannels = System.getenv(NOTIFICATION_MS_TEAMS_CHANNELS_VARIABLE);
@@ -124,7 +126,7 @@ public ReportingConfiguration getConfiguration() {
124126
milestoneId, milestoneName
125127
))
126128
.notification(new ReportingConfiguration.NotificationConfiguration(
127-
notifyOnEachFailure, slackChannels, msTeamsChannels, emails
129+
notificationsEnabled, notifyOnEachFailure, slackChannels, msTeamsChannels, emails
128130
))
129131
.tcm(new ReportingConfiguration.TcmConfiguration(
130132
new ReportingConfiguration.TcmConfiguration.TestCaseStatus(

src/main/java/com/zebrunner/agent/core/config/provider/PropertiesConfigurationProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class PropertiesConfigurationProvider implements ConfigurationProvider {
5151
private static final String TCM_ZEPHYR_JIRA_PROJECT_KEY_PROPERTY = "reporting.tcm.zephyr.jira-project-key";
5252
private static final String TCM_ZEPHYR_TEST_CYCLE_KEY_PROPERTY = "reporting.tcm.zephyr.test-cycle-key";
5353

54+
private static final String NOTIFICATION_ENABLED = "reporting.notification.enabled";
5455
private static final String NOTIFICATION_NOTIFY_ON_EACH_FAILURE_PROPERTY = "reporting.notification.notify-on-each-failure";
5556
private final static String NOTIFICATION_SLACK_CHANNELS_PROPERTY = "reporting.notification.slack-channels";
5657
private final static String NOTIFICATION_MS_TEAMS_PROPERTY = "reporting.notification.ms-teams-channels";
@@ -104,6 +105,7 @@ public ReportingConfiguration getConfiguration() {
104105
String zephyrJiraProjectKey = agentProperties.getProperty(TCM_ZEPHYR_JIRA_PROJECT_KEY_PROPERTY);
105106
String zephyrTestCycleKey = agentProperties.getProperty(TCM_ZEPHYR_TEST_CYCLE_KEY_PROPERTY);
106107

108+
Boolean notificationsEnabled = ConfigurationUtils.parseBoolean(agentProperties.getProperty(NOTIFICATION_ENABLED));
107109
Boolean notifyOnEachFailure = ConfigurationUtils.parseBoolean(agentProperties.getProperty(NOTIFICATION_NOTIFY_ON_EACH_FAILURE_PROPERTY));
108110
String slackChannels = agentProperties.getProperty(NOTIFICATION_SLACK_CHANNELS_PROPERTY);
109111
String msTeamsChannels = agentProperties.getProperty(NOTIFICATION_MS_TEAMS_PROPERTY);
@@ -130,7 +132,7 @@ public ReportingConfiguration getConfiguration() {
130132
milestoneId, milestoneName
131133
))
132134
.notification(new ReportingConfiguration.NotificationConfiguration(
133-
notifyOnEachFailure, slackChannels, msTeamsChannels, emails
135+
notificationsEnabled, notifyOnEachFailure, slackChannels, msTeamsChannels, emails
134136
))
135137
.tcm(new ReportingConfiguration.TcmConfiguration(
136138
new ReportingConfiguration.TcmConfiguration.TestCaseStatus(

src/main/java/com/zebrunner/agent/core/config/provider/SystemPropertiesConfigurationProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class SystemPropertiesConfigurationProvider implements ConfigurationProvi
4747
private static final String TCM_ZEPHYR_JIRA_PROJECT_KEY_PROPERTY = "reporting.tcm.zephyr.jira-project-key";
4848
private static final String TCM_ZEPHYR_TEST_CYCLE_KEY_PROPERTY = "reporting.tcm.zephyr.test-cycle-key";
4949

50+
private static final String NOTIFICATION_ENABLED = "reporting.notification.enabled";
5051
private static final String NOTIFICATION_NOTIFY_ON_EACH_FAILURE_PROPERTY = "reporting.notification.notify-on-each-failure";
5152
private final static String SLACK_CHANNELS_PROPERTY = "reporting.notification.slack-channels";
5253
private final static String MS_TEAMS_CHANNELS_PROPERTY = "reporting.notification.ms-teams-channels";
@@ -96,6 +97,7 @@ public ReportingConfiguration getConfiguration() {
9697
String zephyrJiraProjectKey = System.getProperty(TCM_ZEPHYR_JIRA_PROJECT_KEY_PROPERTY);
9798
String zephyrTestCycleKey = System.getProperty(TCM_ZEPHYR_TEST_CYCLE_KEY_PROPERTY);
9899

100+
Boolean notificationsEnabled = ConfigurationUtils.parseBoolean(System.getProperty(NOTIFICATION_ENABLED));
99101
Boolean notifyOnEachFailure = ConfigurationUtils.parseBoolean(System.getProperty(NOTIFICATION_NOTIFY_ON_EACH_FAILURE_PROPERTY));
100102
String slackChannels = System.getProperty(SLACK_CHANNELS_PROPERTY);
101103
String msTeamsChannels = System.getProperty(MS_TEAMS_CHANNELS_PROPERTY);
@@ -122,7 +124,7 @@ public ReportingConfiguration getConfiguration() {
122124
milestoneId, milestoneName
123125
))
124126
.notification(new ReportingConfiguration.NotificationConfiguration(
125-
notifyOnEachFailure, slackChannels, msTeamsChannels, emails
127+
notificationsEnabled, notifyOnEachFailure, slackChannels, msTeamsChannels, emails
126128
))
127129
.tcm(new ReportingConfiguration.TcmConfiguration(
128130
new ReportingConfiguration.TcmConfiguration.TestCaseStatus(

src/main/java/com/zebrunner/agent/core/config/provider/YamlConfigurationProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class YamlConfigurationProvider implements ConfigurationProvider {
5656
private static final String TCM_ZEPHYR_JIRA_PROJECT_KEY_PROPERTY = "reporting.tcm.zephyr.jira-project-key";
5757
private static final String TCM_ZEPHYR_TEST_CYCLE_KEY_PROPERTY = "reporting.tcm.zephyr.test-cycle-key";
5858

59+
private static final String NOTIFICATION_ENABLED = "reporting.notification.enabled";
5960
private static final String NOTIFICATION_NOTIFY_ON_EACH_FAILURE_PROPERTY = "reporting.notification.notify-on-each-failure";
6061
private final static String NOTIFICATION_SLACK_CHANNELS_PROPERTY = "reporting.notification.slack-channels";
6162
private final static String NOTIFICATION_MS_TEAMS_CHANNELS_PROPERTY = "reporting.notification.ms-teams-channels";
@@ -110,6 +111,7 @@ public ReportingConfiguration getConfiguration() {
110111
String zephyrJiraProjectKey = getProperty(yamlProperties, TCM_ZEPHYR_JIRA_PROJECT_KEY_PROPERTY);
111112
String zephyrTestCycleKey = getProperty(yamlProperties, TCM_ZEPHYR_TEST_CYCLE_KEY_PROPERTY);
112113

114+
Boolean notificationsEnabled = ConfigurationUtils.parseBoolean(getProperty(yamlProperties, NOTIFICATION_ENABLED));
113115
Boolean notifyOnEachFailure = ConfigurationUtils.parseBoolean(getProperty(yamlProperties, NOTIFICATION_NOTIFY_ON_EACH_FAILURE_PROPERTY));
114116
String slackChannels = getProperty(yamlProperties, NOTIFICATION_SLACK_CHANNELS_PROPERTY);
115117
String msTeamsChannels = getProperty(yamlProperties, NOTIFICATION_MS_TEAMS_CHANNELS_PROPERTY);
@@ -136,7 +138,7 @@ public ReportingConfiguration getConfiguration() {
136138
milestoneId, milestoneName
137139
))
138140
.notification(new ReportingConfiguration.NotificationConfiguration(
139-
notifyOnEachFailure, slackChannels, msTeamsChannels, emails
141+
notificationsEnabled, notifyOnEachFailure, slackChannels, msTeamsChannels, emails
140142
))
141143
.tcm(new ReportingConfiguration.TcmConfiguration(
142144
new ReportingConfiguration.TcmConfiguration.TestCaseStatus(

src/main/java/com/zebrunner/agent/core/registrar/ReportingRegistrar.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public void registerStart(TestRunStartDescriptor tr) {
6868
ConfigurationHolder.getMilestoneName()
6969
))
7070
.notifications(new TestRunDTO.Notifications(
71+
ConfigurationHolder.notificationsEnabled(),
7172
collectNotificationTargets(),
7273
ConfigurationHolder.shouldNotifyOnEachFailure()
7374
))

src/main/java/com/zebrunner/agent/core/registrar/domain/TestRunDTO.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public static class JenkinsContext {
6868
@Value
6969
public static class Notifications {
7070

71+
boolean enabled;
7172
Set<NotificationTargetDTO> targets;
7273
boolean notifyOnEachFailure;
7374

0 commit comments

Comments
 (0)