import { useAsync } from 'react-use' ; import { Octokit } from '@octokit/rest' ; import { useApi , githubAuthApiRef } from '@backstage/core-plugin-api' ; import { useEntityGithubScmIntegration } from './useEntityGithubScmIntegration' ; import { ContributorData } from '../components/types' ; import { useEntity } from '@backstage/plugin-catalog-react' ; export const useContributor = ( username ) => { const auth = useApi ( githubAuthApiRef ) ; const { entity } = useEntity ( ) ; const { baseUrl } = useEntityGithubScmIntegration ( entity ) ; const { value , loading , error } = useAsync ( async ( ) : Promise < ContributorData > => { const token = await auth . getAccessToken ( [ 'repo' ] ) ; const octokit = new Octokit ( { auth : token } ) ; const response = await octokit . request ( `GET /users/${ username }` , { baseUrl , } ) ; const data = response . data ; return data ; } , [ username , baseUrl ] ) ; return { contributor : value , loading , error , } ; } ;