Skip to content

Commit

Permalink
Fix Bitbucket Server code annotations (#284)
Browse files Browse the repository at this point in the history
In #237 the property names of the annotation model were changed to fix a bug with how code annotations are reported to Bitbucket Cloud. This PR however did not take into consideration that the previous naming was actually correct and required for Bitbucket Server. With this change Bitbucket Cloud will continue to receive the message as summary (API docs), while Bitbucket Server receives the message as message again (API docs).

The @JsonProperty annotations have been moved to the getters so that they support overrides, as mixing property-level and method-level annotations does not work for this use case. Technically this is only needed for the message property, but for consistency reasons this has been done for all fields and has been verified that this is mapped correctly for both cloud and server.
  • Loading branch information
mKeRix authored Jan 23, 2021
1 parent d5232b4 commit 68aff70
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@
* Class for reusing models between the cloud and the server version
*/
public class CodeInsightsAnnotation {
@JsonProperty("line")
private final int line;
@JsonProperty("summary")
private final String message;
@JsonProperty("path")
private final String path;
@JsonProperty("severity")
private final String severity;

public CodeInsightsAnnotation(int line, String message, String path, String severity) {
Expand All @@ -40,18 +36,22 @@ public CodeInsightsAnnotation(int line, String message, String path, String seve
this.severity = severity;
}

@JsonProperty("line")
public int getLine() {
return line;
}

@JsonProperty("message")
public String getMessage() {
return message;
}

@JsonProperty("path")
public String getPath() {
return path;
}

@JsonProperty("severity")
public String getSeverity() {
return severity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.bitbucket.client.model.CodeInsightsAnnotation;

public class CloudAnnotation extends CodeInsightsAnnotation {
@JsonProperty("external_id")
private final String externalId;
@JsonProperty("link")
private final String link;
@JsonProperty("annotation_type")
private final String annotationType;

@JsonCreator
Expand All @@ -44,14 +41,23 @@ public CloudAnnotation(String externalId,
this.annotationType = annotationType;
}

@Override
@JsonProperty("summary")
public String getMessage() {
return super.getMessage();
}

@JsonProperty("external_id")
public String getExternalId() {
return externalId;
}

@JsonProperty("link")
public String getLink() {
return link;
}

@JsonProperty("annotation_type")
public String getAnnotationType() {
return annotationType;
}
Expand Down

0 comments on commit 68aff70

Please sign in to comment.