(url: string, user: string | undefined, token: string | undefined)
| 401 | } |
| 402 | |
| 403 | export function createBitbucketServerClient(url: string, user: string | undefined, token: string | undefined): BitbucketClient { |
| 404 | const authorizationString = (() => { |
| 405 | // If we're not given any credentials we return an empty auth string. This will only work if the project/repos are public |
| 406 | if(!user && !token) { |
| 407 | return ""; |
| 408 | } |
| 409 | |
| 410 | // A user must be provided when using basic auth |
| 411 | // https://developer.atlassian.com/server/bitbucket/rest/v906/intro/#authentication |
| 412 | if (!user || user == "x-token-auth") { |
| 413 | return `Bearer ${token}`; |
| 414 | } |
| 415 | return `Basic ${Buffer.from(`${user}:${token}`).toString('base64')}`; |
| 416 | })(); |
| 417 | const clientOptions: ClientOptions = { |
| 418 | baseUrl: url, |
| 419 | headers: { |
| 420 | Accept: "application/json", |
| 421 | Authorization: authorizationString, |
| 422 | }, |
| 423 | }; |
| 424 | |
| 425 | const apiClient = createBitbucketServerClientBase(clientOptions); |
| 426 | apiClient.use(throwOnHttpError); |
| 427 | var client: BitbucketClient = { |
| 428 | deploymentType: BITBUCKET_SERVER, |
| 429 | token: token, |
| 430 | apiClient: apiClient, |
| 431 | baseUrl: url, |
| 432 | gitUrl: url, |
| 433 | getReposForWorkspace: serverGetReposForWorkspace, |
| 434 | getReposForProjects: serverGetReposForProjects, |
| 435 | getRepos: serverGetRepos, |
| 436 | shouldExcludeRepo: serverShouldExcludeRepo, |
| 437 | } |
| 438 | |
| 439 | return client; |
| 440 | } |
| 441 | |
| 442 | const getPaginatedServer = async <T>( |
| 443 | path: ServerGetRequestPath, |
no outgoing calls
no test coverage detected