Skip to content

Commit

Permalink
Fix detection of previous PR annotation comments
Browse files Browse the repository at this point in the history
MarkdownFormatterFactory uses System.lineSeparator() as the end-of-line
character for annotation comments.

GraphqlGithubClient.postSummaryComment(), however, uses hardcoded \r\n
as end-of-line character, so it isn't able to match legitimate comments
if SonarQube is not running on Windows.

This change updates GraphqlGithubClient to also use system end-of-line
char.
  • Loading branch information
GreyTeardrop committed Apr 17, 2024
1 parent 425db80 commit c7f801f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ private void postSummaryComment(String graphqlUrl, Map<String, String> headers,

GetRepository.PullRequest pullRequest = getPullRequest(graphqlUrl, headers, pullRequestKey);
String pullRequestId = pullRequest.getId();
String projectCommentMarker = String.format("**Project ID:** %s%n", projectId);

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)))
.filter(c -> c.getBody().contains(projectCommentMarker))
.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 @@ -148,6 +148,7 @@ void verifyCheckRunSubmitsCorrectAnnotations() throws IOException {
ArgumentCaptor<GraphQLRequestEntity> getViewer = ArgumentCaptor.forClass(GraphQLRequestEntity.class);
when(graphQLTemplate.query(getViewer.capture(), eq(Viewer.class))).thenReturn(viewerResponseEntity);

String bodyString = objectMapper.writeValueAsString("**Project ID:** project-key-test" + System.lineSeparator());
GraphQLResponseEntity<GetRepository> getPullRequestResponseEntity =
objectMapper.readValue("{" +
"\"response\": " +
Expand All @@ -159,7 +160,7 @@ void verifyCheckRunSubmitsCorrectAnnotations() throws IOException {
" {" +
" \"id\": \"MDEyOklzc3VlQ29tbWVudDE1MDE3\"," +
" \"isMinimized\": false," +
" \"body\": \"**Project ID:** project-key-test\\r\\n\"," +
" \"body\": " + bodyString + "," +
" \"author\": {" +
" \"__typename\": \"Bot\"," +
" \"login\": \"test-sonar\"" +
Expand Down

0 comments on commit c7f801f

Please sign in to comment.