import { constants } from '@devhub/core' ; import { EMPTY_OBJ } from '../../../utils/constants' ; import { RootState } from '../../types' ; import { installationTokenByOwnerSelector } from './installations' ; const s = ( state ) => ( state . github && state . github . auth ) || EMPTY_OBJ ; export const githubAppTokenDetailsSelector = ( state ) => ( constants . ENABLE_GITHUB_APP_SUPPORT && s ( state ) . app ) || undefined ; export const githubAppTokenSelector = ( state ) => { const tokenDetails = githubAppTokenDetailsSelector ( state ) ; return ( tokenDetails && tokenDetails . token ) || undefined ; } ; export const githubOAuthTokenDetailsSelector = ( state ) => ( constants . ENABLE_GITHUB_OAUTH_SUPPORT && s ( state ) . oauth ) || undefined ; export const githubPersonalTokenDetailsSelector = ( state ) => ( constants . ENABLE_GITHUB_PERSONAL_ACCESS_TOKEN_SUPPORT && s ( state ) . personal ) || undefined ; export const githubTokenDetailsSelector = ( state ) => { const githubPersonalTokenDetails = githubPersonalTokenDetailsSelector ( state ) ; if ( githubPersonalTokenDetails ?. token ) return githubPersonalTokenDetails ; const githubOAuthTokenDetails = githubOAuthTokenDetailsSelector ( state ) ; if ( githubOAuthTokenDetails ?. token ) return githubOAuthTokenDetails ; return undefined ; } ; export const githubTokenSelector = ( state ) => { const tokenDetails = githubTokenDetailsSelector ( state ) ; return ( tokenDetails && tokenDetails . token ) || undefined ; } ; export const githubTokenTypeSelector = ( state ) => { const tokenDetails = githubTokenDetailsSelector ( state ) ; return ( tokenDetails && tokenDetails . tokenType ) || undefined ; } ; export const githubTokenCreatedAtSelector = ( state ) => { const tokenDetails = githubTokenDetailsSelector ( state ) ; return ( tokenDetails && tokenDetails . tokenCreatedAt ) || undefined ; } ; export const githubPrivateTokenDetailsSelector = ( state ) => { const githubPersonalTokenDetails = githubPersonalTokenDetailsSelector ( state ) ; if ( githubPersonalTokenDetails ?. token && githubPersonalTokenDetails . scope ?. includes ( 'repo' ) ) return githubPersonalTokenDetails ; const githubOAuthTokenDetails = githubOAuthTokenDetailsSelector ( state ) ; if ( githubOAuthTokenDetails ?. token && githubOAuthTokenDetails . scope ?. includes ( 'repo' ) ) return githubOAuthTokenDetails ; return undefined ; } ; export const getPrivateTokenByOwnerSelector = ( state , ownerName ) => { const privateTokenDetails = githubPrivateTokenDetailsSelector ( state ) ; if ( privateTokenDetails ?. token ) return privateTokenDetails . token ; const installationToken = installationTokenByOwnerSelector ( state , ownerName ) ; return installationToken || undefined ; } ; export const getPrivateTokenByRepoSelector = ( state , ownerName , _repoName ) => { return getPrivateTokenByOwnerSelector ( state , ownerName ) ; } ; export const currentGitHubUserSelector = ( state ) => { return s ( state ) . user || undefined ; } ; export const currentGitHubUsernameSelector = ( state ) => { const user = s ( state ) . user ; return ( user && user . login ) || undefined ; } ;