Skip to content

Commit 35220e0

Browse files
committed
1 parent aee4c2d commit 35220e0

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ apply from: project.buildscript.classLoader.getResource('release.gradle').toURI(
1919

2020

2121
dependencies {
22-
compile 'se.bjurr.violations:violation-comments-lib:1.102'
22+
compile 'se.bjurr.violations:violation-comments-lib:1.104'
2323
compile 'com.jayway.jsonpath:json-path:2.0.0'
2424
compile 'com.google.code.gson:gson:2.8.0'
2525
compile 'com.google.guava:guava:20.0'

src/main/java/se/bjurr/violations/comments/bitbucketserver/lib/BitbucketServerCommentsProvider.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static com.google.common.cache.CacheBuilder.newBuilder;
55
import static com.google.common.collect.Lists.newArrayList;
66
import static java.util.concurrent.TimeUnit.MINUTES;
7+
import static java.util.logging.Level.INFO;
78
import static java.util.logging.Level.SEVERE;
89
import static se.bjurr.violations.comments.bitbucketserver.lib.client.model.DIFFTYPE.ADDED;
910

@@ -32,6 +33,7 @@
3233
import se.bjurr.violations.comments.lib.model.ChangedFile;
3334
import se.bjurr.violations.comments.lib.model.Comment;
3435
import se.bjurr.violations.lib.ViolationsLogger;
36+
import se.bjurr.violations.lib.reports.ReportsFinder;
3537

3638
public class BitbucketServerCommentsProvider implements CommentsProvider {
3739
private static final Integer BITBUCKET_MAX_COMMENT_SIZE = 32767;
@@ -121,6 +123,16 @@ public List<Comment> getComments() {
121123
* This is time consuming to do and is only needed if we are creating comments on each file.
122124
*/
123125
for (final String changedFile : this.client.pullRequestChanges()) {
126+
final List<String> ignorePaths = this.violationCommentsToBitbucketApi.getIgnorePaths();
127+
if (ReportsFinder.isIgnored(changedFile, ignorePaths)) {
128+
this.violationsLogger.log(
129+
INFO,
130+
"Ignoring changed file "
131+
+ changedFile
132+
+ " because it matched ignored paths: "
133+
+ ignorePaths);
134+
continue;
135+
}
124136
final List<BitbucketServerComment> bitbucketServerCommentsOnFile =
125137
this.client.pullRequestComments(changedFile);
126138
for (final BitbucketServerComment fileComment : bitbucketServerCommentsOnFile) {

src/main/java/se/bjurr/violations/comments/bitbucketserver/lib/ViolationCommentsToBitbucketServerApi.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static se.bjurr.violations.lib.util.Utils.firstNonNull;
88
import static se.bjurr.violations.lib.util.Utils.isNullOrEmpty;
99

10+
import java.util.List;
1011
import java.util.Optional;
1112
import java.util.Set;
1213
import java.util.logging.Level;
@@ -67,6 +68,7 @@ public void log(final Level level, final String string, final Throwable t) {
6768
});
6869
private Integer maxNumberOfViolations;
6970
private boolean shouldCommentOnlyChangedFiles = true;
71+
private List<String> ignorePaths;
7072

7173
private ViolationCommentsToBitbucketServerApi() {}
7274

@@ -393,4 +395,13 @@ public ViolationCommentsToBitbucketServerApi withMaxNumberOfViolations(
393395
public Integer getMaxNumberOfViolations() {
394396
return this.maxNumberOfViolations;
395397
}
398+
399+
public List<String> getIgnorePaths() {
400+
return this.ignorePaths;
401+
}
402+
403+
public ViolationCommentsToBitbucketServerApi withIgnorePaths(final List<String> ignorePaths) {
404+
this.ignorePaths = ignorePaths;
405+
return this;
406+
}
396407
}

src/test/java/se/bjurr/violations/comments/bitbucketserver/lib/client/BitbucketServerIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void withCreateCommentWithAllSingleFileComments() throws Exception {
8282
violations.add(
8383
violationBuilder() //
8484
.setFile(CHANGED_FILE) //
85-
.setMessage("no not ok!") //
85+
.setMessage("no not ok!\nnewline") //
8686
.setSeverity(SEVERITY.ERROR) //
8787
.setStartLine(12) //
8888
.setReporter("The tool") //

0 commit comments

Comments
 (0)