Skip to content

Commit 0ae579b

Browse files
Merge branch 'main' into brendan/feat-bitbucket-server-permission-syncing
2 parents 4bf5113 + da5317b commit 0ae579b

File tree

13 files changed

+92
-0
lines changed

13 files changed

+92
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Added `wa_user_created` PostHog event fired on successful user sign-up. [#933](https://github.com/sourcebot-dev/sourcebot/pull/933)
1515
- Added `wa_askgh_login_wall_prompted` PostHog event fired when an unauthenticated user attempts to ask a question on Ask GitHub. [#933](https://github.com/sourcebot-dev/sourcebot/pull/933)
1616
- Added Bitbucket Server (Data Center) OAuth 2.0 SSO identity provider support (`provider: "bitbucket-server"`). [#934](https://github.com/sourcebot-dev/sourcebot/pull/934)
17+
- Added Bitbucket Server (Data Center) sync all repositories support. [#927](https://github.com/sourcebot-dev/sourcebot/pull/927)
1718
- Added permission syncing support for Bitbucket Server (Data Center), including account-driven and repo-driven sync. [#938](https://github.com/sourcebot-dev/sourcebot/pull/938)
1819

1920
### Changed

docs/docs/connections/bitbucket-data-center.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ If you're not familiar with Sourcebot [connections](/docs/connections/overview),
3939
}
4040
```
4141
</Accordion>
42+
<Accordion title="Sync all repos">
43+
<Note>Requires a `token` to be set in order to access private repositories.</Note>
44+
```json
45+
{
46+
"type": "bitbucket",
47+
"deploymentType": "server",
48+
"url": "https://mybitbucketdeployment.com",
49+
// Index all repos visible to the provided token
50+
"all": true
51+
}
52+
```
53+
</Accordion>
4254
<Accordion title="Exclude repos from syncing">
4355
```json
4456
{

docs/snippets/schemas/v3/bitbucket.schema.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
"default": "cloud",
6868
"description": "The type of Bitbucket deployment"
6969
},
70+
"all": {
71+
"type": "boolean",
72+
"default": false,
73+
"description": "Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`."
74+
},
7075
"workspaces": {
7176
"type": "array",
7277
"items": {

docs/snippets/schemas/v3/connection.schema.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,11 @@
744744
"default": "cloud",
745745
"description": "The type of Bitbucket deployment"
746746
},
747+
"all": {
748+
"type": "boolean",
749+
"default": false,
750+
"description": "Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`."
751+
},
747752
"workspaces": {
748753
"type": "array",
749754
"items": {

docs/snippets/schemas/v3/index.schema.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,11 @@
11591159
"default": "cloud",
11601160
"description": "The type of Bitbucket deployment"
11611161
},
1162+
"all": {
1163+
"type": "boolean",
1164+
"default": false,
1165+
"description": "Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`."
1166+
},
11621167
"workspaces": {
11631168
"type": "array",
11641169
"items": {

packages/backend/src/bitbucket.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ export const getBitbucketReposFromConfig = async (config: BitbucketConnectionCon
7676
let allRepos: BitbucketRepository[] = [];
7777
let allWarnings: string[] = [];
7878

79+
if (config.all === true) {
80+
if (client.deploymentType === BITBUCKET_SERVER) {
81+
const { repos, warnings } = await serverGetAllRepos(client);
82+
allRepos = allRepos.concat(repos);
83+
allWarnings = allWarnings.concat(warnings);
84+
} else {
85+
const warning = `Ignoring option all:true in config: not supported for Bitbucket Cloud`;
86+
logger.warn(warning);
87+
allWarnings = allWarnings.concat(warning);
88+
}
89+
}
90+
7991
if (config.workspaces) {
8092
const { repos, warnings } = await client.getReposForWorkspace(client, config.workspaces);
8193
allRepos = allRepos.concat(repos);
@@ -563,6 +575,26 @@ async function serverGetRepos(client: BitbucketClient, repoList: string[]): Prom
563575
};
564576
}
565577

578+
async function serverGetAllRepos(client: BitbucketClient): Promise<{repos: ServerRepository[], warnings: string[]}> {
579+
logger.debug(`Fetching all repos from Bitbucket Server...`);
580+
const path = `/rest/api/1.0/repos` as ServerGetRequestPath;
581+
const { durationMs, data } = await measure(async () => {
582+
const fetchFn = () => getPaginatedServer<ServerRepository>(path, async (url, start) => {
583+
const response = await client.apiClient.GET(url, {
584+
params: { query: { start } }
585+
});
586+
const { data, error } = response;
587+
if (error) {
588+
throw new Error(`Failed to fetch all repos: ${JSON.stringify(error)}`);
589+
}
590+
return data;
591+
});
592+
return fetchWithRetry(fetchFn, `all repos`, logger);
593+
});
594+
logger.debug(`Found ${data.length} total repos in ${durationMs}ms.`);
595+
return { repos: data, warnings: [] };
596+
}
597+
566598
export function serverShouldExcludeRepo(repo: BitbucketRepository, config: BitbucketConnectionConfig): boolean {
567599
const serverRepo = repo as ServerRepository;
568600

packages/schemas/src/v3/bitbucket.schema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ const schema = {
6666
"default": "cloud",
6767
"description": "The type of Bitbucket deployment"
6868
},
69+
"all": {
70+
"type": "boolean",
71+
"default": false,
72+
"description": "Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`."
73+
},
6974
"workspaces": {
7075
"type": "array",
7176
"items": {

packages/schemas/src/v3/bitbucket.type.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export interface BitbucketConnectionConfig {
3737
* The type of Bitbucket deployment
3838
*/
3939
deploymentType?: "cloud" | "server";
40+
/**
41+
* Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`.
42+
*/
43+
all?: boolean;
4044
/**
4145
* List of workspaces to sync. Ignored if deploymentType is server.
4246
*/

packages/schemas/src/v3/connection.schema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,11 @@ const schema = {
743743
"default": "cloud",
744744
"description": "The type of Bitbucket deployment"
745745
},
746+
"all": {
747+
"type": "boolean",
748+
"default": false,
749+
"description": "Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`."
750+
},
746751
"workspaces": {
747752
"type": "array",
748753
"items": {

packages/schemas/src/v3/connection.type.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ export interface BitbucketConnectionConfig {
288288
* The type of Bitbucket deployment
289289
*/
290290
deploymentType?: "cloud" | "server";
291+
/**
292+
* Sync all repositories visible to the provided `token` (if any) in the Bitbucket Server instance. This option is ignored if `deploymentType` is `cloud`.
293+
*/
294+
all?: boolean;
291295
/**
292296
* List of workspaces to sync. Ignored if deploymentType is server.
293297
*/

0 commit comments

Comments
 (0)