-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38c3d8e
commit 709a825
Showing
8 changed files
with
161 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
components/server/ee/src/bitbucket/bitbucket-app-support.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* Copyright (c) 2020 Gitpod GmbH. All rights reserved. | ||
* Licensed under the Gitpod Enterprise Source Code License, | ||
* See License.enterprise.txt in the project root folder. | ||
*/ | ||
|
||
import { AuthProviderInfo, ProviderRepository, User } from "@gitpod/gitpod-protocol"; | ||
import { inject, injectable } from "inversify"; | ||
import { TokenProvider } from "../../../src/user/token-provider"; | ||
import { Bitbucket } from "bitbucket"; | ||
|
||
@injectable() | ||
export class BitbucketAppSupport { | ||
|
||
@inject(TokenProvider) protected readonly tokenProvider: TokenProvider; | ||
|
||
async getProviderRepositoriesForUser(params: { user: User, provider: AuthProviderInfo }): Promise<ProviderRepository[]> { | ||
const token = await this.tokenProvider.getTokenForHost(params.user, params.provider.host); | ||
const oauthToken = token.value; | ||
|
||
const api = new Bitbucket({ | ||
baseUrl: `https://api.${params.provider.host}/2.0`, | ||
auth: { | ||
token: oauthToken | ||
} | ||
}); | ||
|
||
const result: ProviderRepository[] = []; | ||
const ownersRepos: ProviderRepository[] = []; | ||
|
||
const identity = params.user.identities.find(i => i.authProviderId === params.provider.authProviderId); | ||
if (!identity) { | ||
return result; | ||
} | ||
const usersGitLabAccount = identity.authName; | ||
|
||
const workspaces = (await api.workspaces.getWorkspaces({ pagelen: 100 })).data.values?.map(w => w.slug!) || []; | ||
|
||
const reposPromise = Promise.all(workspaces.map(workspace => api.repositories.list({ | ||
workspace, | ||
pagelen: 100, | ||
role: "admin" | ||
}).catch(e => { | ||
|
||
}))); | ||
|
||
const reposInWorkspace = await reposPromise; | ||
for (const repos of reposInWorkspace) { | ||
if (repos) { | ||
for (const repo of (repos.data.values || [])) { | ||
const fullName = repo.full_name!; | ||
const cloneUrl = repo.links!.clone!.find((x: any) => x.name === "https")!.href!; | ||
const updatedAt = repo.updated_on!; | ||
const accountAvatarUrl = repo.links!.avatar?.href!; | ||
const account = fullName.split("/")[0]; | ||
|
||
(account === usersGitLabAccount ? ownersRepos : result).push({ | ||
name: repo.name!, | ||
account, | ||
cloneUrl, | ||
updatedAt, | ||
accountAvatarUrl, | ||
}) | ||
} | ||
} | ||
} | ||
|
||
// put owner's repos first. the frontend will pick first account to continue with | ||
result.unshift(...ownersRepos); | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5041,10 +5041,10 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/bintrees/-/bintrees-1.0.1.tgz#0e655c9b9c2435eaab68bf4027226d2b55a34524" | ||
integrity sha1-DmVcm5wkNeqraL9AJyJtK1WjRSQ= | ||
|
||
bitbucket@^2.4.2: | ||
version "2.6.3" | ||
resolved "https://registry.yarnpkg.com/bitbucket/-/bitbucket-2.6.3.tgz#e7aa030406720e24c19a40701506b1c366daf544" | ||
integrity sha512-t23mlPsCchl+7TCGGHqI4Up++mnGd6smaKsNe/t+kGlkGfIzm+QmVdWvBboHl8Nyequ8Wm0Whi2lKq9qmfJmxA== | ||
bitbucket@^2.7.0: | ||
version "2.7.0" | ||
resolved "https://registry.yarnpkg.com/bitbucket/-/bitbucket-2.7.0.tgz#fd11b19a42cc9b89f6a899ff669fd1575183a5b3" | ||
integrity sha512-6fw3MzXeFp3TLmo6jF7IWFn9tFpFKpzCpDjKek9s5EY559Ff3snbu2hmS5ZKmR7D0XomPbIT0dBN1juoJ/gGyA== | ||
dependencies: | ||
before-after-hook "^2.1.0" | ||
deepmerge "^4.2.2" | ||
|