(
connectionName: string,
config: BitbucketConnectionConfig,
env: EnvVars,
)
| 155 | } |
| 156 | |
| 157 | async function collectBitbucketServer( |
| 158 | connectionName: string, |
| 159 | config: BitbucketConnectionConfig, |
| 160 | env: EnvVars, |
| 161 | ): Promise<CollectResult> { |
| 162 | const url = await input({ |
| 163 | message: 'Bitbucket Data Center URL (e.g. https://bitbucket.example.com)', |
| 164 | validate: (v) => { |
| 165 | if (!v?.trim()) { |
| 166 | return 'URL is required'; |
| 167 | } |
| 168 | if (!/^https?:\/\//.test(v)) { |
| 169 | return 'Must start with http:// or https://'; |
| 170 | } |
| 171 | return true; |
| 172 | }, |
| 173 | }); |
| 174 | config.url = url; |
| 175 | |
| 176 | note( |
| 177 | [ |
| 178 | 'Create an HTTP Access Token:', |
| 179 | ' Profile → Manage account → HTTP access tokens', |
| 180 | ' Required permissions: Project read, Repository read', |
| 181 | '', |
| 182 | 'Use a user-account token for cross-project access,', |
| 183 | 'or a project/repository-scoped token for narrower access.', |
| 184 | ].join('\n'), |
| 185 | 'Create a Bitbucket Data Center HTTP Access Token', |
| 186 | ); |
| 187 | |
| 188 | const username = await input({ |
| 189 | message: 'Bitbucket username (leave blank if using a project/repo-scoped token)', |
| 190 | }); |
| 191 | if (username.trim()) { |
| 192 | config.user = username; |
| 193 | } |
| 194 | |
| 195 | const tokenEnvKey = toEnvKey(connectionName, 'TOKEN'); |
| 196 | const token = await password({ |
| 197 | message: `Bitbucket HTTP Access Token (stored locally in .env as ${tokenEnvKey})`, |
| 198 | mask: true, |
| 199 | validate: (v) => !v?.trim() ? 'Token is required' : true, |
| 200 | }); |
| 201 | env[tokenEnvKey] = token; |
| 202 | config.token = { env: tokenEnvKey }; |
| 203 | |
| 204 | const indexAll = await confirm({ |
| 205 | message: 'Index every repository visible to the token?', |
| 206 | default: false, |
| 207 | }); |
| 208 | |
| 209 | if (indexAll) { |
| 210 | config.all = true; |
| 211 | return { connections: [{ config }], env }; |
| 212 | } |
| 213 | |
| 214 | const targets = await checkbox<string>({ |
no test coverage detected