import { errorApiRef , useApi } from '@backstage/core-plugin-api' ; import { useAsyncFn } from 'react-use' ; import { buildKiteApiRef } from '../api' ; export const useSingleBuild = ( { owner , repo , buildNumber } ) => { const api = useApi ( buildKiteApiRef ) ; const errorApi = useApi ( errorApiRef ) ; const [ state , fetchBuildData ] = useAsyncFn ( async ( ) => { try { return await api . getSingleBuild ( owner , repo , buildNumber ) ; } catch ( e ) { errorApi . post ( e ) ; return Promise . reject ( e ) ; } } , [ ] ) ; return { loading : state . loading , value : state . value , error : state . error , fetchBuildData , } ; } ;