import * as process from "process" ; import { createHash } from "crypto" ; function getProviders ( env = process . env ) { return [ [ "Travis" , [ env . TRAVIS_REPO_SLUG ] ] , [ "Jenkins" , [ env . JENKINS_URL ] ] , [ "TeamCity" , [ env . TEAMCITY_PROJECT_NAME ] ] , [ "CircleCI" , [ env . CIRCLE_PROJECT_USERNAME , env . CIRCLE_PROJECT_REPONAME ] ] , [ "Codeship" , [ env . CI_REPO_NAME ] ] , [ "GitLab" , [ env . GITLAB_CI , env . CI_REPOSITORY_URL , env . CI_PROJECT_ID ] ] , [ "VSTS" , [ env . SYSTEM_TEAMFOUNDATIONCOLLECTIONURI , env . BUILD_REPOSITORY_NAME ] ] , [ "App Center" , [ env . SYSTEM_TEAMFOUNDATIONCOLLECTIONURI , env . BUILD_REPOSITORY_NAME ] ] , [ "Other" , [ env . CI ] ] ] ; } export function tryHash ( envs ) { if ( envs . some ( s => s === undefined ) ) { return undefined ; } const hash = createHash ( "sha256" ) ; envs . forEach ( s => hash . update ( s as string ) ) ; return hash . digest ( "base64" ) ; } export function getProvider ( environment ? ) { for ( const [ provider , vars ] of getProviders ( environment ) ) { const hash = tryHash ( vars ) ; if ( hash !== undefined ) { return { provider , userId : hash } ; } } return undefined ; }