Skip to content

Commit

Permalink
Initiate release 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
albibanushi committed Jun 7, 2024
1 parent 66f5195 commit c5aac79
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ SONARQUBE_VERSION=10.4-community
DOCKERFILE=release.Dockerfile

# The version of the plugin to include in the image
PLUGIN_VERSION=1.19.3
PLUGIN_VERSION=1.19.4
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class GitlabMergeRequestDecorator extends DiscussionAwarePullRequestDecor
"com.github.mc1arke.sonarqube.plugin.branch.pullrequest.gitlab.pipelineId";
public static final String PULLREQUEST_GITLAB_DONT_FAIL_PIPELINE =
"sonar.analysis.com.github.mc1arke.sonarqube.plugin.branch.pullrequest.gitlab.dontFailPipeline";

private final GitlabClientFactory gitlabClientFactory;
private final MarkdownFormatterFactory formatterFactory;

Expand Down Expand Up @@ -123,11 +123,14 @@ protected void submitPipelineStatus(GitlabClient gitlabClient, MergeRequest merg
Long pipelineId = analysis.getScannerProperty(PULLREQUEST_GITLAB_PIPELINE_ID)
.map(Long::parseLong)
.orElse(null);

boolean dontFailPipeline = analysis.getScannerProperty(PULLREQUEST_GITLAB_DONT_FAIL_PIPELINE)
.map(Boolean::parseBoolean)
.orElse(false);

try {
PipelineStatus pipelineStatus = new PipelineStatus("SonarQube",
"SonarQube Status",
analysis.getQualityGateStatus() == QualityGate.Status.OK ? PipelineStatus.State.SUCCESS : PipelineStatus.State.FAILED,
analysis.getQualityGateStatus() == QualityGate.Status.OK || dontFailPipeline ? PipelineStatus.State.SUCCESS : PipelineStatus.State.FAILED,
analysisSummary.getDashboardUrl(),
analysisSummary.getNewCoverage(),
pipelineId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,38 @@ public void shouldSubmitFailedPipelineStatusAndUnresolvedSummaryCommentOnFailedA
PipelineStatus.State.FAILED, "https://sonarqube2.dummy/dashboard?id=" + PROJECT_KEY + "&pullRequest=" + MERGE_REQUEST_IID, BigDecimal.TEN, 11L));
}

@Test //https://github.com/mc1arke/sonarqube-community-branch-plugin/issues/137
public void shouldSubmitPassedPipelineStatusIfPipelineFailingIsDisabledAndUnresolvedSummaryCommentOnFailedAnalysis() throws IOException {
when(analysisDetails.getQualityGateStatus()).thenReturn(QualityGate.Status.ERROR);
when(analysisDetails.getCommitSha()).thenReturn("other sha");
when(analysisDetails.getScannerProperty("com.github.mc1arke.sonarqube.plugin.branch.pullrequest.gitlab.pipelineId")).thenReturn(Optional.of("11"));
when(analysisDetails.getScannerProperty("com.github.mc1arke.sonarqube.plugin.branch.pullrequest.gitlab.dontFailPipeline")).thenReturn(Optional.of("true"));

when(analysisSummary.format(any())).thenReturn("Different Summary comment");
when(analysisSummary.getDashboardUrl()).thenReturn("https://sonarqube2.dummy/dashboard?id=projectKey&pullRequest=123");
when(analysisSummary.getNewCoverage()).thenReturn(BigDecimal.TEN);

Discussion discussion = mock(Discussion.class);
when(discussion.getId()).thenReturn("dicussion id 2");
when(gitlabClient.addMergeRequestDiscussion(anyLong(), anyLong(), any())).thenReturn(discussion);

underTest.decorateQualityGateStatus(analysisDetails, almSettingDto, projectAlmSettingDto);

ArgumentCaptor<MergeRequestNote> mergeRequestNoteArgumentCaptor = ArgumentCaptor.forClass(MergeRequestNote.class);
verify(gitlabClient).addMergeRequestDiscussion(eq(PROJECT_ID), eq(MERGE_REQUEST_IID), mergeRequestNoteArgumentCaptor.capture());
verify(gitlabClient, never()).resolveMergeRequestDiscussion(PROJECT_ID, MERGE_REQUEST_IID, discussion.getId());
ArgumentCaptor<PipelineStatus> pipelineStatusArgumentCaptor = ArgumentCaptor.forClass(PipelineStatus.class);
verify(gitlabClient).setMergeRequestPipelineStatus(eq(PROJECT_ID), eq("other sha"), pipelineStatusArgumentCaptor.capture());

assertThat(mergeRequestNoteArgumentCaptor.getValue())
.usingRecursiveComparison()
.isEqualTo(new MergeRequestNote("Different Summary comment"));
assertThat(pipelineStatusArgumentCaptor.getValue())
.usingRecursiveComparison()
.isEqualTo(new PipelineStatus("SonarQube", "SonarQube Status",
PipelineStatus.State.SUCCESS, "https://sonarqube2.dummy/dashboard?id=" + PROJECT_KEY + "&pullRequest=" + MERGE_REQUEST_IID, BigDecimal.TEN, 11L));
}

@Test
public void shouldThrowErrorWhenSubmitPipelineStatusToGitlabFails() throws IOException {
when(analysisDetails.getQualityGateStatus()).thenReturn(QualityGate.Status.ERROR);
Expand Down

0 comments on commit c5aac79

Please sign in to comment.