From cd62d9c9efc15c90df77242059b98bdaa4f39a43 Mon Sep 17 00:00:00 2001 From: Gabriel Feo Date: Thu, 25 Apr 2024 17:38:12 +0100 Subject: [PATCH] Improve job summary readability with long tasks Change tests for nbsp and concise badge Make tests pass Signed-off-by: Gabriel Feo --- sources/src/job-summary.ts | 55 +++++++++++++++++++-------- sources/test/jest/job-summary.test.ts | 26 ++++++------- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/sources/src/job-summary.ts b/sources/src/job-summary.ts index adac66d..afaefff 100644 --- a/sources/src/job-summary.ts +++ b/sources/src/job-summary.ts @@ -113,7 +113,7 @@ function renderBuildResults(results: BuildResult[]): string { Requested Tasks Gradle Version Build Outcome - Build Scan® + Build Scan® ${results.map(result => renderBuildResultRow(result)).join('')} ` @@ -134,23 +134,46 @@ function renderOutcome(result: BuildResult): string { return result.buildFailed ? ':x:' : ':white_check_mark:' } -function renderBuildScan(result: BuildResult): string { - if (result.buildScanFailed) { - return renderBuildScanBadge( - 'PUBLISH_FAILED', - 'orange', - 'https://docs.gradle.com/develocity/gradle-plugin/#troubleshooting' - ) - } - if (result.buildScanUri) { - return renderBuildScanBadge('PUBLISHED', '06A0CE', result.buildScanUri) - } - return renderBuildScanBadge('NOT_PUBLISHED', 'lightgrey', 'https://scans.gradle.com') +interface BadgeSpec { + text: string + alt: string + color: string + logo: boolean + targetUrl: string } -function renderBuildScanBadge(outcomeText: string, outcomeColor: string, targetUrl: string): string { - const badgeUrl = `https://img.shields.io/badge/Build%20Scan%C2%AE-${outcomeText}-${outcomeColor}?logo=Gradle` - const badgeHtml = `Build Scan ${outcomeText}` +function renderBuildScan(result: BuildResult): string { + if (result.buildScanFailed) { + return renderBuildScanBadge({ + text: 'Publish failed', + alt: 'Build Scan publish failed', + color: 'orange', + logo: false, + targetUrl: 'https://docs.gradle.com/develocity/gradle-plugin/#troubleshooting' + }) + } + if (result.buildScanUri) { + return renderBuildScanBadge({ + text: 'Build Scan®', + alt: 'Build Scan published', + color: '06A0CE', + logo: true, + targetUrl: result.buildScanUri + }) + } + return renderBuildScanBadge({ + text: 'Not published', + alt: 'Build Scan not published', + color: 'lightgrey', + logo: false, + targetUrl: 'https://scans.gradle.com' + }) +} + +function renderBuildScanBadge({text, alt, color, logo, targetUrl}: BadgeSpec): string { + const encodedText = encodeURIComponent(text) + const badgeUrl = `https://img.shields.io/badge/${encodedText}-${color}${logo ? '?logo=Gradle' : ''}` + const badgeHtml = `${alt}` return `${badgeHtml}` } diff --git a/sources/test/jest/job-summary.test.ts b/sources/test/jest/job-summary.test.ts index c38021e..91cffa2 100644 --- a/sources/test/jest/job-summary.test.ts +++ b/sources/test/jest/job-summary.test.ts @@ -47,14 +47,14 @@ describe('renderSummaryTable', () => { Requested Tasks Gradle Version Build Outcome - Build Scan® + Build Scan® root help 8.0 :white_check_mark: - Build Scan PUBLISHED + Build Scan published `); @@ -68,14 +68,14 @@ describe('renderSummaryTable', () => { Requested Tasks Gradle Version Build Outcome - Build Scan® + Build Scan® root help 8.0 :x: - Build Scan PUBLISHED + Build Scan published `); @@ -90,14 +90,14 @@ describe('renderSummaryTable', () => { Requested Tasks Gradle Version Build Outcome - Build Scan® + Build Scan® root help 8.0 :white_check_mark: - Build Scan NOT_PUBLISHED + Build Scan not published `); @@ -111,14 +111,14 @@ describe('renderSummaryTable', () => { Requested Tasks Gradle Version Build Outcome - Build Scan® + Build Scan® root help 8.0 :white_check_mark: - Build Scan PUBLISH_FAILED + Build Scan publish failed `); @@ -133,21 +133,21 @@ describe('renderSummaryTable', () => { Requested Tasks Gradle Version Build Outcome - Build Scan® + Build Scan® root help 8.0 :white_check_mark: - Build Scan PUBLISHED + Build Scan published root help 8.0 :x: - Build Scan PUBLISHED + Build Scan published `); @@ -161,14 +161,14 @@ describe('renderSummaryTable', () => { Requested Tasks Gradle Version Build Outcome - Build Scan® + Build Scan® root
check publishMyLongNamePluginPublicationToMavenCentral publ…
8.0 :white_check_mark: - Build Scan PUBLISHED + Build Scan published `);