Skip to content

Commit

Permalink
fix: Add project name to GitHub check for monorepos
Browse files Browse the repository at this point in the history
  • Loading branch information
jackylamhk committed Nov 25, 2024
1 parent 4cdc277 commit 7bb3e70
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

public class GithubPullRequestDecorator implements PullRequestBuildStatusDecorator {

private static final String DEFAULT_CHECK_RUN_NAME = "SonarQube Code Analysis";
private final GithubClientFactory githubClientFactory;
private final ReportGenerator reportGenerator;
private final MarkdownFormatterFactory markdownFormatterFactory;
Expand All @@ -71,7 +72,8 @@ public DecorationResult decorateQualityGateStatus(AnalysisDetails analysisDetail
GitHub github = githubClientFactory.createClient(almSettingDto, projectAlmSettingDto);
GHRepository repository = github.getRepository(projectAlmSettingDto.getAlmRepo());

GHPullRequest pullRequest = createCheckRun(repository, analysisDetails, Optional.ofNullable(projectAlmSettingDto.getSummaryCommentEnabled()).orElse(false));
GHPullRequest pullRequest = createCheckRun(repository, analysisDetails, projectAlmSettingDto.getMonorepo(),
Optional.ofNullable(projectAlmSettingDto.getSummaryCommentEnabled()).orElse(false));

return DecorationResult.builder()
.withPullRequestUrl(pullRequest.getHtmlUrl().toExternalForm())
Expand All @@ -88,7 +90,8 @@ public List<ALM> alm() {
}


private GHPullRequest createCheckRun(GHRepository repository, AnalysisDetails analysisDetails, boolean postSummaryComment) throws IOException {
private GHPullRequest createCheckRun(GHRepository repository, AnalysisDetails analysisDetails,
boolean isMonorepo, boolean postSummaryComment) throws IOException {
AnalysisSummary analysisSummary = reportGenerator.createAnalysisSummary(analysisDetails);
String summary = analysisSummary.format(markdownFormatterFactory);

Expand All @@ -102,7 +105,10 @@ private GHPullRequest createCheckRun(GHRepository repository, AnalysisDetails an
);
}

repository.createCheckRun("SonarQube Code Analysis", analysisDetails.getCommitSha())
String checkRunName = isMonorepo
? String.format("[%s] %s", analysisDetails.getAnalysisProjectKey(), DEFAULT_CHECK_RUN_NAME)
: DEFAULT_CHECK_RUN_NAME;
repository.createCheckRun(checkRunName, analysisDetails.getCommitSha())
.withStartedAt(analysisDetails.getAnalysisDate())
.withCompletedAt(Date.from(clock.instant()))
.withStatus(GHCheckRun.Status.COMPLETED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class GithubPullRequestDecoratorTest {
@BeforeEach
void setUp() throws IOException {
when(projectAlmSettingDto.getAlmRepo()).thenReturn("alm-repo");
when(projectAlmSettingDto.getMonorepo()).thenReturn(false);
when(analysisDetails.getPullRequestId()).thenReturn("123");
when(analysisDetails.getAnalysisDate()).thenReturn(Date.from(clock.instant()));
when(analysisDetails.getAnalysisId()).thenReturn("analysis-id");
Expand Down

0 comments on commit 7bb3e70

Please sign in to comment.