-
Notifications
You must be signed in to change notification settings - Fork 331
Expand file tree
/
Copy pathCiVisibilitySettings.java
More file actions
176 lines (152 loc) · 5.38 KB
/
CiVisibilitySettings.java
File metadata and controls
176 lines (152 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package datadog.trace.civisibility.config;
import com.squareup.moshi.FromJson;
import java.nio.file.Path;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Nullable;
public class CiVisibilitySettings {
public static final CiVisibilitySettings DEFAULT =
new CiVisibilitySettings(
false,
false,
false,
false,
false,
false,
false,
EarlyFlakeDetectionSettings.DEFAULT,
TestManagementSettings.DEFAULT,
null);
private final boolean itrEnabled;
private final boolean codeCoverage;
private final boolean testsSkipping;
private final boolean requireGit;
private final boolean flakyTestRetriesEnabled;
private final boolean impactedTestsDetectionEnabled;
private final boolean knownTestsEnabled;
private final EarlyFlakeDetectionSettings earlyFlakeDetectionSettings;
private final TestManagementSettings testManagementSettings;
@Nullable private final String defaultBranch;
CiVisibilitySettings(
boolean itrEnabled,
boolean codeCoverage,
boolean testsSkipping,
boolean requireGit,
boolean flakyTestRetriesEnabled,
boolean impactedTestsDetectionEnabled,
boolean knownTestsEnabled,
EarlyFlakeDetectionSettings earlyFlakeDetectionSettings,
TestManagementSettings testManagementSettings,
@Nullable String defaultBranch) {
this.itrEnabled = itrEnabled;
this.codeCoverage = codeCoverage;
this.testsSkipping = testsSkipping;
this.requireGit = requireGit;
this.flakyTestRetriesEnabled = flakyTestRetriesEnabled;
this.impactedTestsDetectionEnabled = impactedTestsDetectionEnabled;
this.knownTestsEnabled = knownTestsEnabled;
this.earlyFlakeDetectionSettings = earlyFlakeDetectionSettings;
this.testManagementSettings = testManagementSettings;
this.defaultBranch = defaultBranch;
}
public boolean isItrEnabled() {
return itrEnabled;
}
public boolean isCodeCoverageEnabled() {
return codeCoverage;
}
public boolean isTestsSkippingEnabled() {
return testsSkipping;
}
public boolean isGitUploadRequired() {
return requireGit;
}
public boolean isFlakyTestRetriesEnabled() {
return flakyTestRetriesEnabled;
}
public boolean isImpactedTestsDetectionEnabled() {
return impactedTestsDetectionEnabled;
}
public boolean isKnownTestsEnabled() {
return knownTestsEnabled;
}
public EarlyFlakeDetectionSettings getEarlyFlakeDetectionSettings() {
return earlyFlakeDetectionSettings;
}
public TestManagementSettings getTestManagementSettings() {
return testManagementSettings;
}
@Nullable
public String getDefaultBranch() {
return defaultBranch;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CiVisibilitySettings that = (CiVisibilitySettings) o;
return itrEnabled == that.itrEnabled
&& codeCoverage == that.codeCoverage
&& testsSkipping == that.testsSkipping
&& requireGit == that.requireGit
&& flakyTestRetriesEnabled == that.flakyTestRetriesEnabled
&& impactedTestsDetectionEnabled == that.impactedTestsDetectionEnabled
&& knownTestsEnabled == that.knownTestsEnabled
&& Objects.equals(earlyFlakeDetectionSettings, that.earlyFlakeDetectionSettings)
&& Objects.equals(testManagementSettings, that.testManagementSettings)
&& Objects.equals(defaultBranch, that.defaultBranch);
}
@Override
public int hashCode() {
return Objects.hash(
itrEnabled,
codeCoverage,
testsSkipping,
requireGit,
flakyTestRetriesEnabled,
impactedTestsDetectionEnabled,
knownTestsEnabled,
earlyFlakeDetectionSettings,
testManagementSettings,
defaultBranch);
}
public interface Factory {
CiVisibilitySettings create(Path path);
}
public static final class JsonAdapter {
public static final JsonAdapter INSTANCE = new JsonAdapter();
@FromJson
public CiVisibilitySettings fromJson(Map<String, Object> json) {
if (json == null) {
return DEFAULT;
}
return new CiVisibilitySettings(
getBoolean(json, "itr_enabled", false),
getBoolean(json, "code_coverage", false),
getBoolean(json, "tests_skipping", false),
getBoolean(json, "require_git", false),
getBoolean(json, "flaky_test_retries_enabled", false),
getBoolean(json, "impacted_tests_enabled", false),
getBoolean(json, "known_tests_enabled", false),
EarlyFlakeDetectionSettings.JsonAdapter.INSTANCE.fromJson(
(Map<String, Object>) json.get("early_flake_detection")),
TestManagementSettings.JsonAdapter.INSTANCE.fromJson(
(Map<String, Object>) json.get("test_management")),
getString(json, "default_branch", null));
}
private static boolean getBoolean(
Map<String, Object> json, String fieldName, boolean defaultValue) {
Object value = json.get(fieldName);
return value instanceof Boolean ? (Boolean) value : defaultValue;
}
private static String getString(
Map<String, Object> json, String fieldName, String defaultValue) {
Object value = json.get(fieldName);
return value instanceof String ? (String) value : defaultValue;
}
}
}