Skip to content

Commit

Permalink
Add PR Decoration Support for Azure DevOps Server
Browse files Browse the repository at this point in the history
fixing space in url

fix PR URL

SonarCloud fixes

fix spacing issue
  • Loading branch information
Jeff Boccuzzi committed Jul 27, 2020
1 parent f624269 commit 05142e9
Show file tree
Hide file tree
Showing 25 changed files with 1,811 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
*.iml

#Project libs
/sonarqube-lib/
/sonarqube-lib/

#VSCode
.project
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
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.BitbucketPullRequestDecorator;
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.GithubPullRequestDecorator;
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.v3.DefaultLinkHeaderReader;
Expand All @@ -41,7 +42,8 @@ public List<Object> getComponents() {
return Arrays.asList(CommunityBranchLoaderDelegate.class, PullRequestPostAnalysisTask.class,
PostAnalysisIssueVisitor.class, GithubPullRequestDecorator.class,
GraphqlCheckRunProvider.class, DefaultLinkHeaderReader.class, RestApplicationAuthenticationProvider.class,
BitbucketPullRequestDecorator.class, GitlabServerPullRequestDecorator.class);
BitbucketPullRequestDecorator.class, GitlabServerPullRequestDecorator.class,
AzureDevOpsServerPullRequestDecorator.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@

public class AnalysisDetails {

public static final String SCANNERROPERTY_PULLREQUEST_BRANCH = "sonar.pullrequest.branch";
public static final String SCANNERROPERTY_PULLREQUEST_BASE = "sonar.pullrequest.base";
public static final String SCANNERROPERTY_PULLREQUEST_KEY = "sonar.pullrequest.key";

private static final List<String> CLOSED_ISSUE_STATUS = Arrays.asList(Issue.STATUS_CLOSED, Issue.STATUS_RESOLVED);

private static final List<BigDecimal> COVERAGE_LEVELS =
Expand Down Expand Up @@ -116,11 +120,27 @@ public String getDashboardUrl() {
public String getIssueUrl(String issueKey) {
return publicRootURL + "/project/issues?id=" + encode(project.getKey()) + "&pullRequest=" + branchDetails.getBranchName() + "&issues=" + issueKey + "&open=" + issueKey;
}

public Optional<String> getPullRequestBase() {
return Optional.ofNullable(scannerContext.getProperties().get(SCANNERROPERTY_PULLREQUEST_BASE));
}

public Optional<String> getPullRequestBranch() {
return Optional.ofNullable(scannerContext.getProperties().get(SCANNERROPERTY_PULLREQUEST_BRANCH));
}

public Optional<String> getPullRequestKey() {
return Optional.ofNullable(scannerContext.getProperties().get(SCANNERROPERTY_PULLREQUEST_KEY));
}

public QualityGate.Status getQualityGateStatus() {
return qualityGate.getStatus();
}

public String getRuleUrlWithRuleKey(String ruleKey) {
return publicRootURL + "/coding_rules?open=" + encode(ruleKey) + "&rule_key=" + encode(ruleKey);
}

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,66 @@
package com.github.mc1arke.sonarqube.plugin.ce.pullrequest.azuredevops.model;

import java.util.Base64;
import java.nio.charset.StandardCharsets;

public class AzurePullRequestDetails {

public static final String API_VERSION_PREFIX = "?api-version=";
private final String apiVersion;
private final String authorizationHeader;
private final String azureRepositoryName;
private final String azureProjectId;
private final String azureUrl;
private final String baseBranch;
private final String branch;
private final String pullRequestId;

public AzurePullRequestDetails(String apiVersion, String azureRepositoryName, String azureProjectId, String azureUrl,
String baseBranch, String branch, String personalAccessToken, String pullRequestId) {
this.apiVersion = apiVersion;
this.authorizationHeader = generateAuthorizationHeader(personalAccessToken);
this.azureRepositoryName = azureRepositoryName;
this.azureProjectId = azureProjectId;
this.azureUrl = azureUrl;
this.baseBranch = baseBranch;
this.branch = branch;
this.pullRequestId = pullRequestId;
}

private static String generateAuthorizationHeader(String apiToken) {
String encodeBytes = Base64.getEncoder().encodeToString((":" + apiToken).getBytes(StandardCharsets.UTF_8));
return "Basic " + encodeBytes;
}

public String getApiVersion() {
return API_VERSION_PREFIX + this.apiVersion;
}

public String getAuthorizationHeader() {
return this.authorizationHeader;
}

public String getAzureRepositoryName() {
return this.azureRepositoryName;
}

public String getAzureProjectId() {
return this.azureProjectId;
}

public String getAzureUrl() {
return this.azureUrl;
}

public String getBaseBranch() {
return this.baseBranch;
}

public String getBranch() {
return this.branch;
}

public String getPullRequestId() {
return this.pullRequestId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package com.github.mc1arke.sonarqube.plugin.ce.pullrequest.azuredevops.model;

import com.fasterxml.jackson.annotation.JsonCreator;
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 final String content;
private final CommentType commentType;
private final Integer parentCommentId;
private final int id;
private final int threadId;
private final IdentityRef author;
private final Date publishedDate;
private final Date lastUpdatedDate;
private final Date lastContentUpdatedDate;
@JsonProperty("isDeleted")
private final boolean deleted;
private final List<IdentityRef> usersLiked;
@JsonProperty("_links")
private final ReferenceLinks links;

@JsonCreator
public Comment(@JsonProperty("content") String content,
@JsonProperty("commentType") CommentType commentType,
@JsonProperty("parentCommentId") Integer parentCommentId,
@JsonProperty("id") int id,
@JsonProperty("threadId") int threadId,
@JsonProperty("author") IdentityRef author,
@JsonProperty("publishedDate") Date publishedDate,
@JsonProperty("lastUpdatedDate") Date lastUpdatedDate,
@JsonProperty("lastContentUpdatedDate") Date lastContentUpdatedDate,
@JsonProperty("isDeleted") boolean deleted,
@JsonProperty("usersLiked") List<IdentityRef> usersLiked,
@JsonProperty("_links") ReferenceLinks links) {

this.content = content;
this.commentType = commentType;
this.parentCommentId = parentCommentId;
this.id = id;
this.threadId = threadId;
this.author = author;
this.publishedDate = publishedDate;
this.lastUpdatedDate = lastUpdatedDate;
this.lastContentUpdatedDate = lastContentUpdatedDate;
this.deleted = deleted;
this.usersLiked = usersLiked;
this.links = links;
}

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

this.id = 0;
this.threadId = 0;
this.author = null;
this.publishedDate = null;
this.lastUpdatedDate = null;
this.lastContentUpdatedDate = null;
this.deleted = false;
this.usersLiked = null;
this.links = null;
}

/**
* 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,32 @@
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;
}
}
Loading

0 comments on commit 05142e9

Please sign in to comment.