|
4 | 4 | * See License.enterprise.txt in the project root folder.
|
5 | 5 | */
|
6 | 6 |
|
| 7 | +// @ts-nocheck |
7 | 8 | import { AuthProviderInfo, ProviderRepository, User } from "@gitpod/gitpod-protocol";
|
8 | 9 | import { inject, injectable } from "inversify";
|
9 | 10 | import { TokenProvider } from "../../../src/user/token-provider";
|
10 |
| -import { Bitbucket } from "bitbucket"; |
| 11 | +import { Bitbucket, Schema } from "bitbucket"; |
11 | 12 | import { URL } from "url";
|
12 | 13 |
|
13 | 14 | @injectable()
|
@@ -41,44 +42,57 @@ export class BitbucketAppSupport {
|
41 | 42 | const workspaces =
|
42 | 43 | (await api.workspaces.getWorkspaces({ pagelen: 100 })).data.values?.map((w) => w.slug!) || [];
|
43 | 44 |
|
44 |
| - const reposPromise = Promise.all( |
45 |
| - workspaces.map((workspace) => |
46 |
| - api.repositories |
| 45 | + const fetchAllRepos = async (workspace: string) => { |
| 46 | + const reposResponse: (Schema.Repository[] | undefined)[] = []; |
| 47 | + let page = "1"; |
| 48 | + let hasMorePages = true; |
| 49 | + const pagelen = 100; |
| 50 | + |
| 51 | + while (hasMorePages) { |
| 52 | + const response = await api.repositories |
47 | 53 | .list({
|
48 | 54 | workspace,
|
49 |
| - pagelen: 100, |
| 55 | + pagelen, |
| 56 | + page, |
50 | 57 | role: "admin", // installation of webhooks is allowed for admins only
|
51 | 58 | })
|
52 | 59 | .catch((e) => {
|
53 | 60 | console.error(e);
|
54 |
| - }), |
55 |
| - ), |
56 |
| - ); |
57 |
| - |
58 |
| - const reposInWorkspace = await reposPromise; |
59 |
| - for (const repos of reposInWorkspace) { |
60 |
| - if (repos) { |
61 |
| - for (const repo of repos.data.values || []) { |
62 |
| - let cloneUrl = repo.links!.clone!.find((x: any) => x.name === "https")!.href!; |
63 |
| - if (cloneUrl) { |
64 |
| - const url = new URL(cloneUrl); |
65 |
| - url.username = ""; |
66 |
| - cloneUrl = url.toString(); |
67 |
| - } |
68 |
| - const fullName = repo.full_name!; |
69 |
| - const updatedAt = repo.updated_on!; |
70 |
| - const accountAvatarUrl = repo.links!.avatar?.href!; |
71 |
| - const account = fullName.split("/")[0]; |
72 |
| - |
73 |
| - (account === usersBitbucketAccount ? ownersRepos : result).push({ |
74 |
| - name: repo.name!, |
75 |
| - account, |
76 |
| - cloneUrl, |
77 |
| - updatedAt, |
78 |
| - accountAvatarUrl, |
79 | 61 | });
|
| 62 | + if (response) { |
| 63 | + reposResponse.push(response.data.values); |
| 64 | + page++; |
| 65 | + hasMorePages = response.data.size! > pagelen; |
| 66 | + } else { |
| 67 | + hasMorePages = false; |
80 | 68 | }
|
81 | 69 | }
|
| 70 | + return reposResponse.flat(); |
| 71 | + }; |
| 72 | + |
| 73 | + const reposPromise = Promise.all(workspaces.map((workspace) => fetchAllRepos(workspace))); |
| 74 | + const reposInWorkspace: (Schema.Repository | undefined)[][] = await reposPromise; |
| 75 | + |
| 76 | + for (let repo of reposInWorkspace) { |
| 77 | + repo = repo[0]; |
| 78 | + let cloneUrl = repo.links!.clone.find((x: any) => x.name === "https").href; |
| 79 | + if (cloneUrl) { |
| 80 | + const url = new URL(cloneUrl); |
| 81 | + url.username = ""; |
| 82 | + cloneUrl = url.toString(); |
| 83 | + } |
| 84 | + const fullName = repo.full_name!; |
| 85 | + const updatedAt = repo.updated_on!; |
| 86 | + const accountAvatarUrl = repo.links!.avatar?.href!; |
| 87 | + const account = fullName.split("/")[0]; |
| 88 | + |
| 89 | + (account === usersBitbucketAccount ? ownersRepos : result).push({ |
| 90 | + name: repo.name!, |
| 91 | + account, |
| 92 | + cloneUrl, |
| 93 | + updatedAt, |
| 94 | + accountAvatarUrl, |
| 95 | + }); |
82 | 96 | }
|
83 | 97 |
|
84 | 98 | // put owner's repos first. the frontend will pick first account to continue with
|
|
0 commit comments