Skip to content

Commit 4e2cc96

Browse files
committed
Keeping comments and adjusting checkstyle
* Checkstyle now allows empty source attribute. * Comments can optionaly be kept and not removed when new comments are added. * Will no longer re-create identical comments.
1 parent b1c04e2 commit 4e2cc96

File tree

4 files changed

+63
-30
lines changed

4 files changed

+63
-30
lines changed

CHANGELOG.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,31 @@
33
## Unreleased
44
### No issue
55

6+
**Keeping comments and adjusting checkstyle**
7+
8+
* Checkstyle now allows empty source attribute.
9+
* Comments can optionaly be kept and not removed when new comments are added.
10+
* Will no longer re-create identical comments.
11+
12+
[75375780b599622](https://github.com/tomasbjerre/violation-comments-to-bitbucket-server-lib/commit/75375780b599622) Tomas Bjerre *2017-09-02 09:18:53*
13+
14+
15+
## 1.29
16+
### No issue
17+
18+
**Checking for null in API-calls**
19+
20+
21+
[fdff3f2ae865d81](https://github.com/tomasbjerre/violation-comments-to-bitbucket-server-lib/commit/fdff3f2ae865d81) Tomas Bjerre *2017-08-11 10:04:40*
22+
23+
24+
## 1.28
25+
### No issue
26+
627
**URL encoding paths #2**
728

829

9-
[73a75a3c4ffe8d1](https://github.com/tomasbjerre/violation-comments-to-bitbucket-server-lib/commit/73a75a3c4ffe8d1) Tomas Bjerre *2017-08-02 15:29:12*
30+
[7122da4322e2f6e](https://github.com/tomasbjerre/violation-comments-to-bitbucket-server-lib/commit/7122da4322e2f6e) Tomas Bjerre *2017-08-02 15:29:50*
1031

1132

1233
## 1.27

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ repositories {
6868
}
6969

7070
dependencies {
71-
compile 'se.bjurr.violations:violation-comments-lib:1.40'
71+
compile 'se.bjurr.violations:violation-comments-lib:1.42'
7272
compile 'com.jayway.jsonpath:json-path:2.0.0'
7373
compile 'com.google.code.gson:gson:2.8.0'
7474
compile 'com.google.guava:guava:20.0'

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

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
import org.slf4j.Logger;
1313
import org.slf4j.LoggerFactory;
1414

15-
import com.google.common.annotations.VisibleForTesting;
16-
import com.google.common.base.Supplier;
17-
1815
import se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerClient;
1916
import se.bjurr.violations.comments.bitbucketserver.lib.client.model.BitbucketServerComment;
2017
import se.bjurr.violations.comments.bitbucketserver.lib.client.model.BitbucketServerDiff;
@@ -29,6 +26,9 @@
2926
import se.bjurr.violations.lib.model.Violation;
3027
import se.bjurr.violations.lib.util.Optional;
3128

29+
import com.google.common.annotations.VisibleForTesting;
30+
import com.google.common.base.Supplier;
31+
3232
public class BitbucketServerCommentsProvider implements CommentsProvider {
3333

3434
private static final Logger LOG = LoggerFactory.getLogger(BitbucketServerCommentsProvider.class);
@@ -52,12 +52,12 @@ public BitbucketServerDiffResponse get() {
5252
}
5353

5454
public BitbucketServerCommentsProvider(ViolationCommentsToBitbucketServerApi violationCommentsToBitbucketApi) {
55-
String bitbucketServerBaseUrl = violationCommentsToBitbucketApi.getBitbucketServerUrl();
56-
String bitbucketServerProject = violationCommentsToBitbucketApi.getProjectKey();
57-
String bitbucketServerRepo = violationCommentsToBitbucketApi.getRepoSlug();
58-
Integer bitbucketServerPullRequestId = violationCommentsToBitbucketApi.getPullRequestId();
59-
String bitbucketServerUser = violationCommentsToBitbucketApi.getUsername();
60-
String bitbucketServerPassword = violationCommentsToBitbucketApi.getPassword();
55+
final String bitbucketServerBaseUrl = violationCommentsToBitbucketApi.getBitbucketServerUrl();
56+
final String bitbucketServerProject = violationCommentsToBitbucketApi.getProjectKey();
57+
final String bitbucketServerRepo = violationCommentsToBitbucketApi.getRepoSlug();
58+
final Integer bitbucketServerPullRequestId = violationCommentsToBitbucketApi.getPullRequestId();
59+
final String bitbucketServerUser = violationCommentsToBitbucketApi.getUsername();
60+
final String bitbucketServerPassword = violationCommentsToBitbucketApi.getPassword();
6161
client = new BitbucketServerClient(bitbucketServerBaseUrl, bitbucketServerProject, bitbucketServerRepo,
6262
bitbucketServerPullRequestId, bitbucketServerUser, bitbucketServerPassword);
6363
this.violationCommentsToBitbucketApi = violationCommentsToBitbucketApi;
@@ -75,11 +75,11 @@ public void createSingleFileComment(ChangedFile file, Integer line, String comme
7575

7676
@Override
7777
public List<Comment> getComments() {
78-
List<Comment> comments = newArrayList();
79-
for (String changedFile : client.pullRequestChanges()) {
80-
List<BitbucketServerComment> bitbucketServerCommentsOnFile = client.pullRequestComments(changedFile);
81-
for (BitbucketServerComment fileComment : bitbucketServerCommentsOnFile) {
82-
List<String> specifics = newArrayList(fileComment.getVersion() + "", changedFile);
78+
final List<Comment> comments = newArrayList();
79+
for (final String changedFile : client.pullRequestChanges()) {
80+
final List<BitbucketServerComment> bitbucketServerCommentsOnFile = client.pullRequestComments(changedFile);
81+
for (final BitbucketServerComment fileComment : bitbucketServerCommentsOnFile) {
82+
final List<String> specifics = newArrayList(fileComment.getVersion() + "", changedFile);
8383
comments.add(new Comment(fileComment.getId() + "", fileComment.getText(), null, specifics));
8484
}
8585
}
@@ -89,11 +89,11 @@ public List<Comment> getComments() {
8989

9090
@Override
9191
public List<ChangedFile> getFiles() {
92-
List<ChangedFile> changedFiles = newArrayList();
92+
final List<ChangedFile> changedFiles = newArrayList();
9393

94-
List<String> bitbucketServerChangedFiles = client.pullRequestChanges();
94+
final List<String> bitbucketServerChangedFiles = client.pullRequestChanges();
9595

96-
for (String changedFile : bitbucketServerChangedFiles) {
96+
for (final String changedFile : bitbucketServerChangedFiles) {
9797
changedFiles.add(new ChangedFile(changedFile, new ArrayList<String>()));
9898
}
9999

@@ -102,14 +102,14 @@ public List<ChangedFile> getFiles() {
102102

103103
@Override
104104
public void removeComments(List<Comment> comments) {
105-
for (Comment comment : comments) {
105+
for (final Comment comment : comments) {
106106
Integer commentId = null;
107107
Integer commentVersion = null;
108108
try {
109109
commentId = Integer.valueOf(comment.getIdentifier());
110110
commentVersion = Integer.valueOf(comment.getSpecifics().get(0));
111111
client.pullRequestRemoveComment(commentId, commentVersion);
112-
} catch (Exception e) {
112+
} catch (final Exception e) {
113113
LOG.warn("Was unable to remove comment " + commentId + " " + commentVersion, e);
114114
}
115115
}
@@ -120,24 +120,24 @@ public boolean shouldComment(ChangedFile changedFile, Integer changedLine) {
120120
if (!violationCommentsToBitbucketApi.getCommentOnlyChangedContent()) {
121121
return true;
122122
}
123-
int context = violationCommentsToBitbucketApi.getCommentOnlyChangedContentContext();
124-
List<BitbucketServerDiff> diffs = diffResponse.get().getDiffs();
123+
final int context = violationCommentsToBitbucketApi.getCommentOnlyChangedContentContext();
124+
final List<BitbucketServerDiff> diffs = diffResponse.get().getDiffs();
125125
return shouldComment(changedFile, changedLine, context, diffs);
126126
}
127127

128128
@VisibleForTesting
129129
boolean shouldComment(ChangedFile changedFile, Integer changedLine, int context, List<BitbucketServerDiff> diffs) {
130-
for (BitbucketServerDiff diff : diffs) {
131-
DiffDestination destination = diff.getDestination();
130+
for (final BitbucketServerDiff diff : diffs) {
131+
final DiffDestination destination = diff.getDestination();
132132
if (destination != null) {
133-
String destinationToString = destination.getToString();
133+
final String destinationToString = destination.getToString();
134134
if (!isNullOrEmpty(destinationToString)) {
135135
if (destinationToString.equals(changedFile.getFilename())) {
136136
if (diff.getHunks() != null) {
137-
for (DiffHunk hunk : diff.getHunks()) {
138-
for (Segment segment : hunk.getSegments()) {
137+
for (final DiffHunk hunk : diff.getHunks()) {
138+
for (final Segment segment : hunk.getSegments()) {
139139
if (segment.getType() == ADDED) {
140-
for (Line line : segment.getLines()) {
140+
for (final Line line : segment.getLines()) {
141141
if (line.getDestination() >= changedLine - context && line.getDestination() <= changedLine + context) {
142142
return true;
143143
}
@@ -167,4 +167,9 @@ public boolean shouldCreateSingleFileComment() {
167167
public Optional<String> findCommentFormat(ChangedFile changedFile, Violation violation) {
168168
return Optional.absent();
169169
}
170+
171+
@Override
172+
public boolean shouldKeepOldComments() {
173+
return violationCommentsToBitbucketApi.getShouldKeepOldComments();
174+
}
170175
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public static ViolationCommentsToBitbucketServerApi violationCommentsToBitbucket
3131
private List<Violation> violations;
3232
private boolean commentOnlyChangedContent = false;
3333
private int commentOnlyChangedContentContext;
34+
private boolean shouldKeepOldComments;
3435

3536
private ViolationCommentsToBitbucketServerApi() {
3637

@@ -109,7 +110,7 @@ private void populateFromEnvironmentVariables() {
109110
public void toPullRequest() throws Exception {
110111
populateFromEnvironmentVariables();
111112
checkState();
112-
CommentsProvider commentsProvider = new BitbucketServerCommentsProvider(this);
113+
final CommentsProvider commentsProvider = new BitbucketServerCommentsProvider(this);
113114
createComments(commentsProvider, violations, BITBUCKET_MAX_COMMENT_SIZE);
114115
}
115116

@@ -177,4 +178,10 @@ public ViolationCommentsToBitbucketServerApi withViolations(List<Violation> viol
177178
this.violations = violations;
178179
return this;
179180
}
181+
public ViolationCommentsToBitbucketServerApi setShouldKeepOldComments(boolean shouldKeepOldComments) {
182+
this.shouldKeepOldComments = shouldKeepOldComments;
183+
return this;}
184+
public boolean getShouldKeepOldComments() {
185+
return shouldKeepOldComments;
186+
}
180187
}

0 commit comments

Comments
 (0)