|
1 | 1 | import type { AuthenticationSession, CancellationToken } from 'vscode';
|
| 2 | +import { md5 } from '@env/crypto'; |
2 | 3 | import { HostingIntegrationId } from '../../../constants.integrations';
|
3 | 4 | import type { Account } from '../../../git/models/author';
|
4 | 5 | import type { DefaultBranch } from '../../../git/models/defaultBranch';
|
@@ -222,6 +223,7 @@ export class BitbucketIntegration extends HostingIntegration<
|
222 | 223 | `${accessToken}:${resource.id}`,
|
223 | 224 | resourceRepos.map(r => ({
|
224 | 225 | id: `${r.owner}/${r.name}`,
|
| 226 | + resourceId: r.owner, |
225 | 227 | owner: r.owner,
|
226 | 228 | name: r.name,
|
227 | 229 | key: `${r.owner}/${r.name}`,
|
@@ -283,6 +285,55 @@ export class BitbucketIntegration extends HostingIntegration<
|
283 | 285 | remotePullRequest.graphQLId = remotePullRequest.id;
|
284 | 286 | return fromProviderPullRequest(remotePullRequest, this);
|
285 | 287 | }
|
| 288 | + |
| 289 | + protected override async providerOnConnect(): Promise<void> { |
| 290 | + if (this._session == null) return; |
| 291 | + |
| 292 | + const accountStorageKey = md5(this._session.accessToken); |
| 293 | + |
| 294 | + const storedAccount = this.container.storage.get(`bitbucket:${accountStorageKey}:account`); |
| 295 | + const storedWorkspaces = this.container.storage.get(`bitbucket:${accountStorageKey}:workspaces`); |
| 296 | + |
| 297 | + let account: Account | undefined = storedAccount?.data ? { ...storedAccount.data, provider: this } : undefined; |
| 298 | + let workspaces = storedWorkspaces?.data?.map(o => ({ ...o })); |
| 299 | + |
| 300 | + if (storedAccount == null) { |
| 301 | + account = await this.getProviderCurrentAccount(this._session); |
| 302 | + if (account != null) { |
| 303 | + // Clear all other stored workspaces and repositories and accounts when our session changes |
| 304 | + await this.container.storage.deleteWithPrefix('bitbucket'); |
| 305 | + await this.container.storage.store(`bitbucket:${accountStorageKey}:account`, { |
| 306 | + v: 1, |
| 307 | + timestamp: Date.now(), |
| 308 | + data: { |
| 309 | + id: account.id, |
| 310 | + name: account.name, |
| 311 | + email: account.email, |
| 312 | + avatarUrl: account.avatarUrl, |
| 313 | + username: account.username, |
| 314 | + }, |
| 315 | + }); |
| 316 | + } |
| 317 | + } |
| 318 | + this._accounts ??= new Map<string, Account | undefined>(); |
| 319 | + this._accounts.set(this._session.accessToken, account); |
| 320 | + |
| 321 | + if (storedWorkspaces == null) { |
| 322 | + workspaces = await this.getProviderResourcesForUser(this._session, true); |
| 323 | + await this.container.storage.store(`bitbucket:${accountStorageKey}:workspaces`, { |
| 324 | + v: 1, |
| 325 | + timestamp: Date.now(), |
| 326 | + data: workspaces, |
| 327 | + }); |
| 328 | + } |
| 329 | + this._workspaces ??= new Map<string, BitbucketWorkspaceDescriptor[] | undefined>(); |
| 330 | + this._workspaces.set(this._session.accessToken, workspaces); |
| 331 | + } |
| 332 | + |
| 333 | + protected override providerOnDisconnect(): void { |
| 334 | + this._accounts = undefined; |
| 335 | + this._workspaces = undefined; |
| 336 | + } |
286 | 337 | }
|
287 | 338 |
|
288 | 339 | const bitbucketCloudDomainRegex = /^bitbucket\.org$/i;
|
|
0 commit comments