({ uri, credentialsId }: { uri: string; credentialsId?: string | null })
| 2176 | } |
| 2177 | |
| 2178 | export async function fetchRemoteBranches({ uri, credentialsId }: { uri: string; credentialsId?: string | null }) { |
| 2179 | const [mainRef] = await git.listServerRefs({ |
| 2180 | ...gitCallbacks(credentialsId), |
| 2181 | http: httpClient, |
| 2182 | url: uri, |
| 2183 | prefix: 'HEAD', |
| 2184 | symrefs: true, |
| 2185 | }); |
| 2186 | |
| 2187 | const remoteRefs = await git.listServerRefs({ |
| 2188 | ...gitCallbacks(credentialsId), |
| 2189 | http: httpClient, |
| 2190 | url: uri, |
| 2191 | prefix: 'refs/heads/', |
| 2192 | symrefs: true, |
| 2193 | }); |
| 2194 | |
| 2195 | const defaultBranch = mainRef?.target?.replace('refs/heads/', '') || 'main'; |
| 2196 | |
| 2197 | const remoteBranches = remoteRefs |
| 2198 | .filter(b => b.ref !== 'HEAD') |
| 2199 | .map(b => b.ref.replace('refs/heads/', '')) |
| 2200 | .sort((a, b) => { |
| 2201 | if (a === defaultBranch) return -1; |
| 2202 | if (b === defaultBranch) return 1; |
| 2203 | return a.localeCompare(b); |
| 2204 | }); |
| 2205 | |
| 2206 | return remoteBranches; |
| 2207 | } |
| 2208 | |
| 2209 | export default new GitVCS(); |
no test coverage detected