Skip to content

Commit 4e12513

Browse files
address feedback
1 parent bf6d2b2 commit 4e12513

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/main/java/com/bazel_diff/BazelClient.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
interface BazelClient {
2222
List<BazelTarget> queryAllTargets() throws IOException;
23-
Set<String> queryForImpactedTargets(Set<String> impactedTargets, String avoidQuery, Boolean hashAllTargets) throws IOException;
23+
Set<String> queryForImpactedTargets(Set<String> impactedTargets, String avoidQuery) throws IOException;
2424
Set<BazelSourceFileTarget> convertFilepathsToSourceTargets(Set<Path> filepaths) throws IOException, NoSuchAlgorithmException;
2525
Set<BazelSourceFileTarget> queryAllSourcefileTargets() throws IOException, NoSuchAlgorithmException;
2626
}
@@ -47,17 +47,12 @@ public List<BazelTarget> queryAllTargets() throws IOException {
4747
}
4848

4949
@Override
50-
public Set<String> queryForImpactedTargets(Set<String> impactedTargets, String avoidQuery, Boolean hashAllTargets) throws IOException {
50+
public Set<String> queryForImpactedTargets(Set<String> impactedTargets, String avoidQuery) throws IOException {
5151
Set<String> impactedTargetNames = new HashSet<>();
5252
String targetQuery = impactedTargets.stream()
5353
.map(target -> String.format("'%s'", target))
5454
.collect(Collectors.joining(" + "));
55-
String query = "";
56-
if (hashAllTargets != null && hashAllTargets) {
57-
query = targetQuery;
58-
} else {
59-
query = String.format("rdeps(//... except '//external:all-targets', %s)", targetQuery);
60-
}
55+
String query = query = String.format("rdeps(//... except '//external:all-targets', %s)", targetQuery);
6156
if (avoidQuery != null) {
6257
query = String.format("(%s) except (%s)", query, avoidQuery);
6358
}

src/main/java/com/bazel_diff/TargetHashingClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ public Set<String> getImpactedTargets(
4646
impactedTargets.add(entry.getKey());
4747
}
4848
}
49-
return bazelClient.queryForImpactedTargets(impactedTargets, avoidQuery, hashAllTargets);
49+
if (hashAllTargets != null && hashAllTargets && avoidQuery == null) {
50+
return impactedTargets;
51+
}
52+
return bazelClient.queryForImpactedTargets(impactedTargets, avoidQuery);
5053
}
5154

5255
private byte[] createDigestForTarget(

test/java/com/bazel_diff/TargetHashingClientImplTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void hashAllBazelTargets_sourceTargets_modifiedSources() throws IOExcepti
118118

119119
@Test
120120
public void getImpactedTargets() throws IOException {
121-
when(bazelClientMock.queryForImpactedTargets(anySet(), anyObject(), Matchers.eq(false))).thenReturn(
121+
when(bazelClientMock.queryForImpactedTargets(anySet(), anyObject())).thenReturn(
122122
new HashSet<>(Arrays.asList("rule1", "rule3"))
123123
);
124124
TargetHashingClientImpl client = new TargetHashingClientImpl(bazelClientMock);
@@ -138,7 +138,7 @@ public void getImpactedTargets() throws IOException {
138138

139139
@Test
140140
public void getImpactedTargets_withAvoidQuery() throws IOException {
141-
when(bazelClientMock.queryForImpactedTargets(anySet(), eq("some_query"), Matchers.eq(false))).thenReturn(
141+
when(bazelClientMock.queryForImpactedTargets(anySet(), eq("some_query"))).thenReturn(
142142
new HashSet<>(Arrays.asList("rule1"))
143143
);
144144
TargetHashingClientImpl client = new TargetHashingClientImpl(bazelClientMock);
@@ -157,7 +157,7 @@ public void getImpactedTargets_withAvoidQuery() throws IOException {
157157

158158
@Test
159159
public void getImpactedTargets_withHashAllTargets() throws IOException {
160-
when(bazelClientMock.queryForImpactedTargets(anySet(), anyObject(), Matchers.eq(true))).thenReturn(
160+
when(bazelClientMock.queryForImpactedTargets(anySet(), anyObject())).thenReturn(
161161
new HashSet<>(Arrays.asList("rule1"))
162162
);
163163
TargetHashingClientImpl client = new TargetHashingClientImpl(bazelClientMock);
@@ -171,12 +171,13 @@ public void getImpactedTargets_withHashAllTargets() throws IOException {
171171
Set<String> impactedTargets = client.getImpactedTargets(hash1, hash2, null, true);
172172
Set<String> expectedSet = new HashSet<>();
173173
expectedSet.add("rule1");
174+
expectedSet.add("rule3");
174175
assertEquals(expectedSet, impactedTargets);
175176
}
176177

177178
@Test
178179
public void getImpactedTargets_withHashAllTargets_withAvoidQuery() throws IOException {
179-
when(bazelClientMock.queryForImpactedTargets(anySet(), eq("some_query"), Matchers.eq(true))).thenReturn(
180+
when(bazelClientMock.queryForImpactedTargets(anySet(), eq("some_query"))).thenReturn(
180181
new HashSet<>(Arrays.asList("rule1"))
181182
);
182183
TargetHashingClientImpl client = new TargetHashingClientImpl(bazelClientMock);

0 commit comments

Comments
 (0)