import { exec } from 'child_process' /** * Get the current Git commit hash. * @returns The current Git commit hash as a string, or null if an error occurs. */ export async function getGitCommitHash(): Promise { try { const commitHash = (await new Promise((resolve, reject) => { exec('git rev-parse HEAD', (error, stdout) => { if (error) { reject(error) } else { resolve(stdout.toString().trim()) } }) })) as string return commitHash } catch (error) { console.error('Error getting Git commit hash:', error) return null } } /** * Get the Git origin URL. * @returns The Git origin URL as a string, or null if an error occurs. */ export async function getGitOriginUrl(): Promise { try { const originUrl = (await new Promise((resolve, reject) => { exec('git config --get remote.origin.url', (error, stdout) => { if (error) { reject(error) } else { resolve(stdout.toString().trim()) } }) })) as string if (originUrl.startsWith('ssh://')) { const httpsUrl = originUrl.replace(/^ssh:\/\/git@/, 'https://').replace(/\.git$/, '') const urlWithoutPort = httpsUrl.replace(/:\d+/, '') return urlWithoutPort } return originUrl } catch (error) { console.error('Error getting Git origin URL:', error) return null } }