mirror of
https://github.com/mc1arke/sonarqube-community-branch-plugin.git
synced 2025-02-21 19:20:09 +02:00
#785: Only minimise Github summary comments with same project key
The Github decorator was not checking the project key listed against a summary comment so was minimising all summary comments when performing multiple decorations against a mono-repository. To overcome this, the contents of the summary comments are being retrieved and only the ones with a project key matching the current project are being minimised during decoration.
This commit is contained in:
parent
e039e72fb3
commit
8f014bc970
@ -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;
|
||||
@ -49,6 +50,7 @@ public class CheckRunDetails {
|
||||
annotations = builder.annotations;
|
||||
checkConclusionState = builder.checkConclusionState;
|
||||
pullRequestId = builder.pullRequestId;
|
||||
projectKey = builder.projectKey;
|
||||
}
|
||||
|
||||
public String getSummary() {
|
||||
@ -95,6 +97,10 @@ public class CheckRunDetails {
|
||||
return pullRequestId;
|
||||
}
|
||||
|
||||
public String getProjectKey() {
|
||||
return projectKey;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
@ -111,6 +117,7 @@ public class CheckRunDetails {
|
||||
private List<Annotation> annotations;
|
||||
private CheckConclusionState checkConclusionState;
|
||||
private int pullRequestId;
|
||||
private String projectKey;
|
||||
|
||||
private Builder() {
|
||||
super();
|
||||
@ -171,6 +178,11 @@ public class CheckRunDetails {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withProjectKey(String projectKey) {
|
||||
this.projectKey = projectKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CheckRunDetails build() {
|
||||
return new CheckRunDetails(this);
|
||||
}
|
||||
|
@ -49,12 +49,14 @@ public class Comments {
|
||||
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() {
|
||||
@ -68,5 +70,9 @@ public class Comments {
|
||||
public boolean isMinimized() {
|
||||
return minimized;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ public class GraphqlGithubClient implements GithubClient {
|
||||
|
||||
|
||||
if (postSummaryComment) {
|
||||
postSummaryComment(graphqlUrl, headers, checkRunDetails.getPullRequestId(), checkRunDetails.getSummary());
|
||||
postSummaryComment(graphqlUrl, headers, checkRunDetails.getPullRequestId(), checkRunDetails.getSummary(), checkRunDetails.getProjectKey());
|
||||
}
|
||||
|
||||
return graphQLResponseEntity.getResponse().getCheckRun().getId();
|
||||
@ -128,7 +128,7 @@ public class GraphqlGithubClient implements GithubClient {
|
||||
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);
|
||||
@ -137,6 +137,7 @@ public class GraphqlGithubClient implements GithubClient {
|
||||
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));
|
||||
|
||||
|
@ -79,6 +79,7 @@ public class GithubPullRequestDecorator implements PullRequestBuildStatusDecorat
|
||||
.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 {
|
||||
|
@ -159,6 +159,7 @@ class GraphqlGithubClientTest {
|
||||
" {" +
|
||||
" \"id\": \"MDEyOklzc3VlQ29tbWVudDE1MDE3\"," +
|
||||
" \"isMinimized\": false," +
|
||||
" \"body\": \"**Project ID:** project-key-test\\r\\n\"," +
|
||||
" \"author\": {" +
|
||||
" \"__typename\": \"Bot\"," +
|
||||
" \"login\": \"test-sonar\"" +
|
||||
@ -207,6 +208,7 @@ class GraphqlGithubClientTest {
|
||||
.withName("Name")
|
||||
.withTitle("Title")
|
||||
.withPullRequestId(999)
|
||||
.withProjectKey("project-key-test")
|
||||
.build();
|
||||
|
||||
|
||||
@ -299,7 +301,7 @@ class GraphqlGithubClientTest {
|
||||
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()
|
||||
);
|
||||
|
||||
|
@ -147,6 +147,7 @@ class GithubPullRequestDecoratorTest {
|
||||
.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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user