Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
C4tWithShell committed Apr 8, 2024
1 parent 67c6fb5 commit 08f2d79
Show file tree
Hide file tree
Showing 47 changed files with 72 additions and 38 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=mc1arke_sonarqube-community-branch-plugin&metric=alert_status)](https://sonarcloud.io/dashboard?id=mc1arke_sonarqube-community-branch-plugin)
[![Build Status](https://img.shields.io/github/actions/workflow/status/mc1arke/sonarqube-community-branch-plugin/.github/workflows/build.yml?branch=master&logo=github)](https://github.com/mc1arke/sonarqube-community-branch-plugin?workflow=build)
[![Build Status](https://img.shields.io/github/actions/workflow/status/soramitsu/soramitsu-sonarqube-community-branch-plugin/.github/workflows/build.yml?branch=master&logo=github)](https://github.com/mc1arke/sonarqube-community-branch-plugin?workflow=build)

# Sonarqube Community Branch Plugin

Expand All @@ -23,6 +22,12 @@ Use the following table to find the correct plugin version for each SonarQube ve

SonarQube Version | Plugin Version
------------------|---------------
10.4 | 1.17.2
10.3 | 1.16.1
10.2 | 1.16.0
10.1 | 1.15.0
10.0 | 1.15.0
9.9 (LTS) | 1.14.0
9.8+ | 1.14.0
9.7 | 1.13.0
9.1 - 9.6 | 1.12.0
Expand All @@ -35,6 +40,8 @@ SonarQube Version | Plugin Version
7.8 - 8.0 | 1.3.2
7.4 - 7.7 | 1.0.2

Older versions are listed on the Github release page but are no longer supported.

# Features

The plugin is intended to support the
Expand Down Expand Up @@ -71,6 +78,13 @@ __Note:__ If you're setting the `SONAR_WEB_JAVAADDITIONALOPTS` or `SONAR_CE_JAVA
your container launch then you'll need to add the `javaagent` configuration to your overrides to match what's in the
provided Dockerfile.

## Docker Compose

A `docker-compose.yml` file is provided.
It uses the env variables available in `.env`.

To use it, clone the repository and execute `docker-compose up`. Note that you need to have docker-compose installed in your system and added to your PATH

## Kubernetes with official Helm Chart

When using
Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ tasks.withType(JavaCompile) {
dependencies {
compileOnly(fileTree(dir: sonarLibraries, include: '**/*.jar', exclude: 'extensions/*.jar'))
testImplementation(fileTree(dir: sonarLibraries, include: '**/*.jar', exclude: 'extensions/*.jar'))
testImplementation('org.mockito:mockito-core:5.8.0')
testImplementation('org.assertj:assertj-core:3.25.1')
testImplementation('org.wiremock:wiremock:3.3.1')
testImplementation('org.mockito:mockito-core:5.11.0')
testImplementation('org.assertj:assertj-core:3.25.3')
testImplementation('org.wiremock:wiremock:3.5.2')
zip("sonarqube:sonarqube:${sonarqubeVersion}@zip")
implementation('org.bouncycastle:bcpkix-jdk15on:1.70')
implementation(files('lib/nodes-0.5.0.jar'))
runtimeOnly('com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.16.1')
runtimeOnly('com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.0')
compileOnly('com.google.code.findbugs:jsr305:3.0.2')
implementation('org.javassist:javassist:3.30.2-GA')
implementation('com.squareup.okhttp3:logging-interceptor:4.12.0')
testImplementation(platform('org.junit:junit-bom:5.10.1'))
testImplementation(platform('org.junit:junit-bom:5.10.2'))
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation('junit:junit:4.13.2')
testRuntimeOnly('org.junit.vintage:junit-vintage-engine')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class CheckRunDetails {
private final List<Annotation> annotations;
private final CheckConclusionState checkConclusionState;
private final int pullRequestId;
private final String projectKey;

private CheckRunDetails(Builder builder) {
summary = builder.summary;
Expand All @@ -49,6 +50,7 @@ private CheckRunDetails(Builder builder) {
annotations = builder.annotations;
checkConclusionState = builder.checkConclusionState;
pullRequestId = builder.pullRequestId;
projectKey = builder.projectKey;
}

public String getSummary() {
Expand Down Expand Up @@ -95,6 +97,10 @@ public int getPullRequestId() {
return pullRequestId;
}

public String getProjectKey() {
return projectKey;
}

public static Builder builder() {
return new Builder();
}
Expand All @@ -111,6 +117,7 @@ public static final class Builder {
private List<Annotation> annotations;
private CheckConclusionState checkConclusionState;
private int pullRequestId;
private String projectKey;

private Builder() {
super();
Expand Down Expand Up @@ -171,6 +178,11 @@ public Builder withPullRequestId(int pullRequestId) {
return this;
}

public Builder withProjectKey(String projectKey) {
this.projectKey = projectKey;
return this;
}

public CheckRunDetails build() {
return new CheckRunDetails(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,9 @@ public RepositoryAuthenticationToken getInstallationToken(String apiUrl, String

Instant issued = clock.instant().minus(10, ChronoUnit.SECONDS);
Instant expiry = issued.plus(2, ChronoUnit.MINUTES);
String jwtToken = new DefaultJwtBuilder()
.expiration(Date.from(expiry))
.issuedAt(Date.from(issued))
.claim("iss", appId)
.signWith(createPrivateKey(apiPrivateKey), Jwts.SIG.RS256)
.compact();
String jwtToken = new DefaultJwtBuilder().issuedAt(Date.from(issued)).expiration(Date.from(expiry))
.claim("iss", appId).signWith(createPrivateKey(apiPrivateKey), Jwts.SIG.RS256).compact();

Optional<RepositoryAuthenticationToken> repositoryAuthenticationToken = findTokenFromAppInstallationList(getV3Url(apiUrl) + "/app/installations", jwtToken, projectPath);

return repositoryAuthenticationToken.orElseThrow(() -> new InvalidConfigurationException(InvalidConfigurationException.Scope.PROJECT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ public static class CommentNode {
private final Actor author;
@GraphQLProperty(name = "isMinimized")
private final boolean minimized;
private final String body;

@JsonCreator
public CommentNode(@JsonProperty("id") String id, @JsonProperty("author") Actor author, @JsonProperty("isMinimized") boolean minimized) {
public CommentNode(@JsonProperty("id") String id, @JsonProperty("author") Actor author, @JsonProperty("isMinimized") boolean minimized, @JsonProperty("body") String body) {
this.id = id;
this.author = author;
this.minimized = minimized;
this.body = body;
}

public String getId() {
Expand All @@ -68,5 +70,9 @@ public Actor getAuthor() {
public boolean isMinimized() {
return minimized;
}

public String getBody() {
return body;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public String createCheckRun(CheckRunDetails checkRunDetails, boolean postSummar


if (postSummaryComment) {
postSummaryComment(graphqlUrl, headers, checkRunDetails.getPullRequestId(), checkRunDetails.getSummary());
postSummaryComment(graphqlUrl, headers, checkRunDetails.getPullRequestId(), checkRunDetails.getSummary(), checkRunDetails.getProjectKey());
}

return graphQLResponseEntity.getResponse().getCheckRun().getId();
Expand All @@ -128,7 +128,7 @@ public String getRepositoryUrl() {
return repositoryAuthenticationToken.getRepositoryUrl();
}

private void postSummaryComment(String graphqlUrl, Map<String, String> headers, int pullRequestKey, String summary) throws IOException {
private void postSummaryComment(String graphqlUrl, Map<String, String> headers, int pullRequestKey, String summary, String projectId) throws IOException {
String login = getLogin(graphqlUrl, headers);

GetRepository.PullRequest pullRequest = getPullRequest(graphqlUrl, headers, pullRequestKey);
Expand All @@ -137,6 +137,7 @@ private void postSummaryComment(String graphqlUrl, Map<String, String> headers,
getComments(pullRequest, graphqlUrl, headers, pullRequestKey).stream()
.filter(c -> "Bot".equalsIgnoreCase(c.getAuthor().getType()) && login.equalsIgnoreCase(c.getAuthor().getLogin()))
.filter(c -> !c.isMinimized())
.filter(c -> c.getBody().contains(String.format("**Project ID:** %s\r\n", projectId)))
.map(Comments.CommentNode::getId)
.forEach(commentId -> this.minimizeComment(graphqlUrl, headers, commentId));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public DecorationResult decorateQualityGateStatus(AnalysisDetails analysisDetail
.withExternalId(analysisDetails.getAnalysisId())
.withName(String.format("%s Sonarqube Results", analysisDetails.getAnalysisProjectName()))
.withTitle("Quality Gate " + (analysisDetails.getQualityGateStatus() == QualityGate.Status.OK ? "success" : "failed"))
.withProjectKey(analysisDetails.getAnalysisProjectKey())
.build();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public AnalysisIssueSummary createAnalysisIssueSummary(PostAnalysisIssueVisitor.
.withProjectKey(analysisDetails.getAnalysisProjectKey())
.withResolution(issue.resolution())
.withSeverity(issue.severity())
.withSeverityImageUrl(String.format("%s/checks/Severity/%s.svg?sanitize=true", baseImageUrl, issue.severity().toLowerCase()))
.withSeverityImageUrl(String.format("%s/checks/Severity/%s.png", baseImageUrl, issue.severity().toLowerCase()))
.withType(issue.type().name())
.withTypeImageUrl(String.format("%s/checks/IssueType/%s.svg?sanitize=true", baseImageUrl, issue.type().name().toLowerCase()))
.withTypeImageUrl(String.format("%s/checks/IssueType/%s.png", baseImageUrl, issue.type().name().toLowerCase()))
.build();
}

Expand Down Expand Up @@ -131,10 +131,10 @@ public AnalysisSummary createAnalysisSummary(AnalysisDetails analysisDetails) {
.withSummaryImageUrl(baseImageUrl + "/common/icon.png")
.withBugCount(issueCounts.get(RuleType.BUG))
.withBugUrl(getIssuesUrlForRuleType(analysisDetails, RuleType.BUG))
.withBugImageUrl(baseImageUrl + "/common/bug.svg?sanitize=true")
.withBugImageUrl(baseImageUrl + "/common/bug.png")
.withCodeSmellCount(issueCounts.get(RuleType.CODE_SMELL))
.withCodeSmellUrl(getIssuesUrlForRuleType(analysisDetails, RuleType.CODE_SMELL))
.withCodeSmellImageUrl(baseImageUrl + "/common/code_smell.svg?sanitize=true")
.withCodeSmellImageUrl(baseImageUrl + "/common/code_smell.png")
.withCoverage(coverage)
.withNewCoverage(newCoverage)
.withCoverageUrl(getComponentMeasuresUrlForCodeMetrics(analysisDetails, CoreMetrics.NEW_COVERAGE_KEY))
Expand All @@ -149,13 +149,13 @@ public AnalysisSummary createAnalysisSummary(AnalysisDetails analysisDetails) {
.collect(Collectors.toList()))
.withStatusDescription(QualityGate.Status.OK == analysisDetails.getQualityGateStatus() ? "Passed" : "Failed")
.withStatusImageUrl(QualityGate.Status.OK == analysisDetails.getQualityGateStatus()
? baseImageUrl + "/checks/QualityGateBadge/passed.svg?sanitize=true"
: baseImageUrl + "/checks/QualityGateBadge/failed.svg?sanitize=true")
? baseImageUrl + "/checks/QualityGateBadge/passed.png"
: baseImageUrl + "/checks/QualityGateBadge/failed.png")
.withTotalIssueCount(issueTotal)
.withSecurityHotspotCount(issueCounts.get(RuleType.SECURITY_HOTSPOT))
.withVulnerabilityCount(issueCounts.get(RuleType.VULNERABILITY))
.withVulnerabilityUrl(getIssuesUrlForRuleType(analysisDetails, RuleType.VULNERABILITY))
.withVulnerabilityImageUrl(baseImageUrl + "/common/vulnerability.svg?sanitize=true")
.withVulnerabilityImageUrl(baseImageUrl + "/common/vulnerability.png")
.build();
}

Expand Down Expand Up @@ -201,7 +201,7 @@ private String getDashboardUrl(AnalysisDetails analysisDetails) {

private static String createCoverageImage(BigDecimal coverage, String baseImageUrl) {
if (null == coverage) {
return baseImageUrl + "/checks/CoverageChart/NoCoverageInfo.svg?sanitize=true";
return baseImageUrl + "/checks/CoverageChart/NoCoverageInfo.png";
}
BigDecimal matchedLevel = BigDecimal.ZERO;
for (BigDecimal level : COVERAGE_LEVELS) {
Expand All @@ -210,12 +210,12 @@ private static String createCoverageImage(BigDecimal coverage, String baseImageU
break;
}
}
return baseImageUrl + "/checks/CoverageChart/" + matchedLevel + ".svg?sanitize=true";
return baseImageUrl + "/checks/CoverageChart/" + matchedLevel + ".png";
}

private static String createDuplicateImage(BigDecimal duplications, String baseImageUrl) {
if (null == duplications) {
return baseImageUrl + "/checks/Duplications/NoDuplicationInfo.svg?sanitize=true";
return baseImageUrl + "/checks/Duplications/NoDuplicationInfo.png";
}
String matchedLevel = "20plus";
for (DuplicationMapping level : DUPLICATION_LEVELS) {
Expand All @@ -224,7 +224,7 @@ private static String createDuplicateImage(BigDecimal duplications, String baseI
break;
}
}
return baseImageUrl + "/checks/Duplications/" + matchedLevel + ".svg?sanitize=true";
return baseImageUrl + "/checks/Duplications/" + matchedLevel + ".png";
}

private static String formatQualityGateCondition(QualityGate.Condition condition) {
Expand Down
Binary file added src/main/resources/static/checks/CoverageChart/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/Duplications/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/Duplications/20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/Duplications/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/Duplications/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/IssueType/bug.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/RatingBadge/A.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/RatingBadge/B.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/RatingBadge/C.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/RatingBadge/D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/RatingBadge/E.png
Binary file added src/main/resources/static/checks/Severity/info.png
Binary file added src/main/resources/static/checks/Severity/major.png
Binary file added src/main/resources/static/checks/Severity/minor.png
Binary file added src/main/resources/static/common/bug.png
Binary file added src/main/resources/static/common/code_smell.png
Binary file added src/main/resources/static/common/vulnerability.png
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ void verifyCheckRunSubmitsCorrectAnnotations() throws IOException {
" {" +
" \"id\": \"MDEyOklzc3VlQ29tbWVudDE1MDE3\"," +
" \"isMinimized\": false," +
" \"body\": \"**Project ID:** project-key-test\\r\\n\"," +
" \"author\": {" +
" \"__typename\": \"Bot\"," +
" \"login\": \"test-sonar\"" +
Expand Down Expand Up @@ -207,6 +208,7 @@ void verifyCheckRunSubmitsCorrectAnnotations() throws IOException {
.withName("Name")
.withTitle("Title")
.withPullRequestId(999)
.withProjectKey("project-key-test")
.build();


Expand Down Expand Up @@ -299,7 +301,7 @@ void verifyCheckRunSubmitsCorrectAnnotations() throws IOException {
assertEquals(requestEntities.get(2), getPullRequestRequestEntityArgumentCaptor.getValue());
assertEquals(
"query { repository (owner:\"owner\",name:\"repository\") { url pullRequest : pullRequest (number:999) { comments : comments (first:100) { nodes" +
" { author { type : __typename login } id minimized : isMinimized } pageInfo { hasNextPage endCursor } } id } } } ",
" { author { type : __typename login } id minimized : isMinimized body } pageInfo { hasNextPage endCursor } } id } } } ",
getPullRequestRequestEntityArgumentCaptor.getValue().getRequest()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ void verifyCorrectArgumentsAndReturnValuesUsed() throws IOException {
.withSeverity(i % 5 < 1 ? CheckAnnotationLevel.NOTICE : i % 5 > 2 ? CheckAnnotationLevel.FAILURE : CheckAnnotationLevel.WARNING)
.build()).collect(Collectors.toList()))
.withCheckConclusionState(CheckConclusionState.SUCCESS)
.withProjectKey(analysisDetails.getAnalysisProjectKey())
.build());
assertThat(decorationResult).usingRecursiveComparison().isEqualTo(expectedResult);
}
Expand Down
Loading

0 comments on commit 08f2d79

Please sign in to comment.