import { execSync } from "child_process" ; function getProjectIdByGit ( ) { try { const originBuffer = execSync ( `git config --local --get remote.origin.url` , { timeout : 1000 , stdio : `pipe` , } ) ; return String ( originBuffer ) . trim ( ) ; } catch ( _ ) { return null ; } } export function normalizeGitUrl ( url ) { url = url . trim ( ) ; url = url . endsWith ( ".git" ) ? url . substring ( 0 , url . length - 4 ) : url ; if ( url . startsWith ( "git@" ) ) { const match = url . match ( /git@([^:]+):(.*)/ ) ; if ( match && match . length > 2 ) { return `${ match [ 1 ] }/${ match [ 2 ] }` ; } } else if ( url . startsWith ( "http://" ) || url . startsWith ( "https://" ) ) { const match = url . match ( /https?:\/\/([^@]+@)?(.*)/ ) ; if ( match && match . length > 2 ) { return match [ 2 ] ; } } return url ; } export function getRawProjectId ( ) { const gitUrl = getProjectIdByGit ( ) ; if ( gitUrl ) { return normalizeGitUrl ( gitUrl ) ; } const repoUrl = process . env . REPOSITORY_URL ; if ( repoUrl ) { return normalizeGitUrl ( repoUrl ) ; } return process . cwd ( ) ; }