Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/docs/connections/bitbucket-data-center.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ If you're not familiar with Sourcebot [connections](/docs/connections/overview),
}
```
</Accordion>
<Accordion title="Sync all repos">
<Note>Requires a `token` to be set in order to access private repositories.</Note>
```json
{
"type": "bitbucket",
"deploymentType": "server",
"url": "https://mybitbucketdeployment.com",
// Index all repos visible to the provided token
"all": true
}
```
</Accordion>
<Accordion title="Exclude repos from syncing">
```json
{
Expand Down
5 changes: 5 additions & 0 deletions docs/snippets/schemas/v3/bitbucket.schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
"default": "cloud",
"description": "The type of Bitbucket deployment"
},
"all": {
"type": "boolean",
"default": false,
"description": "Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`."
},
"workspaces": {
"type": "array",
"items": {
Expand Down
5 changes: 5 additions & 0 deletions docs/snippets/schemas/v3/connection.schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,11 @@
"default": "cloud",
"description": "The type of Bitbucket deployment"
},
"all": {
"type": "boolean",
"default": false,
"description": "Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`."
},
"workspaces": {
"type": "array",
"items": {
Expand Down
5 changes: 5 additions & 0 deletions docs/snippets/schemas/v3/index.schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,11 @@
"default": "cloud",
"description": "The type of Bitbucket deployment"
},
"all": {
"type": "boolean",
"default": false,
"description": "Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`."
},
"workspaces": {
"type": "array",
"items": {
Expand Down
32 changes: 32 additions & 0 deletions packages/backend/src/bitbucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ export const getBitbucketReposFromConfig = async (config: BitbucketConnectionCon
let allRepos: BitbucketRepository[] = [];
let allWarnings: string[] = [];

if (config.all === true) {
if (client.deploymentType === BITBUCKET_SERVER) {
const { repos, warnings } = await serverGetAllRepos(client);
allRepos = allRepos.concat(repos);
allWarnings = allWarnings.concat(warnings);
} else {
const warning = `Ignoring option all:true in config: not supported for Bitbucket Cloud`;
logger.warn(warning);
allWarnings = allWarnings.concat(warning);
}
}

if (config.workspaces) {
const { repos, warnings } = await client.getReposForWorkspace(client, config.workspaces);
allRepos = allRepos.concat(repos);
Expand Down Expand Up @@ -554,6 +566,26 @@ async function serverGetRepos(client: BitbucketClient, repoList: string[]): Prom
};
}

async function serverGetAllRepos(client: BitbucketClient): Promise<{repos: ServerRepository[], warnings: string[]}> {
logger.debug(`Fetching all repos from Bitbucket Server...`);
const path = `/rest/api/1.0/repos` as ServerGetRequestPath;
const { durationMs, data } = await measure(async () => {
const fetchFn = () => getPaginatedServer<ServerRepository>(path, async (url, start) => {
const response = await client.apiClient.GET(url, {
params: { query: { start } }
});
const { data, error } = response;
if (error) {
throw new Error(`Failed to fetch all repos: ${JSON.stringify(error)}`);
}
return data;
});
return fetchWithRetry(fetchFn, `all repos`, logger);
});
logger.debug(`Found ${data.length} total repos in ${durationMs}ms.`);
return { repos: data, warnings: [] };
}

export function serverShouldExcludeRepo(repo: BitbucketRepository, config: BitbucketConnectionConfig): boolean {
const serverRepo = repo as ServerRepository;

Expand Down
5 changes: 5 additions & 0 deletions packages/schemas/src/v3/bitbucket.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ const schema = {
"default": "cloud",
"description": "The type of Bitbucket deployment"
},
"all": {
"type": "boolean",
"default": false,
"description": "Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`."
},
"workspaces": {
"type": "array",
"items": {
Expand Down
4 changes: 4 additions & 0 deletions packages/schemas/src/v3/bitbucket.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export interface BitbucketConnectionConfig {
* The type of Bitbucket deployment
*/
deploymentType?: "cloud" | "server";
/**
* Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`.
*/
all?: boolean;
/**
* List of workspaces to sync. Ignored if deploymentType is server.
*/
Expand Down
5 changes: 5 additions & 0 deletions packages/schemas/src/v3/connection.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,11 @@ const schema = {
"default": "cloud",
"description": "The type of Bitbucket deployment"
},
"all": {
"type": "boolean",
"default": false,
"description": "Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`."
},
"workspaces": {
"type": "array",
"items": {
Expand Down
4 changes: 4 additions & 0 deletions packages/schemas/src/v3/connection.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ export interface BitbucketConnectionConfig {
* The type of Bitbucket deployment
*/
deploymentType?: "cloud" | "server";
/**
* Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`.
*/
all?: boolean;
/**
* List of workspaces to sync. Ignored if deploymentType is server.
*/
Expand Down
5 changes: 5 additions & 0 deletions packages/schemas/src/v3/index.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,11 @@ const schema = {
"default": "cloud",
"description": "The type of Bitbucket deployment"
},
"all": {
"type": "boolean",
"default": false,
"description": "Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`."
},
"workspaces": {
"type": "array",
"items": {
Expand Down
4 changes: 4 additions & 0 deletions packages/schemas/src/v3/index.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,10 @@ export interface BitbucketConnectionConfig {
* The type of Bitbucket deployment
*/
deploymentType?: "cloud" | "server";
/**
* Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`.
*/
all?: boolean;
/**
* List of workspaces to sync. Ignored if deploymentType is server.
*/
Expand Down
5 changes: 5 additions & 0 deletions schemas/v3/bitbucket.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
"default": "cloud",
"description": "The type of Bitbucket deployment"
},
"all": {
"type": "boolean",
"default": false,
"description": "Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`."
},
"workspaces": {
"type": "array",
"items": {
Expand Down
Loading