(configs: {
backend: Backend;
repo: string;
token?: string;
apiRoot?: string;
})
| 218 | } |
| 219 | |
| 220 | export async function getDefaultBranchName(configs: { |
| 221 | backend: Backend; |
| 222 | repo: string; |
| 223 | token?: string; |
| 224 | apiRoot?: string; |
| 225 | }) { |
| 226 | let apiPath; |
| 227 | const { token, backend, repo, apiRoot } = configs; |
| 228 | switch (backend) { |
| 229 | case 'gitlab': { |
| 230 | apiPath = `/projects/${encodeURIComponent(repo)}`; |
| 231 | break; |
| 232 | } |
| 233 | case 'bitbucket': { |
| 234 | apiPath = `/repositories/${repo}`; |
| 235 | break; |
| 236 | } |
| 237 | default: { |
| 238 | apiPath = `/repos/${repo}`; |
| 239 | } |
| 240 | } |
| 241 | const repoInfo = await apiRequest(apiPath, { token, backend, apiRoot }); |
| 242 | let defaultBranchName; |
| 243 | if (backend === 'bitbucket') { |
| 244 | const { |
| 245 | mainbranch: { name }, |
| 246 | } = repoInfo; |
| 247 | defaultBranchName = name; |
| 248 | } else { |
| 249 | const { default_branch } = repoInfo; |
| 250 | defaultBranchName = default_branch; |
| 251 | } |
| 252 | return defaultBranchName; |
| 253 | } |
| 254 | |
| 255 | export async function readFile( |
| 256 | id: string | null | undefined, |
no test coverage detected