(connectionName: string)
| 5 | import { multiInput, note, toEnvKey } from './utils.js'; |
| 6 | |
| 7 | export async function collectAzureDevOpsConfig(connectionName: string): Promise<CollectResult> { |
| 8 | const env: EnvVars = {}; |
| 9 | |
| 10 | const deploymentType = await select<'cloud' | 'server'>({ |
| 11 | message: 'Which Azure DevOps deployment?', |
| 12 | choices: [ |
| 13 | { value: 'cloud', name: 'Azure DevOps Cloud', description: 'dev.azure.com' }, |
| 14 | { value: 'server', name: 'Azure DevOps Server', description: 'self-hosted' }, |
| 15 | ], |
| 16 | }); |
| 17 | |
| 18 | const config: AzureDevOpsConnectionConfig = { |
| 19 | type: 'azuredevops', |
| 20 | deploymentType, |
| 21 | token: { env: '' }, |
| 22 | }; |
| 23 | |
| 24 | if (deploymentType === 'server') { |
| 25 | const url = await input({ |
| 26 | message: 'Azure DevOps Server URL (e.g. https://ado.example.com)', |
| 27 | validate: (v) => { |
| 28 | if (!v?.trim()) { |
| 29 | return 'URL is required'; |
| 30 | } |
| 31 | if (!/^https?:\/\//.test(v)) { |
| 32 | return 'Must start with http:// or https://'; |
| 33 | } |
| 34 | return true; |
| 35 | }, |
| 36 | }); |
| 37 | config.url = url; |
| 38 | |
| 39 | const useTfsPath = await confirm({ |
| 40 | message: 'Use legacy TFS path format (/tfs in API URLs)?', |
| 41 | default: false, |
| 42 | }); |
| 43 | if (useTfsPath) { |
| 44 | config.useTfsPath = true; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | note( |
| 49 | [ |
| 50 | 'Create a Personal Access Token at:', |
| 51 | deploymentType === 'cloud' |
| 52 | ? ' https://dev.azure.com/<your-org>/_usersSettings/tokens' |
| 53 | : ' <your-server-url>/_usersSettings/tokens', |
| 54 | 'Grant `Code (Read)` scope so Sourcebot can find and clone your repos.', |
| 55 | ].join('\n'), |
| 56 | 'Azure DevOps Personal Access Token', |
| 57 | ); |
| 58 | |
| 59 | const envKey = toEnvKey(connectionName, 'TOKEN'); |
| 60 | const token = await password({ |
| 61 | message: `Azure DevOps Personal Access Token (stored locally in .env as ${envKey})`, |
| 62 | mask: true, |
| 63 | validate: (v) => !v?.trim() ? 'Token is required' : true, |
| 64 | }); |
no test coverage detected