Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sq 8 2+azure devops #202

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ repositories {
}
}

def sonarqubeVersion = '8.1.0.31237'
def sonarqubeVersion = '8.2.0.32929'
def sonarqubeLibDir = "${projectDir}/sonarqube-lib"
def sonarLibraries = "${sonarqubeLibDir}/sonarqube-${sonarqubeVersion}/lib"

Expand Down Expand Up @@ -116,6 +116,11 @@ tasks.shadowJar.configure {
classifier = null
}

tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:unchecked'
options.deprecation = true
}

assemble.dependsOn('shadowJar')

pitest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.PostAnalysisIssueVisitor;
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.PullRequestPostAnalysisTask;
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.azuredevops.AzureDevOpsServerPullRequestDecorator;
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.bitbucket.BitbucketServerPullRequestDecorator;
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.bitbucket.client.BitbucketClient;
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.GithubPullRequestDecorator;
Expand All @@ -43,7 +44,8 @@ public List<Object> getComponents() {
PostAnalysisIssueVisitor.class, GithubPullRequestDecorator.class,
GraphqlCheckRunProvider.class, DefaultLinkHeaderReader.class, RestApplicationAuthenticationProvider.class,
BitbucketServerPullRequestDecorator.class, BitbucketClient.class,
GitlabServerPullRequestDecorator.class);
GitlabServerPullRequestDecorator.class,
AzureDevOpsServerPullRequestDecorator.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.Map;

public class AnalysisDetails {

Expand Down Expand Up @@ -121,6 +122,10 @@ public QualityGate.Status getQualityGateStatus() {
return qualityGate.getStatus();
}

public Map<String,String> getScannerProperties() {
return scannerContext.getProperties();
}

Comment on lines +125 to +128
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only seems to have been introduced to allow logging of all the properties, which doesn't seem like a good use case. The logging should either happen in the PostAnalysisTask that triggers decoration, or be removed.

public Optional<String> getScannerProperty(String propertyName) {
return Optional.ofNullable(scannerContext.getProperties().get(propertyName));
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.github.mc1arke.sonarqube.plugin.ce.pullrequest.azuredevops.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.azuredevops.model.enums.CommentType;

import java.io.Serializable;
import java.util.Date;
import java.util.List;


/**
* Represents a comment which is one of potentially many in a comment thread.
*/
public class Comment implements Serializable {

private String content;
private CommentType commentType;
private Integer parentCommentId;
private int id;
private int threadId;
private IdentityRef author;
private Date publishedDate;
private Date lastUpdatedDate;
private Date lastContentUpdatedDate;
@JsonProperty("isDeleted")
private Boolean deleted;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean rather than Boolean?

private List<IdentityRef> usersLiked;
@JsonProperty("_links")
private ReferenceLinks links;

public Comment() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with other classes, can you confirm where this constructor is used, as I'd like the fields in this to be final if possible?

}

public Comment(String content) {
this.content = content;
this.parentCommentId = 0;
this.commentType = CommentType.TEXT;
}

/**
* The ID of the parent comment. This is used for replies.
*/
public Integer getParentCommentId() {
return this.parentCommentId;
}
/**
* The comment content.
*/
public String getContent() {
return this.content;
}
/**
* The comment type at the time of creation.
*/
public CommentType getCommentType() {
return this.commentType;
}
/**
* The comment ID. IDs start at 1 and are unique to a pull request.
*/
public int getId() {
return this.id;
}
/**
* The parent thread ID. Used for internal server purposes only -- note
* that this field is not exposed to the REST client.
*/
public int getThreadId() {
return this.threadId;
}
/**
* The author of the comment.
*/
public IdentityRef getAuthor() {
return this.author;
}
/**
* The date the comment was first published.;
*/
public Date getPublishedDate() {
return this.publishedDate;
}
/**
* The date the comment was last updated.
*/
public Date getLastUpdatedDate() {
return this.lastUpdatedDate;
}
/**
* The date the comment's content was last updated.
*/
public Date getLastContentUpdatedDate() {
return this.lastContentUpdatedDate;
}
/**
* Whether or not this comment was soft-deleted.
*/
public Boolean isDeleted() {
return this.deleted;
}
/**
* A list of the users who have liked this comment.
*/
public List<IdentityRef> getUsersLiked() {
return this.usersLiked;
}
/**
* Links to other related objects.
*/
public ReferenceLinks getLinks() {
return this.links;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.github.mc1arke.sonarqube.plugin.ce.pullrequest.azuredevops.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;

public class CommentPosition implements Serializable {
private final int line;
private final int offset;

@JsonCreator
public CommentPosition(@JsonProperty("line") int line, @JsonProperty("offset") int offset){
this.line = line;
this.offset = offset + 1;
}
/**
*The line number of a thread's position. Starts at 1. ///
*/
public int getLine()
{
return this.line;
};

/**
*The character offset of a thread's position inside of a line. Starts at 0.
*/
public int getOffset(){
return this.offset;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.github.mc1arke.sonarqube.plugin.ce.pullrequest.azuredevops.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.azuredevops.model.enums.CommentThreadStatus;
import org.sonar.db.protobuf.DbIssues;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
* Represents a comment thread of a pull request. A thread contains meta data about the file
* it was left on along with one or more comments (an initial comment and the subsequent replies).
*/
public class CommentThread implements Serializable {

private CommentThreadStatus status;
private List<Comment> comments;
private CommentThreadContext threadContext;
private int id;
private Date publishedDate;
private Date lastUpdatedDate;
private HashMap<String, IdentityRef> identities;
@JsonProperty("isDeleted")
private Boolean deleted;
@JsonProperty("_links")
private ReferenceLinks links;
public CommentThread(){};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this constructor used? In theory, all the fields above it should be final, but this constructor prevents that.


public CommentThread(String filePath, DbIssues.Locations locations, String message){
comments = Arrays.asList(
new Comment(message)
);
status = CommentThreadStatus.ACTIVE; //CommentThreadStatusMapper.toCommentThreadStatus(issue.status());
threadContext = new CommentThreadContext(
filePath,
locations
);

}
/**
* A list of the comments.
*/
public List<Comment> getComments(){
return this.comments;
};
/**
* The status of the comment thread.
*/
public CommentThreadStatus getStatus(){
return this.status;
};
/**
* Specify thread context such as position in left/right file.
*/
public CommentThreadContext getThreadContext() {
return this.threadContext;
};
/**
* The comment thread id.
*/
public int getId()
{
return this.id;
};
/**
* The time this thread was published.
*/
public Date getPublishedDate()
{
return this.publishedDate;
};
/**
* The time this thread was last updated.
*/
public Date getLastUpdatedDate()
{
return this.lastUpdatedDate;
};
/**
* Set of identities related to this thread
*/
public HashMap<String, IdentityRef> getIdentities()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we narrow this down to a Map rather than the implementation type of HashMap?

{
return this.identities;
};
/**
* Specify if the thread is deleted which happens when all comments are deleted.
*/
public Boolean isDeleted()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually nullable, or can it be a boolean?

{
return this.deleted;
};
/**
* Links to other related objects.
*/
public ReferenceLinks getLinks()
{
return this.links;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.github.mc1arke.sonarqube.plugin.ce.pullrequest.azuredevops.model;

import org.sonar.db.protobuf.DbIssues;

import java.io.Serializable;

public class CommentThreadContext implements Serializable {

private String filePath;
private CommentPosition leftFileStart;
private CommentPosition leftFileEnd;
private CommentPosition rightFileStart;
private CommentPosition rightFileEnd;

public CommentThreadContext() {};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, is this constructor actually required? I generally aim for the classes to be immutable but this constructor prevents the fields in this class from being declared final


public CommentThreadContext(String filePath, DbIssues.Locations locations){
this.filePath = filePath;
this.leftFileEnd = null;
this.leftFileStart = null;
this.rightFileEnd = new CommentPosition(
locations.getTextRange().getEndLine(),
locations.getTextRange().getEndOffset()
);
this.rightFileStart = new CommentPosition(
locations.getTextRange().getStartLine(),
locations.getTextRange().getStartOffset()
);
}
/**
* File path relative to the root of the repository. It's up to the client to
*/
public String getFilePath(){
return this.filePath;
};
/**
* Position of first character of the thread's span in left file. ///
*/
public CommentPosition getLeftFileStart(){
return this.leftFileStart;
};
/**
* Position of last character of the thread's span in left file. ///
*/
public CommentPosition getLeftFileEnd(){
return this.leftFileEnd;
};
/**
* Position of first character of the thread's span in right file. ///
*/
public CommentPosition getRightFileStart(){
return this.rightFileStart;
};
/**
* Position of last character of the thread's span in right file. ///
*/
public CommentPosition getRightFileEnd(){
return this.rightFileEnd;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.github.mc1arke.sonarqube.plugin.ce.pullrequest.azuredevops.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class CommentThreadResponse {
private final CommentThread[] value;

@JsonCreator
public CommentThreadResponse(@JsonProperty("value") CommentThread[] value){
this.value = value;
}
public CommentThread[] getValue(){
return this.value;
}
}
Loading