From 47a6ff7f71b3db4dd28d0fb6770bc47d79a91b69 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Wed, 20 Jan 2021 19:40:50 -0500 Subject: [PATCH 1/3] Add fields and reword card --- .../jenkins/src/components/Cards/Cards.tsx | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/plugins/jenkins/src/components/Cards/Cards.tsx b/plugins/jenkins/src/components/Cards/Cards.tsx index 31acedc180..447afff266 100644 --- a/plugins/jenkins/src/components/Cards/Cards.tsx +++ b/plugins/jenkins/src/components/Cards/Cards.tsx @@ -14,6 +14,7 @@ * limitations under the License. */ import React from 'react'; +import { DateTime, Duration } from 'luxon'; import { Link, Theme, makeStyles, LinearProgress } from '@material-ui/core'; import { InfoCard, StructuredMetadataTable } from '@backstage/core'; import ExternalLinkIcon from '@material-ui/icons/Launch'; @@ -30,28 +31,37 @@ const useStyles = makeStyles({ const WidgetContent = ({ loading, - lastRun, + latestRun, }: { loading?: boolean; - lastRun: any; + latestRun: any; branch: string; }) => { const classes = useStyles(); - if (loading || !lastRun) return ; - + if (loading || !latestRun) return ; + const displayDate = DateTime.fromMillis(latestRun.timestamp).toRelative(); + // TODO This works, but hard codes as minutes. Would prefer something smarter/relative. + const durationInMinutes = Math.round( + Duration.fromMillis(latestRun.duration).as('minutes'), + ); + const displayDuration = `${durationInMinutes} minute${ + durationInMinutes > 1 ? 's' : '' + }`; return ( ), - build: lastRun.fullDisplayName, - url: ( - + build: latestRun.fullDisplayName, + 'latest run': displayDate, + duration: displayDuration, + link: ( + See more on Jenkins{' '} @@ -70,10 +80,10 @@ export const LatestRunCard = ({ }) => { const { owner, repo } = useProjectSlugFromEntity(); const [{ builds, loading }] = useBuilds(owner, repo, branch); - const lastRun = builds ?? {}; + const latestRun = builds ?? {}; return ( - - + + ); }; From 04268e9fb7bc2ea6cca71871bb9dbfba13a111d6 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Wed, 20 Jan 2021 19:41:03 -0500 Subject: [PATCH 2/3] Add Luxon date library --- plugins/jenkins/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/jenkins/package.json b/plugins/jenkins/package.json index f8c0b3fd76..3e552c7dc9 100644 --- a/plugins/jenkins/package.json +++ b/plugins/jenkins/package.json @@ -39,6 +39,7 @@ "@material-ui/icons": "^4.9.1", "@material-ui/lab": "4.0.0-alpha.45", "jenkins": "^0.28.0", + "luxon": "^1.25.0", "react": "^16.13.1", "react-dom": "^16.13.1", "react-router": "6.0.0-beta.0", From 9f8faed258dd6ae659b1a34e6e4ac8270c17449c Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Wed, 20 Jan 2021 19:42:44 -0500 Subject: [PATCH 3/3] Add changeset --- .changeset/unlucky-jokes-grab.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/unlucky-jokes-grab.md diff --git a/.changeset/unlucky-jokes-grab.md b/.changeset/unlucky-jokes-grab.md new file mode 100644 index 0000000000..a7394c9f1f --- /dev/null +++ b/.changeset/unlucky-jokes-grab.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-jenkins': patch +--- + +Update Jenkins card with build date, duration, and rename card to "latest" build.