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. diff --git a/plugins/jenkins/package.json b/plugins/jenkins/package.json index 20ece04620..74a4723450 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", 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 ( - - + + ); };