( repoUrl: string, customRepoName: string, commitSha: string = 'HEAD', addRandomSuffix: boolean = false, initCommand?: string, parentSha?: string, )
| 69 | } |
| 70 | |
| 71 | export async function setupTestRepo( |
| 72 | repoUrl: string, |
| 73 | customRepoName: string, |
| 74 | commitSha: string = 'HEAD', |
| 75 | addRandomSuffix: boolean = false, |
| 76 | initCommand?: string, |
| 77 | parentSha?: string, |
| 78 | ): Promise<string> { |
| 79 | const repoName = customRepoName || extractRepoNameFromUrl(repoUrl) |
| 80 | console.log(`Setting up test repository: ${repoName}...`) |
| 81 | |
| 82 | const targetSha = parentSha || commitSha |
| 83 | const repoBaseDir = path.join(TEST_REPOS_DIR, `${repoName}-${targetSha}`) |
| 84 | const repoDir = addRandomSuffix |
| 85 | ? `${repoBaseDir}-${generateCompactId()}` |
| 86 | : repoBaseDir |
| 87 | |
| 88 | // Create test-repos directory if it doesn't exist |
| 89 | if (!fs.existsSync(TEST_REPOS_DIR)) { |
| 90 | fs.mkdirSync(TEST_REPOS_DIR, { recursive: true }) |
| 91 | } |
| 92 | |
| 93 | // Remove existing repo if it exists |
| 94 | if (fs.existsSync(repoDir)) { |
| 95 | console.log(`Removing existing ${repoName} repo...`) |
| 96 | fs.rmSync(repoDir, { recursive: true, force: true }) |
| 97 | } |
| 98 | |
| 99 | try { |
| 100 | // Check if we're in a CI environment (GitHub Actions or Render.com) |
| 101 | const isGitHubActions = process.env.GITHUB_ACTIONS === 'true' |
| 102 | const isRenderCron = |
| 103 | process.env.RENDER === 'true' || process.env.IS_PULL_REQUEST === 'false' |
| 104 | |
| 105 | // Always try authenticated approach first if we have a token, regardless of environment |
| 106 | const githubToken = process.env.CODEBUFF_GITHUB_TOKEN |
| 107 | const shouldUseAuth = githubToken && repoUrl.includes('github.com') |
| 108 | |
| 109 | let effectiveCloneUrl = repoUrl |
| 110 | if (shouldUseAuth) { |
| 111 | // In CI environments or when we have a token, handle authentication for private repos |
| 112 | const envName = isGitHubActions |
| 113 | ? 'GitHub Actions' |
| 114 | : isRenderCron |
| 115 | ? 'Render.com' |
| 116 | : 'Local with token' |
| 117 | console.log(`${envName} detected - setting up authentication...`) |
| 118 | |
| 119 | // Convert SSH URL to HTTPS with token if needed |
| 120 | if (repoUrl.startsWith('git@github.com:')) { |
| 121 | effectiveCloneUrl = repoUrl.replace( |
| 122 | 'git@github.com:', |
| 123 | 'https://github.com/', |
| 124 | ) |
| 125 | } |
| 126 | if (effectiveCloneUrl.endsWith('.git')) { |
| 127 | effectiveCloneUrl = effectiveCloneUrl.slice(0, -4) |
| 128 | } |
no test coverage detected